generate random string from a canonical form useful for responding like humans
Join the DZone community and get the full member experience.Join For Free
#!/usr/bin/env ruby # generate a single sentence from a canonical form # canonical sentence is a multi sentences combined in one # form, generator will generate a sentence from it randomly # based on the form, for example: # "Hello [Emad|Elsaid]" , may generate "Hello Emad" or # "Hello Elsaid" the result is random. # also you could nest  inside each other to gain a multi level # canonical sentence example: # "[[Hi|Hello] [Emad|elsaid] | good [morning|night] sir]" def generate(result) while result.include? '[' s_start = result.index '[' s_end = s_start+1 while s_end
Opinions expressed by DZone contributors are their own.