Class Raingrams::Ngram
In: lib/raingrams/ngram.rb
Parent: Array
Model TrigramModel BigramModel QuadgramModel PentagramModel HexagramModel Model TrigramModel BigramModel QuadgramModel PentagramModel HexagramModel RuntimeError PrefixFrequencyMissing Set NgramSet Array Ngram Token StopSentence StartSentence Unknown ProbabilityTable Tokens Commonality Random Similarity Frequency Probability Helpers OpenModel OpenVocabulary Raingrams dot/f_1.png

Methods

+   <<   []   ends_with?   flatten   flatten!   include?   includes_all?   includes_any?   inspect   new   postfix   postfixed_by?   prefix   prefixed_by?   starts_with?   to_s  

Public Class methods

Creates a new Ngram object from the specified objects.

[Source]

# File lib/raingrams/ngram.rb, line 16
    def self.[](*objects)
      self.new(objects)
    end

Creates a new Ngram object with the specified objects.

[Source]

# File lib/raingrams/ngram.rb, line 9
    def initialize(objects)
      super(objects.map { |obj| obj.to_gram })
    end

Public Instance methods

Creates a new Ngram object by appending the specified grams to the ngram.

[Source]

# 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

[Source]

# File lib/raingrams/ngram.rb, line 34
    def <<(gram)
      super(gram.to_gram)
    end

[Source]

# File lib/raingrams/ngram.rb, line 65
    def ends_with?(obj)
      self.last == obj.to_gram
    end

[Source]

# File lib/raingrams/ngram.rb, line 81
    def flatten
      self.dup
    end

[Source]

# File lib/raingrams/ngram.rb, line 85
    def flatten!
      self
    end

[Source]

# File lib/raingrams/ngram.rb, line 69
    def include?(obj)
      super(obj.to_gram)
    end

[Source]

# File lib/raingrams/ngram.rb, line 77
    def includes_all?(*grams)
      grams.all? { |gram| include?(gram) }
    end

[Source]

# File lib/raingrams/ngram.rb, line 73
    def includes_any?(*grams)
      grams.any? { |gram| include?(gram) }
    end

[Source]

# File lib/raingrams/ngram.rb, line 93
    def inspect
      'Ngram[' + self.map { |gram| gram.inspect }.join(', ') + ']'
    end

[Source]

# File lib/raingrams/ngram.rb, line 53
    def postfix
      self[1..-1]
    end

[Source]

# File lib/raingrams/ngram.rb, line 57
    def postfixed_by?(ngram)
      postfix == ngram
    end

Returns the prefix of the ngram.

[Source]

# File lib/raingrams/ngram.rb, line 41
    def prefix
      self[0...length-1]
    end

Returns true if the ngram is prefixed by the specified smaller_ngram.

[Source]

# File lib/raingrams/ngram.rb, line 49
    def prefixed_by?(smaller_ngram)
      prefix == smaller_ngram
    end

[Source]

# File lib/raingrams/ngram.rb, line 61
    def starts_with?(obj)
      self.first == obj.to_gram
    end

[Source]

# File lib/raingrams/ngram.rb, line 89
    def to_s
      join(', ')
    end

[Validate]