Sha256: f22328e41adcd3c1b530c884fcf0fc94ab9ecadfceae2b92f42507b3a01c4704

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

class Snuffle::LatentObject

  include PoroPlus

  attr_accessor :object_candidate, :source_methods

  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",
    "one", "all", "would", "there", "their", "what", "so", "up", "out", "if",
    "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"
  ]

  def self.from(nodes)
    potential_objects_with_methods(nodes).map do |k,v|
      new(object_candidate: k, source_methods: v)
    end
  end

  def self.potential_objects_with_methods(nodes, threshold=DUPLICATE_THRESHOLD)
    method_candidates = Snuffle::Element::MethodDefinition.materialize(nodes.methods)
    extract_candidates(method_candidates).select{|k,v| v.count > threshold }
  end

  def self.extract_candidates(methods)
    methods.map(&:method_name).inject({}) do |words, method_name|
      atoms = method_name.split('_') - STOPWORDS
      atoms.each{ |word| words[word] ||= []; words[word] << method_name }
      words
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
snuffle-0.11.1 lib/snuffle/latent_object.rb
snuffle-0.10.1 lib/snuffle/latent_object.rb