From 96095e727f1af0cca913764f85a67011d132c104 Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Sun, 19 Jan 2014 15:30:48 +0000 Subject: Made repl version --- markov-repl.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 markov-repl.rb (limited to 'markov-repl.rb') 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 -- cgit v1.2.1