class Snuffle::Cohort

Attributes

element[RW]
line_numbers[RW]
neighbors[RW]

Public Class Methods

from(nodes) click to toggle source
# 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

Public Instance Methods

distance(primary_matrix, token_matrix) click to toggle source
# 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?() click to toggle source
# File lib/snuffle/cohort.rb, line 19
def has_near_neighbors?
  near_neighbors.present?
end
near_neighbors() click to toggle source
# File lib/snuffle/cohort.rb, line 23
def near_neighbors
  @near_neighbors ||= neighbors.select{ |n| (n.values & values).size == values.size }
end
neighbor() click to toggle source
# File lib/snuffle/cohort.rb, line 35
def neighbor
  Struct.new(:element, :distance)
end
values() click to toggle source
# File lib/snuffle/cohort.rb, line 31
def values
  @values ||= self.element.values
end