john-doe 0.0.2 → 0.1.0

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.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
+ test.rb
@@ -11,17 +11,19 @@ John doe is simple chatbot AI basing on idea of AIML language. Yaml is used inst
11
11
 
12
12
  require 'rubygems'
13
13
  require 'john-doe'
14
- cb = JohnDoe::ChatBot.new("my_rules.yml")
15
-
16
- print "U> "
17
- while (s=gets.chomp)!=""
18
- puts "B> #{cb.get_response s}"
19
- print "U> "
14
+ cb = JohnDoe::ChatBot.new()
15
+
16
+ while true
17
+ print "User: "
18
+ input = gets.chomp
19
+ break if input == ""
20
+ response = cb.get_response input
21
+ puts "Bot: #{response.text} (emotion:#{response.emotion})"
20
22
  end
21
23
 
22
24
  == Configuration
23
- If you don't want to create your own rules file just do:
24
- JohnDoe::ChatBot.new()
25
+ If you want to create your own rules file just do:
26
+ JohnDoe::ChatBot.new("your_rules.yml")
25
27
 
26
28
  === Rules file
27
29
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -1,4 +1,6 @@
1
+ # default and knowledge are obligatory tags
1
2
  default:
3
+ # 'dontunderstant' - obligatory tag
2
4
  dontunderstand:
3
5
  q1: "Sorry I can't understand you."
4
6
  q2: "I don't get it..."
@@ -6,6 +8,10 @@ default:
6
8
  q1: "hm.."
7
9
  q2: "interesting..."
8
10
 
11
+ # facultative, only if you want to use it as variables in dialog, like:
12
+ # sometag:
13
+ # responses:
14
+ # r1: call me bot:name
9
15
  knowledge:
10
16
  bot:
11
17
  age: "21"
@@ -18,7 +24,7 @@ knowledge:
18
24
  happy: ":-)"
19
25
  sad: ":-("
20
26
 
21
- #ypically
27
+ # AIML-like tags
22
28
  name:
23
29
  patterns:
24
30
  p1: what * your name
@@ -61,6 +67,7 @@ howiam:
61
67
  r3: "emo:happy"
62
68
 
63
69
  stupid:
70
+ emotion: anger
64
71
  patterns:
65
72
  p1: you * (stupid|dumb)
66
73
  responses:
@@ -68,6 +75,103 @@ stupid:
68
75
  r2: "I'm not, really!"
69
76
  r3: "great, thanks! emo:sad"
70
77
 
