class Documentally::Document
Attributes
name[R]
term_hash[RW]
Public Class Methods
new(name, terms)
click to toggle source
# File lib/documentally/document.rb, line 5 def initialize(name, terms) @name = name @term_hash = Hash.new(0.0) terms.each do |term| @term_hash[term] += 1 end end
Public Instance Methods
==(other)
click to toggle source
# File lib/documentally/document.rb, line 26 def ==(other) union_of_terms = (terms + other.terms).uniq union_of_terms.all? { |term| frequency(term) == other.frequency(term) } end
frequency(term)
click to toggle source
# File lib/documentally/document.rb, line 22 def frequency(term) term_hash[term] end
normalize!(corpus)
click to toggle source
# File lib/documentally/document.rb, line 35 def normalize!(corpus) terms.each do |term| term_hash[term] /= corpus.frequency(term) end end
similarity(query)
click to toggle source
# File lib/documentally/document.rb, line 31 def similarity(query) terms.map { |term| frequency(term) * query.frequency(term) }.inject(&:+) end
terms()
click to toggle source
# File lib/documentally/document.rb, line 18 def terms term_hash.keys end
to_s()
click to toggle source
# File lib/documentally/document.rb, line 14 def to_s name.to_s end