Module: Raingrams::OpenVocabulary::OpenModel
- Included in:
- BigramModel, HexagramModel, MultigramModel, PentagramModel, QuadgramModel, TrigramModel, UnigramModel
- 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(opts = {}, &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(opts = {}, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/raingrams/open_vocabulary/open_model.rb', line 10 def initialize(opts={},&block) @lexicon = opts[:lexicon] || [] super(opts,&block) end |
#train_ngram(ngram) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/raingrams/open_vocabulary/open_model.rb', line 20 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
16 17 18 |
# File 'lib/raingrams/open_vocabulary/open_model.rb', line 16 def within_lexicon?(gram) @lexicon.include?(gram) end |