class Sequitur::Digram
In linguistics, a digram is a sequence of two letters. In Sequitur
, a digram is a sequence of two consecutive symbols that appear in a production rule. Each symbol in a digram can be a terminal or not.
Attributes
@return [String] An unique hash key of the digram
@return [Sequitur::Production] The production in which the digram occurs
The sequence of two consecutive grammar symbols. @return [Array<String, Symbol>] The two symbols should respond to the :hash message.
Public Class Methods
Constructor. A digram represents a sequence of two symbols (that appears in a rhs of a production). Terminal symbols must respond to the :hash message. @param symbol1 [String, Symbol] First element of the digram @param symbol2 [String, Symbol] Second element of the digram @param aProduction [Sequitur::Production] Production
in which the RHS
the sequence symbol1 symbol2 appears.
# File lib/sequitur/digram.rb, line 29 def initialize(symbol1, symbol2, aProduction) @symbols = [symbol1, symbol2] @key = "#{symbol1.hash.to_s(16)}:#{symbol2.hash.to_s(16)}" @production = aProduction end
Public Instance Methods
Equality testing.
true iff keys of both digrams are equal, false otherwise
@param other [Sequitur::Digram] another to compare with @return [TrueClass, FalseClass]
# File lib/sequitur/digram.rb, line 39 def ==(other) key == other.key end
Does the digram consists of twice the same symbols? @return [TrueClass, FalseClass] true when symbols.first == symbols.last
# File lib/sequitur/digram.rb, line 45 def repeating? symbols[0] == symbols[1] end