Sha256: 3f1c6dcfbd28637e101e6aeb7564e6b9c34dfe512af6cc715811e33a0a8cf115

Contents?: true

Size: 989 Bytes

Versions: 1

Compression:

Stored size: 989 Bytes

Contents

module Raingrams
  module Helpers
    module Frequency
      #
      # Returns the observed frequency of the specified _ngram_ within
      # the training text.
      #
      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 observed frequency of the specified _ngrams_ occurring
      # within the training text.
      #
      def frequencies_for(ngrams)
        table = {}

        ngrams.each do |ngram|
          table[ngram] = frequency_of_ngram(ngram)
        end

        return table
      end

      #
      # Returns the total observed frequency of the specified _ngrams_
      # occurring within the training text.
      #
      def frequency_of_ngrams(ngrams)
        frequencies_for(ngrams).values.inject do |total,freq|
          total + freq
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
raingrams-0.1.2 lib/raingrams/helpers/frequency.rb