Class: NGram
- Inherits:
-
Object
- Object
- NGram
- Defined in:
- lib/ngram.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#padchar ⇒ Object
Returns the value of attribute padchar.
-
#size ⇒ Object
Returns the value of attribute size.
-
#word_separator ⇒ Object
Returns the value of attribute word_separator.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ NGram
constructor
A new instance of NGram.
- #parse(phrase) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ NGram
Returns a new instance of NGram.
6 7 8 9 10 |
# File 'lib/ngram.rb', line 6 def initialize(opts={}) @size = opts[:size]||2 @word_separator = opts[:word_separator]||" " @padchar = opts[:padchar]||"_" end |
Instance Attribute Details
#padchar ⇒ Object
Returns the value of attribute padchar.
4 5 6 |
# File 'lib/ngram.rb', line 4 def padchar @padchar end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/ngram.rb', line 4 def size @size end |
#word_separator ⇒ Object
Returns the value of attribute word_separator.
4 5 6 |
# File 'lib/ngram.rb', line 4 def word_separator @word_separator end |
Instance Method Details
#parse(phrase) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/ngram.rb', line 12 def parse(phrase) words = phrase.split(@separator) if words.length == 1 process(phrase) else words.map { |w| process(w) } end end |