Module: Raingrams::OpenVocabulary::OpenModel
- Included in:
- BigramModel, HexagramModel, Model, PentagramModel, QuadgramModel, TrigramModel
- Defined in:
- lib/raingrams/open_vocabulary/open_model.rb
Instance Attribute Summary collapse
-
#lexicon ⇒ Object
readonly
The fixed lexicon of this model.
Instance Method Summary collapse
- #initialize(options = {}, &block) ⇒ Object
- #train_ngram(ngram) ⇒ Object
- #within_lexicon?(gram) ⇒ Boolean
Instance Attribute Details
#lexicon ⇒ Object (readonly)
The fixed lexicon of this model
8 9 10 |
# File 'lib/raingrams/open_vocabulary/open_model.rb', line 8 def lexicon @lexicon end |
Instance Method Details
#initialize(options = {}, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/raingrams/open_vocabulary/open_model.rb', line 10 def initialize(={},&block) @lexicon = ([:lexicon] || []) @lexicon.map! do |word| word.to_gram end super(,&block) end |
#train_ngram(ngram) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# 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 |
#within_lexicon?(gram) ⇒ Boolean
20 21 22 |
# File 'lib/raingrams/open_vocabulary/open_model.rb', line 20 def within_lexicon?(gram) @lexicon.include?(gram.to_gram) end |