lita-markov 1.0.1 → 1.0.2
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 +4 -4
- data/lib/lita/handlers/markov/engine.rb +19 -8
- data/lib/lita/handlers/markov.rb +7 -2
- data/lita-markov.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b5c291ff7b19be493ce427ed3ef9d49eac2ba4d
|
4
|
+
data.tar.gz: bec9e862f464c5ed4daeeea15adf946bb22335b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f82af9abdb8fcd6c6413e6f384cf884034d34b4be5a63a6e6f28357d9465a02b81a215447ea16196730aca584ab7bb229b4e8de03bcdcc4615ab9d94c9ab722
|
7
|
+
data.tar.gz: b7bc2ad646600648117a2013986d56a02ad803cba950e8e81167f429f688742c5fe08625ae53fa294e507c041f9bbb09500a30d9c8ad2f144bf423fd4f0d6ca8
|
@@ -69,8 +69,10 @@ class Lita::Handlers::Markov
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
def random_capitalized_word
|
73
|
-
states = @db[:dictionary]
|
72
|
+
def random_capitalized_word(user)
|
73
|
+
states = @db[:dictionary]
|
74
|
+
.where(user: user)
|
75
|
+
.map(:current_state)
|
74
76
|
|
75
77
|
capitalized_states = states.select do |state|
|
76
78
|
/^[A-Z]/ =~ state
|
@@ -87,9 +89,10 @@ class Lita::Handlers::Markov
|
|
87
89
|
return state.split(' ').first
|
88
90
|
end
|
89
91
|
|
90
|
-
def random_second_word(first_word)
|
92
|
+
def random_second_word(user, first_word)
|
91
93
|
states = @db[:dictionary]
|
92
94
|
.where(Sequel.like(:current_state, first_word+'%'))
|
95
|
+
.where(user: user)
|
93
96
|
.map(:current_state)
|
94
97
|
|
95
98
|
state = states.sample
|
@@ -97,7 +100,7 @@ class Lita::Handlers::Markov
|
|
97
100
|
end
|
98
101
|
|
99
102
|
def is_punctuation?(string)
|
100
|
-
PUNCTUATION.any? { |p| string
|
103
|
+
PUNCTUATION.any? { |p| string == p }
|
101
104
|
end
|
102
105
|
|
103
106
|
def get_next_state(user, current_state)
|
@@ -114,10 +117,11 @@ class Lita::Handlers::Markov
|
|
114
117
|
end
|
115
118
|
|
116
119
|
def generate_sentence_for(user, length = 30)
|
117
|
-
first_word = random_capitalized_word
|
118
|
-
second_word = random_second_word first_word
|
120
|
+
first_word = random_capitalized_word user
|
121
|
+
second_word = random_second_word user, first_word
|
119
122
|
|
120
123
|
sentence = [first_word, second_word]
|
124
|
+
ended_with_punctuation = false
|
121
125
|
|
122
126
|
while sentence.length < length
|
123
127
|
current_state = sentence.slice(sentence.length - @depth, @depth).join ' '
|
@@ -129,10 +133,17 @@ class Lita::Handlers::Markov
|
|
129
133
|
|
130
134
|
sentence << next_state
|
131
135
|
|
132
|
-
|
136
|
+
if is_punctuation? next_state
|
137
|
+
ended_with_punctuation = true
|
138
|
+
break
|
139
|
+
end
|
133
140
|
end
|
134
141
|
|
135
|
-
sentence.slice(0..-2).join(' ')
|
142
|
+
chain = sentence.slice(0..-2).join(' ')
|
143
|
+
chain << ' ' unless ended_with_punctuation
|
144
|
+
chain << sentence.last
|
145
|
+
|
146
|
+
chain
|
136
147
|
end
|
137
148
|
|
138
149
|
def separate_string string
|
data/lib/lita/handlers/markov.rb
CHANGED
@@ -31,10 +31,15 @@ module Lita::Handlers
|
|
31
31
|
|
32
32
|
def generate(chat)
|
33
33
|
name = chat.matches[0][0].strip
|
34
|
-
|
34
|
+
user = Lita::User.fuzzy_find name
|
35
|
+
|
36
|
+
if user.nil?
|
37
|
+
chat.reply "Couldn't find the user #{name}. :("
|
38
|
+
return
|
39
|
+
end
|
35
40
|
|
36
41
|
begin
|
37
|
-
sentence = engine.generate_sentence_for id
|
42
|
+
sentence = engine.generate_sentence_for user.id
|
38
43
|
|
39
44
|
chat.reply sentence
|
40
45
|
rescue Engine::EmptyDictionaryError
|
data/lita-markov.gemspec
CHANGED