I'm trying to push all the derivation of the sentence.
For example: The < animal > in the < object >
I want derivations to hold the expansions, so derivation[0]
would have "The cat in the < object >"
, while derivation[1]
would have "The cat in the hat"
.
However, all the derivations before getting overwritten by the final derivation.
How do I prevent this from happening?
while is_non_terminal?(sentence)
$key = sentence.match(/(\<[a-zA-Z0-9_\-*]+\>)/)
sentence.sub!(/(\<[a-zA-Z0-9_\-*]+\>)/){grammar[$key.to_s].sample.join(' ')}
derivations.push(sentence)
puts derivations.to_s
#puts sentence
end