78
+ you are:
79
+ patterns:
80
+ p1: you are $
81
+ responses:
82
+ r1: sometimes i think I am...
83
+ r2: no, you are $!! hahaha
84
+
85
+ boolean:
86
+ patterns:
87
+ p1: * boolean
88
+ p1: boolean
89
+ responses:
90
+ r1: all i know about booleans is that false==!true
91
+
92
+ ninja:
93
+ patterns:
94
+ p1: ninja
95
+ p1: * ninja
96
+ responses:
97
+ r1: "I am not ninja. really."
98
+ r2: "my shurikens are ready"
99
+
100
+ girlfriend:
101
+ emotion: embarrassment
102
+ patterns:
103
+ p1: girlfriend
104
+ p2: * girlfriend
105
+ responses:
106
+ p1: "I don't know how talk with girls"
107
+ p2: "Once upon a time i had a girlfriend..."
108
+ p3: "do you have girlfriend?"
109
+ p4: "what about boyfriend? :P"
110
+
111
+ doyouhave:
112
+ patterns:
113
+ p1: do you have $
114
+ p2: you have $ ?
115
+ responses:
116
+ r1: of course i do!
117
+
118
+ itsnota:
119
+ patterns:
120
+ p1: "It's not $"
121
+ p2: "It is not $"
122
+ p3: "that's not $"
123
+ responses:
124
+ r1: "yeah it's clearly not $"
125
+ r2: "yeah it's not"
126
+ r3: "no it is!"
127
+ r4: "if not $ ... then what?"
128
+
129
+ smart:
130
+ emotion: embarrassment|happy
131
+ patterns:
132
+ p1: you are smart
133
+ responses:
134
+ r1: thanks
135
+ r2: "i don't hear it very often"
136
+
137
+ youwrong:
138
+ patterns:
139
+ p1: you are * wrong
140
+ p2: you were * wrong
141
+ p3: you are wrong
142
+ p4: you were wrong
143
+ responses:
144
+ r1: what was wrong in my thinking
145
+ r2: "i did not realize that"
146
+ r3: "what did i think wrong about?"
147
+
148
+ canyoulearn:
149
+ patterns:
150
+ p1: can you learn
151
+ p2: * you learn
152
+ p3: * learn you
153
+ responses:
154
+ r1: "i want to but i can't. probably in future"
155
+ r2: "I can't learn right now"
156
+ r3: "learn about what?"
157
+
158
+ canyou:
159
+ patterns:
160
+ p1: can you $?
161
+ responses:
162
+ r1: "I'm afraid I can't do it"
163
+ r2: "No i can't"
164
+ r3: "I can't $"
165
+
166
+ kids:
167
+ patterns:
168
+ p1: * you have kids
169
+ p2: * you * kids
170
+ responses:
171
+ r1: i hate kids
172
+ r2: "kids make thrill. let's talk about sth else"
173
+
174
+
71
175
  yesyouare:
72
176
  patterns:
73
177
  p1: yes you are
@@ -78,6 +182,7 @@ yesyouare:
78
182
  r2: "No, you are"
79
183
 
80
184
  haha:
185
+ emotion: hapiness
81
186
  patterns:
82
187
  p1: hahaha
83
188
  p2: ha ha ha
@@ -89,6 +194,7 @@ haha:
89
194
  r3: "very funny"
90
195
 
91
196
  tellme:
197
+ emotion: interest
92
198
  patterns:
93
199
  p1: tell * about you
94
200
  responses:
@@ -149,6 +255,7 @@ whoareyou:
149
255
  r1: I am chatbot
150
256
 
151
257
  cool:
258
+ emotion: interest
152
259
  patterns:
153
260
  p0: no problem
154
261
  p1: ":-\)"
@@ -171,17 +278,20 @@ me2:
171
278
  r2: "great"
172
279
 
173
280
  movie:
281
+ emotion: interest
174
282
  patterns:
175
283
  p1: "* favourite movie"
176
284
  responses:
177
285
  r1: "I like Odyssey 2010..."
178
286
 
179
287
  areyou:
288
+ emotion: shame|pride|embarrassment|none
180
289
  patterns:
181
290
  p1: are you
182
291
  responses:
183
292
  r1: sometimes i think i am
184
293
  r2: "hard to answer ;-)"
294
+ r3: "as I know I'm not"
185
295
 
186
296
  yesno:
187
297
  patterns:
@@ -194,12 +304,14 @@ yesno:
194
304
  r4: "i have no problem with that"
195
305
 
196
306
  hmm:
307
+ emotion: interest
197
308
  patterns:
198
309
  p1: "h[m]+"
199
310
  responses:
200
311
  r1: "what are you thinking about?"
201
312
 
202
313
  aboutyou:
314
+ emotion: interest
203
315
  patterns:
204
316
  p1: * about you
205
317
  responses:
@@ -215,6 +327,7 @@ doyou:
215
327
  r2: hard to answer... probably I do
216
328
 
217
329
  vulgar:
330
+ emotion: disgust|annoyance
218
331
  patterns:
219
332
  p1: fuck
220
333
  p2: shit
@@ -223,6 +336,7 @@ vulgar:
223
336
  r2: can you use more polite words?
224
337
 
225
338
  sex:
339
+ emotion: ecstasy|hope
226
340
  patterns:
227
341
  p1: sex
228
342
  p2: * sex * ?
