Class: Raingrams::Ngram
Class Method Summary collapse
-
.[](*objects) ⇒ Object
Creates a new Ngram object from the specified objects.
Instance Method Summary collapse
-
#+(grams) ⇒ Object
Creates a new Ngram object by appending the specified grams to the ngram.
- #<<(gram) ⇒ Object
- #ends_with?(obj) ⇒ Boolean
- #flatten ⇒ Object
- #flatten! ⇒ Object
- #include?(obj) ⇒ Boolean
- #includes_all?(*grams) ⇒ Boolean
- #includes_any?(*grams) ⇒ Boolean
-
#initialize(objects) ⇒ Ngram
constructor
Creates a new Ngram object with the specified objects.
- #inspect ⇒ Object
- #postfix ⇒ Object
- #postfixed_by?(ngram) ⇒ Boolean
-
#prefix ⇒ Object
Returns the prefix of the ngram.
-
#prefixed_by?(smaller_ngram) ⇒ Boolean
Returns
true
if the ngram is prefixed by the specified smaller_ngram. - #starts_with?(obj) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(objects) ⇒ Ngram
Creates a new Ngram object with the specified objects.
9 10 11 |
# File 'lib/raingrams/ngram.rb', line 9 def initialize(objects) super(objects.map { |obj| obj.to_gram }) end |
Class Method Details
.[](*objects) ⇒ Object
Creates a new Ngram object from the specified objects.
16 17 18 |
# File 'lib/raingrams/ngram.rb', line 16 def self.[](*objects) self.new(objects) end |
Instance Method Details
#+(grams) ⇒ Object
Creates a new Ngram object by appending the specified grams to the ngram.
24 25 26 27 28 29 30 31 32 |
# File 'lib/raingrams/ngram.rb', line 24 def +(grams) if grams.kind_of?(Array) return self.class.new(super(grams.map { |gram| gram.to_gram })) else return self.class.new(super([grams.to_gram])) end end |
#<<(gram) ⇒ Object
34 35 36 |
# File 'lib/raingrams/ngram.rb', line 34 def <<(gram) super(gram.to_gram) end |
#ends_with?(obj) ⇒ Boolean
65 66 67 |
# File 'lib/raingrams/ngram.rb', line 65 def ends_with?(obj) self.last == obj.to_gram end |
#flatten ⇒ Object
81 82 83 |
# File 'lib/raingrams/ngram.rb', line 81 def flatten self.dup end |
#flatten! ⇒ Object
85 86 87 |
# File 'lib/raingrams/ngram.rb', line 85 def flatten! self end |
#include?(obj) ⇒ Boolean
69 70 71 |
# File 'lib/raingrams/ngram.rb', line 69 def include?(obj) super(obj.to_gram) end |
#includes_all?(*grams) ⇒ Boolean
77 78 79 |
# File 'lib/raingrams/ngram.rb', line 77 def includes_all?(*grams) grams.all? { |gram| include?(gram) } end |
#includes_any?(*grams) ⇒ Boolean
73 74 75 |
# File 'lib/raingrams/ngram.rb', line 73 def includes_any?(*grams) grams.any? { |gram| include?(gram) } end |
#inspect ⇒ Object
93 94 95 |
# File 'lib/raingrams/ngram.rb', line 93 def inspect 'Ngram[' + self.map { |gram| gram.inspect }.join(', ') + ']' end |
#postfix ⇒ Object
53 54 55 |
# File 'lib/raingrams/ngram.rb', line 53 def postfix self[1..-1] end |
#postfixed_by?(ngram) ⇒ Boolean
57 58 59 |
# File 'lib/raingrams/ngram.rb', line 57 def postfixed_by?(ngram) postfix == ngram end |
#prefix ⇒ Object
Returns the prefix of the ngram.
41 42 43 |
# File 'lib/raingrams/ngram.rb', line 41 def prefix self[0...length-1] end |
#prefixed_by?(smaller_ngram) ⇒ Boolean
Returns true
if the ngram is prefixed by the specified smaller_ngram.
49 50 51 |
# File 'lib/raingrams/ngram.rb', line 49 def prefixed_by?(smaller_ngram) prefix == smaller_ngram end |
#starts_with?(obj) ⇒ Boolean
61 62 63 |
# File 'lib/raingrams/ngram.rb', line 61 def starts_with?(obj) self.first == obj.to_gram end |
#to_s ⇒ Object
89 90 91 |
# File 'lib/raingrams/ngram.rb', line 89 def to_s join(', ') end |