class Company::Mapping::TermFrequency

Raw term frequency (number of times a token appears in a given string - document)

Public Class Methods

new(tokenizer) click to toggle source
# File lib/company/mapping/tfidf/tf/term_frequency.rb, line 6
def initialize(tokenizer)
  @tokenizer = tokenizer
end

Public Instance Methods

calculate(text) click to toggle source

Calculates the raw term frequency given the contents of the document.

# File lib/company/mapping/tfidf/tf/term_frequency.rb, line 11
def calculate(text)
  rawFrequency(text)
end

Protected Instance Methods

rawFrequency(contents) click to toggle source
# File lib/company/mapping/tfidf/tf/term_frequency.rb, line 16
def rawFrequency(contents)
  @tokenizer.tokenize(contents).each_with_object({}) do |token, tf|
    tf[token] ||= 0
    tf[token] += 1
  end
end