Class: Sequitur::Digram

Inherits:
Object
  • Object
show all
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 grammar (production) rule. Each symbol in a digram can be a terminal or not.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol1, symbol2, aProduction) ⇒ Digram

Constructor. the sequence symbol1 symbol2 appears.

Parameters:

  • First element of the digram

  • Second element of the digram

  • Production in which the RHS



24
25
26
27
28
# File 'lib/sequitur/digram.rb', line 24

def initialize(symbol1, symbol2, aProduction)
  @symbols = [symbol1, symbol2]
  @key = "#{symbol1.hash.to_s(16)}:#{symbol2.hash.to_s(16)}" 
  @production_id = aProduction.object_id
end

Instance Attribute Details

#keyObject (readonly)

An unique Hash key of the digram



17
18
19
# File 'lib/sequitur/digram.rb', line 17

def key
  @key
end

#production_idObject (readonly)

The object id of the production that contains this digram in its rhs.



14
15
16
# File 'lib/sequitur/digram.rb', line 14

def production_id
  @production_id
end

#symbolsObject (readonly)

The sequence of two consecutive grammar symbols.



11
12
13
# File 'lib/sequitur/digram.rb', line 11

def symbols
  @symbols
end

Instance Method Details

#productionObject

Return the production object of this digram



31
32
33
# File 'lib/sequitur/digram.rb', line 31

def production()
  ObjectSpace._id2ref(production_id)
end