class Markov::Parser
Attributes
source[R]
Public Class Methods
new(source, options={})
click to toggle source
# File lib/markov/parser.rb, line 6 def initialize source, options={} @source = source end
Public Instance Methods
groups(chunk_size, options={})
click to toggle source
# File lib/markov/parser.rb, line 19 def groups chunk_size, options={} text = options[:tagged] ? tagged_text : raw_text words = text.split (chunk_size - 1).times { |r,a| words.unshift("\"\"") } words.each_cons(chunk_size).to_a.inject([]){ |r,a| r << { prefix: a[0..(chunk_size - 2)], suffix: a.last } } end
raw_text()
click to toggle source
# File lib/markov/parser.rb, line 10 def raw_text @raw_text ||= File.read(@source).scrub! end
tagged_text()
click to toggle source
# File lib/markov/parser.rb, line 14 def tagged_text tagger = EngTagger.new @tagged_text ||= tagger.get_readable(raw_text) end