Created
August 2, 2016 06:26
-
-
Save dyama/b4a0aaa3f246236a9cc848eb666a43d3 to your computer and use it in GitHub Desktop.
Markov
This file contains hidden or 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
#!/usr/bin/ruby | |
# coding: utf-8 | |
ts = {} | |
as = [] | |
(`chasen source.txt`).each_line do |line| | |
as.push line.split(/\t/)[0] | |
end | |
as.each_cons(2) do |ar| | |
if ts.key? ar.first | |
ts[ar.first].push(ar.last) | |
else | |
ts[ar.first] = [ar.last] | |
end | |
end | |
(0..10).each do | |
w = "」" | |
while w == "」" | |
w = ts["。"][rand(ts["。"].size)] | |
end | |
while true | |
printf w | |
if w == "。" || w == "」" | |
break | |
end | |
w = ts[w][rand(ts[w].size)] | |
end | |
puts "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment