diff options
author | Nathan Lasseter <nathan@4574.co.uk> | 2014-01-19 15:30:48 +0000 |
---|---|---|
committer | Nathan Lasseter <nathan@4574.co.uk> | 2014-01-19 15:30:48 +0000 |
commit | 96095e727f1af0cca913764f85a67011d132c104 (patch) | |
tree | 4b8d240619604ae88235dae13a4cc09cf5714e0b /markov-repl.rb | |
parent | 214e8900240e2f98fba5b1553ed792ad8ff6f56f (diff) |
Made repl version
Diffstat (limited to 'markov-repl.rb')
-rwxr-xr-x | markov-repl.rb | 35 |
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 |