Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/marky_markov
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#A Markov Chain generator.

require 'optparse'
require 'marky_markov'
require '../lib/marky_markov.rb'

options = {}
opt_parser = OptionParser.new do |opts|
Expand Down
6 changes: 3 additions & 3 deletions lib/marky_markov/markov_dictionary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ def open_source(source)
def add_word(rootword, followedby)
@dictionary[rootword] ||= []
@dictionary[rootword] << followedby
if followedby == followedby.capitalize
@capitalized_words.push followedby
end
end

# Given a source of text, be it a text file (file=true) or a string (file=false)
Expand All @@ -54,6 +51,9 @@ def parse_source(source, file=true)
end
contents.map! {|sentence| sentence.gsub(/["()]/,"")}
contents.each do |sentence|
split = sentence.split(@split_words)
split[0][0].upcase!
@capitalized_words.push split[0..@depth-1]
sentence.split(@split_words).each_cons(@depth+1) do |words|
self.add_word(words[0..-2], words[-1])
end
Expand Down
2 changes: 1 addition & 1 deletion lib/marky_markov/markov_sentence_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def generate_sentence(sentencecount)
maximum_length = key_count < 30 ? key_count + 5 : 30
sentencecount.times do
wordcount = 0
sentence.push(random_capitalized_word)
sentence.push(*random_capitalized_word)
until (punctuation?(sentence.last[-1])) || wordcount > maximum_length
wordcount += 1
word = weighted_random(sentence.last(@depth))
Expand Down