Module Raingrams::OpenVocabulary::OpenModel
In: lib/raingrams/open_vocabulary/open_model.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

Attributes

lexicon  [R]  The fixed lexicon of this model

Public Class methods

[Source]

# File lib/raingrams/open_vocabulary/open_model.rb, line 10
      def initialize(options={},&block)
        @lexicon = (options[:lexicon] || [])

        @lexicon.map! do |word|
          word.to_gram
        end

        super(options,&block)
      end

Public Instance methods

[Source]

# File lib/raingrams/open_vocabulary/open_model.rb, line 24
      def train_ngram(ngram)
        ngram = ngram.map do |gram|
          if within_lexicon?(gram)
            gram
          else
            Tokens::Unknown
          end
        end

        return super(ngram)
      end

[Source]

# File lib/raingrams/open_vocabulary/open_model.rb, line 20
      def within_lexicon?(gram)
        @lexicon.include?(gram.to_gram)
      end

[Validate]