markov_chains 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee16106b2590f0bc8e9eda0d97a5fcc271ee22f3
4
- data.tar.gz: 6858012c3c1f13b9f29992dcf4b61a955424d687
3
+ metadata.gz: 2a5502df6fbd5d786c29c3c73eeccc2aadf024a8
4
+ data.tar.gz: ad36913b85e82c09e51e2d4737554c3b05a05f6a
5
5
  SHA512:
6
- metadata.gz: d52d880b9f62e9eab776176cd03bc5513442a078fa992a5c0f157a1a15465d63a08386cfa15c0bc50801fef944809c824892bc495de566de02c8cf85447119f4
7
- data.tar.gz: b80a72e8a71bb2c1b90355b1347e7b41032794716ad9cab3ad820062d32634265e9bd33e4b3de1ea6c1a647bc06cf063a8a21466763a235d97207930dbfb3a3a
6
+ metadata.gz: f9a1b39ef2e706d7228f610c05100cd98faf8d60fe03bc26193fe7b0700952a09b791da004986488e327644582b9386518ce6fd9c0964e354756ac42e0896387
7
+ data.tar.gz: 9de8d90926e2bb63ff65f34bed0d826c4081829946c1aa013c614c5d696b290c4cb4ab758e411c89fbcce1098a74bcf1e183ac0cd18dd5a4265fa964642d9fa0
@@ -28,32 +28,6 @@ module MarkovChains
28
28
  sentences = text.split seps
29
29
  sentences.each_slice(2) { |s,t| process_sentence(s.strip,t) }
30
30
  end
31
-
32
- # Processes a single sentence with terminator
33
- #
34
- # @example Process a sentence
35
- # process_sentence("It is sunny today", "!")
36
- #
37
- # @param [String] sentence to process
38
- # @param [Character] sentence terminator
39
- #
40
- private def process_sentence(sentence, terminator)
41
- # Consider phrases/words/clauses separators when splitting
42
- seps = "([,;:])"
43
-
44
- # Split <sentence> into words
45
- words = sentence.gsub(/[^#{seps}\w'\s]/, "").gsub(/(#{seps})\s+/, '\1').split(/\s+|#{seps}/)
46
- words << terminator
47
-
48
- # Add <@order> start words to the list
49
- @start_words << words[0, @order]
50
-
51
- # Add the words to the frequency hash <words_for>
52
- until words.size < @order + 1 do
53
- (@words_for[words[0, @order]] ||= []) << words[@order]
54
- words.shift
55
- end
56
- end
57
31
 
58
32
  # Returns a word based on the likelihood of it appearing after the input array of words
59
33
  #
@@ -79,5 +53,33 @@ module MarkovChains
79
53
  def get_start_words
80
54
  @start_words.sample
81
55
  end
56
+
57
+ private
58
+
59
+ # Processes a single sentence with terminator
60
+ #
61
+ # @example Process a sentence
62
+ # process_sentence("It is sunny today", "!")
63
+ #
64
+ # @param [String] sentence to process
65
+ # @param [Character] sentence terminator
66
+ #
67
+ def process_sentence(sentence, terminator)
68
+ # Consider phrases/words/clauses separators when splitting
69
+ seps = "([,;:])"
70
+
71
+ # Split <sentence> into words
72
+ words = sentence.gsub(/[^#{seps}\w'\s]/, "").gsub(/(#{seps})\s+/, '\1').split(/\s+|#{seps}/)
73
+ words << terminator
74
+
75
+ # Add <@order> start words to the list
76
+ @start_words << words[0, @order]
77
+
78
+ # Add the words to the frequency hash <words_for>
79
+ until words.size < @order + 1 do
80
+ (@words_for[words[0, @order]] ||= []) << words[@order]
81
+ words.shift
82
+ end
83
+ end
82
84
  end
83
85
  end
@@ -1,3 +1,3 @@
1
1
  module MarkovChains
2
- VERSION = '0.1.0'
3
- end
2
+ VERSION = '0.1.1'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markov_chains
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - justindomingue