aboutsummaryrefslogtreecommitdiff
path: root/markov-repl.rb
diff options
context:
space:
mode:
Diffstat (limited to 'markov-repl.rb')
-rwxr-xr-xmarkov-repl.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/markov-repl.rb b/markov-repl.rb
new file mode 100755
index 0000000..624539f
--- /dev/null
+++ b/markov-repl.rb
@@ -0,0 +1,35 @@
+#!/usr/bin/env ruby
+
+require './markov-analyse.rb'
+require './markov-generate.rb'
+require 'readline'
+
+$replstate = Hash.new
+
+def handle_input(inputs)
+ input = inputs.split
+ case input[0]
+ when 'load'
+ case input[1]
+ when 'corpus'
+ $replstate[:analyser] = Markov::Analyser.new(input[2], input[3].to_i)
+ when 'serial'
+ $replstate[:generator] = Markov::Generator.new(input[2])
+ end
+ when 'analyse'
+ $replstate[:analyser].analyse
+ when 'save'
+ $replstate[:analyser].save(input[1])
+ when 'generate'
+ $replstate[:generator].generate(input[1].to_i)
+ when 'quit'
+ puts
+ exit
+ end
+end
+
+trap('INT'){puts; exit}
+
+while line = Readline.readline('>> ', true) do
+ handle_input(line)
+end