class Ngram

Attributes

options[RW]

Public Class Methods

new(target, options = { regex: / / }) click to toggle source
# File lib/ruby_nlp/ngram.rb, line 4
def initialize(target, options = { regex: / / })
  @target = target
  @options = options
end

Public Instance Methods

bigrams() click to toggle source
# File lib/ruby_nlp/ngram.rb, line 17
def bigrams
  ngrams(2)
end
ngrams(n) click to toggle source
# File lib/ruby_nlp/ngram.rb, line 9
def ngrams(n)
  @target.split(@options[:regex]).each_cons(n).to_a
end
trigrams() click to toggle source
# File lib/ruby_nlp/ngram.rb, line 21
def trigrams
  ngrams(3)
end
unigrams() click to toggle source
# File lib/ruby_nlp/ngram.rb, line 13
def unigrams
  ngrams(1)
end