Module Raingrams::Helpers::Probability
In: lib/raingrams/helpers/probability.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 probability of the specified fragment occuring within arbitrary text.

[Source]

# File lib/raingrams/helpers/probability.rb, line 46
      def fragment_probability(fragment)
        probability_of_ngrams(ngrams_from_fragment(fragment))
      end

Returns the probability of the specified ngrams occurring within arbitrary text.

[Source]

# File lib/raingrams/helpers/probability.rb, line 22
      def probabilities_for(ngrams)
        table = {}

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

        return table
      end

Returns the probability of the specified ngram occurring within arbitrary text.

[Source]

# File lib/raingrams/helpers/probability.rb, line 8
      def probability_of_ngram(ngram)
        prefix = ngram.prefix

        if @prefixes.has_key?(prefix)
          return @prefixes[prefix].probability_of(ngram.last)
        else
          return 0.0
        end
      end

Returns the joint probability of the specified ngrams occurring within arbitrary text.

[Source]

# File lib/raingrams/helpers/probability.rb, line 36
      def probability_of_ngrams(ngrams)
        probabilities_for(ngrams).values.inject do |joint,prob|
          joint * prob
        end
      end

Returns the probability of the specified sentence occuring within arbitrary text.

[Source]

# File lib/raingrams/helpers/probability.rb, line 54
      def sentence_probability(sentence)
        probability_of_ngrams(ngrams_from_sentence(sentence))
      end

Returns the probability of the specified text occuring within arbitrary text.

[Source]

# File lib/raingrams/helpers/probability.rb, line 62
      def text_probability(text)
        probability_of_ngrams(ngrams_from_text(text))
      end

[Validate]