aboutsummaryrefslogtreecommitdiff
path: root/markov-analyse.rb
diff options
context:
space:
mode:
Diffstat (limited to 'markov-analyse.rb')
-rw-r--r--markov-analyse.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/markov-analyse.rb b/markov-analyse.rb
index 6c306ca..7263411 100644
--- a/markov-analyse.rb
+++ b/markov-analyse.rb
@@ -1,15 +1,15 @@
module Markov
class Analyser
- def initialize(inputfile, chunklength)
- @chunklength = chunklength
- @stats = {"__SETTINGS__" => {"__CHUNKLENGTH__" => @chunklength}}
-
+ def initialize(inputfile)
@words = File.readlines(inputfile)
.map(&:split)
.flatten
end
- def analyse
+ def analyse(chunklength)
+ @chunklength = chunklength
+ @stats = {"__SETTINGS__" => {"__CHUNKLENGTH__" => @chunklength}}
+
(0 .. (@words.length - @chunklength - @chunklength)).each do |i|
k = @words[i...(i+@chunklength)]
v = @words[(i+@chunklength)]
@@ -27,6 +27,10 @@ module Markov
end
end
+ def stats
+ return @stats
+ end
+
def save(outputfile)
File.new(outputfile, "w").print(Marshal::dump(@stats))
end