Class: Ngram
- Inherits:
-
Object
- Object
- Ngram
- Defined in:
- lib/ruby_nlp/ngram.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #bigrams ⇒ Object
-
#initialize(target, options = { regex: / / }) ⇒ Ngram
constructor
A new instance of Ngram.
- #ngrams(n) ⇒ Object
- #trigrams ⇒ Object
- #unigrams ⇒ Object
Constructor Details
#initialize(target, options = { regex: / / }) ⇒ Ngram
Returns a new instance of Ngram.
4 5 6 7 |
# File 'lib/ruby_nlp/ngram.rb', line 4 def initialize(target, = { regex: / / }) @target = target @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
2 3 4 |
# File 'lib/ruby_nlp/ngram.rb', line 2 def @options end |
Instance Method Details
#bigrams ⇒ Object
17 18 19 |
# File 'lib/ruby_nlp/ngram.rb', line 17 def bigrams ngrams(2) end |
#ngrams(n) ⇒ Object
9 10 11 |
# File 'lib/ruby_nlp/ngram.rb', line 9 def ngrams(n) @target.split(@options[:regex]).each_cons(n).to_a end |
#trigrams ⇒ Object
21 22 23 |
# File 'lib/ruby_nlp/ngram.rb', line 21 def trigrams ngrams(3) end |
#unigrams ⇒ Object
13 14 15 |
# File 'lib/ruby_nlp/ngram.rb', line 13 def unigrams ngrams(1) end |