markov_noodles 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/markov_noodles.rb +3 -10
  3. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25c202c27f6207b467221cbf0d8a009ee19638f6
4
- data.tar.gz: 747f38c46ad2775a86b10c6469d434597911aef4
3
+ metadata.gz: b34a2ec2ef6953c0bc94374e2f42c7c1051a1368
4
+ data.tar.gz: 4489f26f93d2e914d5c4a9f29d03f586384ad1e1
5
5
  SHA512:
6
- metadata.gz: 6b097a3bb1b3973b4fd1780c5b8d3d1000918e4ef42dab87f7c2401b1f67cb86eb8cf2869778ba81b613d374c11a766ecde8060b590853ee1c00da5274c1693c
7
- data.tar.gz: 9ff568d2373c0003c4e2982d6a0156815bbe672f0560f274c963d855521956a698d20c3a2d1be76534c0317ae15d4c0b9a2b1154abf417cfad199b8cc062e8c2
6
+ metadata.gz: 3b33bf239c5c2d30e57f77c07f76477a8be9db8cf576ad4948a31fa6825b2968d1b5803932bbb9aff9c0f4d8b430b47c6568ba15d5035be7e78f4acbf3ba428c
7
+ data.tar.gz: ec28d8ab3a6fd2657d081cceee28c4137c97968b19c8cacd4be21ce16248b133d999f7eb7c7035f8a57c94be51c36628e94fb2c5e32e054651ee88db634d39ac
@@ -6,7 +6,7 @@ class MarkovNoodles
6
6
 
7
7
  def initialize(depth = 2)
8
8
  @depth = depth
9
- @dictionary = {}
9
+ @dictionary = Hash.new { |hash, missing_word| hash[missing_word] = [] }
10
10
  end
11
11
 
12
12
  def analyse_file(filename)
@@ -35,13 +35,7 @@ class MarkovNoodles
35
35
  end
36
36
 
37
37
  def generate_n_sentences(n)
38
- text = ''
39
- n.times do |i|
40
- text.concat(generate_sentence)
41
- is_last_sentence = i == (n - 1)
42
- text.concat(' ') unless is_last_sentence
43
- end
44
- text
38
+ n.times.map { generate_sentence }.join(' ')
45
39
  end
46
40
 
47
41
  def generate_sentence
@@ -52,7 +46,7 @@ class MarkovNoodles
52
46
  sentence_array.push new_word if new_word
53
47
  break if end_word?(new_word)
54
48
  next_word_options = @dictionary[current_words]
55
- if next_word_options.nil? && !end_word?(new_word)
49
+ if next_word_options.empty? && !end_word?(new_word)
56
50
  new_word.concat('.')
57
51
  break
58
52
  end
@@ -84,7 +78,6 @@ class MarkovNoodles
84
78
  end
85
79
 
86
80
  def add_words(preceding, followedby)
87
- @dictionary[preceding] ||= []
88
81
  @dictionary[preceding].push followedby
89
82
  end
90
83
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markov_noodles
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filip Defar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: msgpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
13
27
  description: Noodles uses Markov chains to generate superficially real-looking text
14
28
  given a sample document.
15
29
  email: filip.defar@gmail.com