Skip to content

Instantly share code, notes, and snippets.

@dyama
Created August 2, 2016 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyama/b4a0aaa3f246236a9cc848eb666a43d3 to your computer and use it in GitHub Desktop.
Save dyama/b4a0aaa3f246236a9cc848eb666a43d3 to your computer and use it in GitHub Desktop.
Markov
#!/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