lita-markov 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34357a93d6cd917570538738c72f1bc0d301b78b
4
- data.tar.gz: 4fa6a56d9c25baf00d141bb9d593bc11bf3fc469
3
+ metadata.gz: 899ea3cf061e0e9e60046fa630ecc85ac0c62d3c
4
+ data.tar.gz: c9c47683d42548b71f6b9adcf17130786d0e7ae3
5
5
  SHA512:
6
- metadata.gz: a139b7b1e4618b420addacdaf0732885d02defcbc0c741186c892efb85b7d9dba0ea230b6dffd544903cac599f257f73624158340cf7baf10cf1cb745f84189a
7
- data.tar.gz: 7737301aa793730960cc142892586d64d6a8e5310760fe4ad868d792610d04240ba253f2bd69c24148c3c5be2cd842efa4d9bce7fbef8a698c111c3aac2c682a
6
+ metadata.gz: f52a9534465220eadd3b53cee38d98169f04640696deb168a4c7dcc549b3f19587c6d508046c950b99438894d962f527a8c4f8affbf36bdd8b58b92ecb4e4548
7
+ data.tar.gz: ee9904cfdaef57ca3757407511e90763fac96173b0897973cd6616a21915b3a8a41da460f56fd9767c85e35f56069d4c77774a7afa1ac400be8274393470d31a
@@ -36,8 +36,8 @@ class Lita::Handlers::Markov
36
36
 
37
37
  return if words.length == 0
38
38
 
39
- # Capitalize the first word
40
- words = [words[0].capitalize] + words.slice(1..-1)
39
+ # Capitalize the first word and add a period at the end
40
+ words = [words[0].capitalize] + words.slice(1..-1) + ['.']
41
41
 
42
42
  # Iterate over it one step at a time in sets of `@depth + 1`
43
43
  words.each_cons(@depth + 1) do |words|
@@ -99,10 +99,6 @@ class Lita::Handlers::Markov
99
99
  state.split(' ').last
100
100
  end
101
101
 
102
- def is_punctuation?(string)
103
- PUNCTUATION.any? { |p| string == p }
104
- end
105
-
106
102
  def get_next_state(user, current_state)
107
103
  states = @db[:dictionary]
108
104
  .where(user: user, current_state: current_state)
@@ -133,7 +129,7 @@ class Lita::Handlers::Markov
133
129
 
134
130
  sentence << next_state
135
131
 
136
- if is_punctuation? next_state
132
+ if next_state == '.'
137
133
  ended_with_punctuation = true
138
134
  break
139
135
  end
@@ -146,7 +142,7 @@ class Lita::Handlers::Markov
146
142
  chain
147
143
  end
148
144
 
149
- STRING_SEPARATOR = /([.!?])|\s+/
145
+ STRING_SEPARATOR = /\s+/
150
146
 
151
147
  def separate_string string
152
148
  # Including the punctuation in group so they'll be included in the
@@ -157,33 +153,22 @@ class Lita::Handlers::Markov
157
153
  .select { |w| !w.empty? }
158
154
  end
159
155
 
160
- PUNCTUATION = [',', '.', '!', '?']
161
-
162
156
  # Don't allow anything besides letters, digits, whitespace, and puncutation
163
- ILLEGAL_CHARACTERS = /[^\w\d\s:;,.!?#@]/
157
+ NON_WORD_CHARACTERS = /[^\w\d'"“”’:+-]/
164
158
 
165
159
  HYPERLINKS = /http[^\s]+/
166
160
  SIMPLE_CODE_BLOCK = /`[^`]+`/
167
161
  EXTENDED_CODE_BLOCK = /```.+```/m
168
-
169
- REPEATED_PUNCTUATION = /([.!?])[.!?]+/
170
- BASIC_PUNCTUATION = /([;,.!?])/
171
-
162
+ REPEATED_WHITESPACE = /\s+/
172
163
 
173
164
  def sanitize_string string
174
165
  string = string
175
166
  .gsub(HYPERLINKS, ''.freeze) # Remove any hyperlinks
176
167
  .gsub(SIMPLE_CODE_BLOCK, ''.freeze) # Remove code blocks and illegal characters
177
168
  .gsub(EXTENDED_CODE_BLOCK, ''.freeze)
178
- .gsub(ILLEGAL_CHARACTERS, ''.freeze)
179
- .gsub(REPEATED_PUNCTUATION, '\1'.freeze) # Trim down repeated punctuation
180
- .gsub(BASIC_PUNCTUATION, '\1 '.freeze) # Put whitespace after punctuation for proper separation
169
+ .gsub(NON_WORD_CHARACTERS, ' '.freeze) # Convert non-word characters into whitespace
170
+ .gsub(REPEATED_WHITESPACE, ' '.freeze) # Convert repeated whitespace into just single spaces
181
171
  .strip()
182
-
183
- ends_with_punctuation = PUNCTUATION.any? { |p| string.end_with? p }
184
- string = string+'.'.freeze unless ends_with_punctuation
185
-
186
- string
187
172
  end
188
173
  end
189
174
  end
data/lita-markov.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-markov"
3
- spec.version = "1.1.0"
3
+ spec.version = "1.1.1"
4
4
  spec.authors = ["Dirk Gadsden"]
5
5
  spec.email = ["dirk@dirk.to"]
6
6
  spec.description = "Markov chains for Lita."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-markov
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dirk Gadsden