Method: Sequitur::Production#derive_step
- Defined in:
- lib/sequitur/production.rb
#derive_step(another) ⇒ Object
Replace every occurrence of 'another' production in self.rhs by the symbols in the rhs of 'another'.
Given the production p_A : a p_B b p_B c
And the production p_B : x y
Then...
p_A.derive_step(p_B)
Modifies p_A as into: p_A -> a x y b x y c
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/sequitur/production.rb', line 204 def derive_step(another) (0...rhs.size).to_a.reverse_each do |index| next unless rhs[index] == another rhs.insert_at(index + 1, another.rhs) another.decr_refcount rhs.delete_at(index) end recalc_digrams end |