Class: Sequitur::Digram
- Inherits:
-
Object
- Object
- Sequitur::Digram
- Defined in:
- lib/sequitur/digram.rb
Overview
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.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
An unique hash key of the digram.
-
#production ⇒ Object
readonly
The production in which the digram occurs.
-
#symbols ⇒ Object
readonly
The sequence of two consecutive grammar symbols.
Instance Method Summary collapse
-
#==(other) ⇒ true/false
Equality testing.
-
#initialize(symbol1, symbol2, aProduction) ⇒ Digram
constructor
Constructor.
-
#repeating? ⇒ true/false
Does the digram consists of twice the same symbols?.
Constructor Details
#initialize(symbol1, symbol2, aProduction) ⇒ Digram
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.
27 28 29 30 31 |
# File 'lib/sequitur/digram.rb', line 27 def initialize(symbol1, symbol2, aProduction) @symbols = [symbol1, symbol2] @key = symbol1.hash.to_s(16) + ':' + symbol2.hash.to_s(16) @production = aProduction end |
Instance Attribute Details
#key ⇒ Object (readonly)
An unique hash key of the digram
14 15 16 |
# File 'lib/sequitur/digram.rb', line 14 def key @key end |
#production ⇒ Object (readonly)
The production in which the digram occurs
17 18 19 |
# File 'lib/sequitur/digram.rb', line 17 def production @production end |
#symbols ⇒ Object (readonly)
The sequence of two consecutive grammar symbols. The two symbols should respond to the :hash message.
11 12 13 |
# File 'lib/sequitur/digram.rb', line 11 def symbols @symbols end |
Instance Method Details
#==(other) ⇒ true/false
Equality testing. true iff keys of both digrams are equal, false otherwise
37 38 39 |
# File 'lib/sequitur/digram.rb', line 37 def ==(other) return key == other.key end |
#repeating? ⇒ true/false
Does the digram consists of twice the same symbols?
43 44 45 |
# File 'lib/sequitur/digram.rb', line 43 def repeating?() return symbols[0] == symbols[1] end |