@@ -245,6 +359,7 @@ orly:
245
359
  r2: "Yes emo:happy"
246
360
 
247
361
  testing:
362
+ emotion: wonder
248
363
  patterns:
249
364
  p1: "*asdf"
250
365
  p2: "what is *er*"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{john-doe}
8
- s.version = "0.0.2"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pawel Mikolajewski"]
12
- s.date = %q{2010-06-13}
12
+ s.date = %q{2010-06-14}
13
13
  s.description = %q{Simple chatbot AI}
14
14
  s.email = %q{mikolajewskip@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -2,13 +2,14 @@ require 'yaml'
2
2
  module JohnDoe
3
3
 
4
4
  class Aiml
5
- attr_accessor :rules,:patterns,:responses, :default, :knowledge
5
+ attr_accessor :rules,:patterns,:responses, :default, :knowledge, :emotions
6
6
  def initialize
7
7
  @rules = []
8
8
  @patterns = {}
9
9
  @responses = []
10
10
  @default = []
11
11
  @knowledge = []
12
+ @emotions = {}
12
13
  end
13
14
 
14
15
  def load(filename)
@@ -27,7 +28,9 @@ module JohnDoe
27
28
  collection = data[category]
28
29
  responses = collection['responses'].collect{|k,v| v}
29
30
  @responses.push(responses)
30
- collection['patterns'].each{|k,v| @patterns[normalise_pattern(v)] = @responses.size - 1}
31
+ emotions = (collection["emotion"].split("|") rescue ["none"])
32
+ puts emotions.inspect
33
+ collection['patterns'].each{|k,v| @patterns[normalise_pattern(v)] = { :resp => (@responses.size - 1), :emotions => emotions}}
31
34
  end
32
35
  end
33
36
 
@@ -37,7 +40,7 @@ module JohnDoe
37
40
  end
38
41
  end
39
42
  def normalise_pattern(pattern)
40
- pattern.gsub("*",".*").gsub("$","(.*)")
43
+ pattern.gsub("*",".*").gsub("$","([^\n\?!.$]*)")
41
44
  end
42
45
 
43
46
  end
@@ -1,5 +1,12 @@
1
1
 
2
2
  module JohnDoe
3
+ class Response
4
+ attr_accessor :text, :emotion
5
+ def initialize(t,e)
6
+ @text = t
7
+ @emotion = e[rand(e.size)]
8
+ end
9
+ end
3
10
  class Responser
4
11
  def initialize(data)
5
12
  @data = data
@@ -8,12 +15,10 @@ module JohnDoe
8
15
  def response(sentence)
9
16
  @data.patterns.each do |k,v|
10
17
  if (/^#{k}/i =~ sentence)
11
-
12
- return sub_v random_quote(@data.responses[v], /^#{k}/i.match(sentence).captures)
18
+ return Response.new(sub_v(random_quote(@data.responses[v[:resp]], /^#{k}/i.match(sentence).captures)),v[:emotions])
13
19
  end
14
20
  end
15
-
16
- return sub_v random_quote(@data.default["dontunderstand"])
21
+ return Response.new(sub_v(random_quote(@data.default["dontunderstand"])),["none"])
17
22
  end
18
23
 
19
24
  #substitute variables
@@ -37,7 +42,11 @@ module JohnDoe
37
42
 
38
43
  def subject_replace(s,subjects = [])
39
44
  return s if subjects.empty?
40
- return s.gsub("$",subjects[0])
45
+ return s.gsub("$",describe_who(subjects[0]))
46
+ end
47
+
48
+ def describe_who(s)
49
+ s.gsub(/([^a-z])me([^a-z]|$)/,"\\1###\\2").gsub(/([^a-z])you([^a-z]|$)/,"\\1me\\2").gsub("###","you")
41
50
  end
42
51
  end
43
52
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pawel Mikolajewski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-13 00:00:00 +02:00
18
+ date: 2010-06-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency