-
-
Save wbzyl/f54ed5b841b3893a83ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stems = ARGF.read | |
.split | |
.each_cons(2) | |
.group_by { |word_pair| word_pair[0] } | |
def next_word ary | |
ary[rand(ary.length).to_i][1] | |
end | |
e = Enumerator.new do |e| | |
word = stems.first.first | |
while word | |
e << word | |
word = next_word(stems[word] || stems.first) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment