Class: Snuffle::LatentObject
- Inherits:
-
Object
- Object
- Snuffle::LatentObject
- Includes:
- PoroPlus
- Defined in:
- lib/snuffle/latent_object.rb
Constant Summary collapse
- DUPLICATE_THRESHOLD =
1- STOPWORDS =
[ "the", "be", "to", "of", "and", "a", "in", "that", "have", "I", "it", "for", "not", "on", "with", "he", "as", "you", "do", "at", "this", "but", "his", "by", "from", "they", "we", "say", "her", "she", "or", "an", "will", "my", "are", "one", "all", "would", "there", "their", "what", "so", "up", "out", "if", "is", "about", "who", "get", "which", "go", "me", "when", "make", "can", "like", "time", "no", "just", "him", "know", "take", "into", "else", "other", "again", "your", "good", "some", "could", "them", "see", "other", "than", "then", "now", "look", "only", "come", "its", "over", "think", "also", "back", "else", "after", "use", "two", "how", "our", "work", "first", "well", "way", "even", "new", "want", "because", "any", "these", "give", "day", "most", "us", "call", "create", "edit", "new", "delete", "destroy", "update" ]
Instance Attribute Summary collapse
-
#object_candidate ⇒ Object
Returns the value of attribute object_candidate.
-
#source_methods ⇒ Object
Returns the value of attribute source_methods.
Class Method Summary collapse
- .extract_candidates(method_defs) ⇒ Object
- .from(nodes) ⇒ Object
- .potential_objects_with_methods(nodes, threshold = DUPLICATE_THRESHOLD) ⇒ Object
Instance Attribute Details
#object_candidate ⇒ Object
Returns the value of attribute object_candidate.
7 8 9 |
# File 'lib/snuffle/latent_object.rb', line 7 def object_candidate @object_candidate end |
#source_methods ⇒ Object
Returns the value of attribute source_methods.
7 8 9 |
# File 'lib/snuffle/latent_object.rb', line 7 def source_methods @source_methods end |
Class Method Details
.extract_candidates(method_defs) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/snuffle/latent_object.rb', line 35 def self.extract_candidates(method_defs) stemmer = UEAStemmer.new method_defs.map(&:method_name).inject({}) do |words, method_name| atoms = method_name.split('_') - STOPWORDS atoms = atoms.map{|atom| stemmer.stem(atom.to_s)} atoms.each{ |word| words[word] ||= []; words[word] << method_name } words end end |
.from(nodes) ⇒ Object
24 25 26 27 28 |
# File 'lib/snuffle/latent_object.rb', line 24 def self.from(nodes) potential_objects_with_methods(nodes).map do |k,v| new(object_candidate: k, source_methods: v) end end |
.potential_objects_with_methods(nodes, threshold = DUPLICATE_THRESHOLD) ⇒ Object
30 31 32 33 |
# File 'lib/snuffle/latent_object.rb', line 30 def self.potential_objects_with_methods(nodes, threshold=DUPLICATE_THRESHOLD) method_candidates = Snuffle::Element::MethodDefinition.materialize(nodes.method_defs) extract_candidates(method_candidates).select{|k,v| v.count > threshold } end |