marky_markov 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,25 +1,20 @@
1
1
  Marky Markov and the Funky Sentences
2
2
  ====================================
3
3
 
4
- Marky Markov is a naïve experiment in Markov Chain generation implemented
4
+ Marky Markov is an experiment in Markov Chain generation implemented
5
5
  in Ruby. It can be used both from the command-line and as a library within your code.
6
6
 
7
7
  NOTE: 0.3.0 now uses arrays with multiple entries per word instead of a
8
8
  hash key for each word with the value representing number of occurences.
9
- While a less elegant solution, it leads to faster text generation. We
10
- are also now using ox instead of yajl-json to store the dictionary
11
- as yajl-json does not appear to support arrays within hashes properly.
12
-
13
- NOTE: In the transition between 0.1.3 to 0.2.0 MarkyMarkov has added the
14
- ability to generate proper sentences (generate_n_sentences) instead of simply a
15
- maximum number of words. The command-line app has changed to sentences as its default
16
- behavior.
9
+ While a less elegant solution, it leads to much faster text generation.
17
10
 
18
11
  # Installation
19
12
 
20
13
  gem install marky_markov
21
14
 
22
- # Module Usage
15
+ # Imported Module Usage
16
+
17
+ ## Temporary Dictionary
23
18
 
24
19
  A basic usage of the TemporaryDictionary, which parses strings and files into a
25
20
  temporary dictionary that will not be saved to disk.
@@ -30,7 +25,9 @@ temporary dictionary that will not be saved to disk.
30
25
  markov.parse_file "filename.txt"
31
26
  puts markov.generate_n_sentences 5
32
27
  puts markov.generate_n_words 200
33
- markov.clear!
28
+ markov.clear! # Clear the temporary dictionary.
29
+
30
+ ## Persistent Dictionary
34
31
 
35
32
  Dictionary creates or opens a persistent dictionary at a location defined by its
36
33
  initalizer, and will allow you to build and save a dictionary over multiple runs.
@@ -45,6 +42,8 @@ of the dictionary name.
45
42
  puts markov.generate_n_sentences 2
46
43
  markov.save_dictionary! # Saves the modified dictionary/creates one if it didn't exist.
47
44
 
45
+ ## generate_20_words
46
+
48
47
  If you keep looking at generate_n_words or generate_n_sentences and wonder why you can't put a
49
48
  number in there, well, you can!
50
49
 
@@ -65,6 +64,8 @@ creates a dictionary with a depth of three words.
65
64
  `{["I", "hope", "this"] => ["makes"],
66
65
  ["hope", "this", "makes"] => ["sense"]`
67
66
 
67
+ ## Delete a Dictionary
68
+
68
69
  If you want to delete a dictionary you call it upon the Dictionary class itself while
69
70
  passing in the filename/location.
70
71
 
data/bin/marky_markov CHANGED
@@ -23,6 +23,9 @@ opt_parser = OptionParser.new do |opts|
23
23
  options[:sentencecount] = 5
24
24
  opts.on('-c', '--sentencecount NUMBER', 'Set number of sentences generated') do |number|
25
25
  options[:sentencecount] = number.to_i
26
+ if options[:sentencecount] < 1
27
+ abort("You must enter a number higher than 0. Try 4. Or maybe 10?")
28
+ end
26
29
  end
27
30
 
28
31
  options[:source] = nil
@@ -81,19 +84,15 @@ when "read"
81
84
  end
82
85
  when "listen"
83
86
  markov = MarkyMarkov::TemporaryDictionary.new
84
- begin
85
- markov.parse_string(STDIN.tty? ? ARGV[1] : STDIN.read)
86
- STDOUT.puts markov.generate_n_sentences(options[:sentencecount])
87
- rescue
88
- abort("Not enough words to generate a sentence.")
89
- end
87
+ markov.parse_string(STDIN.tty? ? ARGV[1] : STDIN.read)
88
+ STDOUT.puts markov.generate_n_sentences(options[:sentencecount])
90
89
  else
