aboutsummaryrefslogtreecommitdiff
path: root/markov-repl.rb
blob: 0d0ae63fbac2bd3cd00d8b523bed2ad543dd3e40 (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
36
37
38
39
40
41
#!/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])
		when 'stats'
			unless input[2].nil? then
				$replstate[:generator] = Markov::Generator.new(input[2], :file)
			else
				$replstate[:generator] = Markov::Generator.new($replstate[:analyser].stats)
			end
		end
	when 'analyse'
		$replstate[:analyser].analyse(input[1].to_i)
	when 'save'
		$replstate[:analyser].save(input[1])
	when 'generate'
		$replstate[:generator].generate(input[1].to_i)
	when 'quit'
		puts
		exit
	else
		puts "Error"
	end
end

trap('INT'){puts; exit}

while line = Readline.readline('>> ', true) do
	handle_input(line)
end