Module: Raingrams::Helpers::Frequency
- Included in:
- Model
- Defined in:
- lib/raingrams/helpers/frequency.rb
Instance Method Summary collapse
-
#frequencies_for(ngrams) ⇒ Object
Returns the observed frequency of the specified ngrams occurring within the training text.
-
#frequency_of_ngram(ngram) ⇒ Object
Returns the observed frequency of the specified ngram within the training text.
-
#frequency_of_ngrams(ngrams) ⇒ Object
Returns the total observed frequency of the specified ngrams occurring within the training text.
Instance Method Details
#frequencies_for(ngrams) ⇒ Object
Returns the observed frequency of the specified ngrams occurring within the training text.
22 23 24 25 26 27 28 29 30 |
# File 'lib/raingrams/helpers/frequency.rb', line 22 def frequencies_for(ngrams) table = {} ngrams.each do |ngram| table[ngram] = frequency_of_ngram(ngram) end return table end |
#frequency_of_ngram(ngram) ⇒ Object
Returns the observed frequency of the specified ngram within the training text.
8 9 10 11 12 13 14 15 16 |
# File 'lib/raingrams/helpers/frequency.rb', line 8 def frequency_of_ngram(ngram) prefix = ngram.prefix if @prefixes.has_key?(prefix) return @prefixes[prefix].frequency_of(ngram.last) else return 0 end end |
#frequency_of_ngrams(ngrams) ⇒ Object
Returns the total observed frequency of the specified ngrams occurring within the training text.
36 37 38 39 40 |
# File 'lib/raingrams/helpers/frequency.rb', line 36 def frequency_of_ngrams(ngrams) frequencies_for(ngrams).values.inject do |total,freq| total + freq end end |