diff options
author | Nathan Lasseter <nathan@4574.co.uk> | 2014-01-30 20:10:56 +0000 |
---|---|---|
committer | Nathan Lasseter <nathan@4574.co.uk> | 2014-01-30 20:10:56 +0000 |
commit | 69ee9398256a7e15e64aa73428e7291f6f50a11c (patch) | |
tree | e0f6d35a62c2d1abf2589815a3e7b09d47b32841 /markov-analyse.rb | |
parent | 46804facd4b74e6c5796b3427ccbb1a273528395 (diff) |
Diffstat (limited to 'markov-analyse.rb')
-rw-r--r-- | markov-analyse.rb | 14 |
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 |