Class: Snuffle::Cohort
- Inherits:
-
Object
- Object
- Snuffle::Cohort
- Includes:
- PoroPlus
- Defined in:
- lib/snuffle/cohort.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
Returns the value of attribute element.
-
#line_numbers ⇒ Object
Returns the value of attribute line_numbers.
-
#neighbors ⇒ Object
Returns the value of attribute neighbors.
Class Method Summary collapse
Instance Method Summary collapse
- #distance(primary_matrix, token_matrix) ⇒ Object
- #has_near_neighbors? ⇒ Boolean
- #near_neighbors ⇒ Object
- #neighbor ⇒ Object
- #values ⇒ Object
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
6 7 8 |
# File 'lib/snuffle/cohort.rb', line 6 def element @element end |
#line_numbers ⇒ Object
Returns the value of attribute line_numbers.
6 7 8 |
# File 'lib/snuffle/cohort.rb', line 6 def line_numbers @line_numbers end |
#neighbors ⇒ Object
Returns the value of attribute neighbors.
6 7 8 |
# File 'lib/snuffle/cohort.rb', line 6 def neighbors @neighbors end |
Class Method Details
.from(nodes) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/snuffle/cohort.rb', line 8 def self.from(nodes) nodes = nodes.non_sends.hashes cohorts = Element::Hash.materialize(nodes.to_a).inject([]) do |cohorts, element| cohort = Cohort.new(element: element, line_numbers: element.node.line_numbers ) if cohort.values.count > 1 && cohort.near_neighbors.count > 0 cohorts << cohort end cohorts end end |
Instance Method Details
#distance(primary_matrix, token_matrix) ⇒ Object
39 40 41 |
# File 'lib/snuffle/cohort.rb', line 39 def distance(primary_matrix, token_matrix) Snuffle::Util::Correlation.distance(primary_matrix, token_matrix) end |
#has_near_neighbors? ⇒ Boolean
19 20 21 |
# File 'lib/snuffle/cohort.rb', line 19 def has_near_neighbors? near_neighbors.present? end |
#near_neighbors ⇒ Object
23 24 25 |
# File 'lib/snuffle/cohort.rb', line 23 def near_neighbors @near_neighbors ||= neighbors.select{ |n| (n.values & values).size == values.size } end |
#neighbor ⇒ Object
35 36 37 |
# File 'lib/snuffle/cohort.rb', line 35 def neighbor Struct.new(:element, :distance) end |
#values ⇒ Object
31 32 33 |
# File 'lib/snuffle/cohort.rb', line 31 def values @values ||= self.element.values end |