91
90
  unless STDIN.tty?
92
91
  markov = MarkyMarkov::TemporaryDictionary.new
93
92
  markov.parse_string(STDIN.read)
94
93
  STDOUT.puts markov.generate_n_sentences(options[:sentencecount])
95
94
  else
96
- STDERR.puts "Sorry, I don't know how to #{ARGV[0]}."
95
+ STDERR.puts "Sorry, I don't know how to #{ARGV[0]}." if ARGV[0]
97
96
  STDOUT.puts opt_parser
98
97
  exit false
99
98
  end
@@ -24,6 +24,8 @@ class MarkovDictionary # :nodoc:
24
24
  #
25
25
  # @example Adding a word
26
26
  # add_word("Hello", "world")
27
+ # @example Adding a multi-word dictionary
28
+ # add_word("You are", "awesome")
27
29
  def add_word(rootword, followedby)
28
30
  @dictionary[rootword] ||= []
29
31
  @dictionary[rootword] << followedby
@@ -73,7 +73,7 @@ class MarkovSentenceGenerator # :nodoc:
73
73
  sentence.concat(random_capitalized_word)
74
74
  (wordcount-1).times do
75
75
  word = weighted_random(sentence.last(@depth))
76
- if punctuation?(word[0])
76
+ if punctuation?(word)
77
77
  sentence[-1] = sentence.last.dup << word
78
78
  elsif word.nil?
79
79
  sentence.concat(random_capitalized_word)
@@ -16,7 +16,7 @@ class PersistentDictionary < MarkovDictionary # :nodoc:
16
16
  def initialize(dictionary, depth=2)
17
17
  @depth = depth
18
18
  unless (1..5).include?(depth)
19
- raise DepthNotInRangeError.new("Depth must be between 1 and 5")
19
+ raise DepthNotInRangeError.new("Depth must be between 1 and 5. For best results, use 2.")
20
20
  end
21
21
  @dictionarylocation = dictionary
22
22
  @split_words = /([.?!])|[\s]+/
data/lib/marky_markov.rb CHANGED
@@ -4,12 +4,12 @@
4
4
  require_relative 'marky_markov/persistent_dictionary'
5
5
  require_relative 'marky_markov/markov_sentence_generator'
6
6
 
7
- # @version = 0.3.3
7
+ # @version = 0.3.4
8
8
  # @author Matt Furden
9
9
  # Module containing TemporaryDictionary and Dictionary for creation of
10
10
  # Markov Chain Dictionaries and generating sentences from those dictionaries.
11
11
  module MarkyMarkov
12
- VERSION = '0.3.3'
12
+ VERSION = '0.3.4'
13
13
 
14
14
  class TemporaryDictionary
15
15
  # Create a new Temporary Markov Chain Dictionary and sentence generator for use.
data/marky_markov.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'marky_markov'
16
- s.version = '0.3.3'
17
- s.date = '2012-02-13'
16
+ s.version = '0.3.4'
17
+ s.date = '2012-02-27'
18
18
  s.rubyforge_project = 'marky_markov'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
data/spec/spec_helper.rb CHANGED
@@ -1 +1,2 @@
1
- require 'marky_markov'
1
+ require_relative '../lib/marky_markov'
2
+ require 'rspec/autorun'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marky_markov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-13 00:00:00.000000000 Z
12
+ date: 2012-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ox
16
- requirement: &70245354003740 !ruby/object:Gem::Requirement
16
+ requirement: &70229846255560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '1.4'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70245354003740
24
+ version_requirements: *70229846255560
25
25
  description: ! "MarkyMarkov makes it easy to generate simply Markov Chains based upon
26
26
  input from\n either a source file or a string. While usable as a module in your
27
27
  code it can also be called on\n from the command line and piped into like a standard
@@ -71,4 +71,3 @@ signing_key:
71
71
  specification_version: 2
72
72
  summary: Simple Markov Chain generation available in the command-line
73
73
  test_files: []
74
- has_rdoc: