Module Raingrams::Helpers::Frequency
In: lib/raingrams/helpers/frequency.rb
Model TrigramModel BigramModel QuadgramModel PentagramModel HexagramModel Model TrigramModel BigramModel QuadgramModel PentagramModel HexagramModel RuntimeError PrefixFrequencyMissing Set NgramSet Array Ngram Token StopSentence StartSentence Unknown ProbabilityTable Tokens Commonality Random Similarity Frequency Probability Helpers OpenModel OpenVocabulary Raingrams dot/f_1.png

Methods

Public Instance methods

Returns the observed frequency of the specified ngrams occurring within the training text.

[Source]

# 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

Returns the observed frequency of the specified ngram within the training text.

[Source]

# 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

Returns the total observed frequency of the specified ngrams occurring within the training text.

[Source]

# 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

[Validate]