aboutsummaryrefslogtreecommitdiff
path: root/markov-repl.rb
blob: 624539fe876a42b02c4be0658787768ace4d3860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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