john-doe 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/default.yml CHANGED
@@ -26,9 +26,10 @@ knowledge:
26
26
 
27
27
  # AIML-like tags
28
28
  name:
29
- patterns:
29
+ rank: 10
30
+ patterns:
30
31
  p1: what * your name
31
- p2: your name
32
+ p2: * your name
32
33
  responses:
33
34
  r1: "bot:name bot:surname"
34
35
  r2: "Call me bot:name"
@@ -200,7 +201,16 @@ tellme:
200
201
  responses:
201
202
  r1: "I am just normal bot:specimen"
202
203
  r2: "What do you want to know?"
204
+
205
+ because:
206
+ patterns:
207
+ p1: because
208
+ responses:
209
+ r1: "that's good reason"
210
+ r2: "thanks for explanation ;-)"
211
+
203
212
  specimen:
213
+ priority: 20
204
214
  patterns:
205
215
  p1: are you * human
206
216
  p2: are you * bot
@@ -350,6 +360,7 @@ asl:
350
360
  responses:
351
361
  r1: "bot:age bot:sex bot:language"
352
362
  orly:
363
+ priority: 10
353
364
  patterns:
354
365
  p1: "really?"
355
366
  p2: are you sure
Binary file
data/john-doe.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{john-doe}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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"]
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "default.yml",
27
+ "john-doe-0.1.0.gem",
27
28
  "john-doe.gemspec",
28
29
  "lib/john-doe.rb",
29
30
  "lib/johndoe/aiml.rb",
data/lib/johndoe/aiml.rb CHANGED
@@ -29,8 +29,8 @@ module JohnDoe
29
29
  responses = collection['responses'].collect{|k,v| v}
30
30
  @responses.push(responses)
31
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}}
32
+ priority = (collection["rank"].to_i rescue 0)
33
+ collection['patterns'].each{|k,v| @patterns[normalise_pattern(v)] = { :resp => (@responses.size - 1), :emotions => emotions, :priority => priority}}
34
34
  end
35
35
  end
36
36
 
@@ -13,12 +13,23 @@ module JohnDoe
13
13
  end
14
14
 
15
15
  def response(sentence)
16
+ max_priority = -1
17
+ best_v = nil
18
+ best_k = nil
19
+
16
20
  @data.patterns.each do |k,v|
17
21
  if (/^#{k}/i =~ sentence)
18
- return Response.new(sub_v(random_quote(@data.responses[v[:resp]], /^#{k}/i.match(sentence).captures)),v[:emotions])
22
+ next if v[:priority] <= max_priority
23
+ max_priority = v[:priority]
24
+ best_v = v
25
+ best_k = k
19
26
  end
20
27
  end
21
- return Response.new(sub_v(random_quote(@data.default["dontunderstand"])),["none"])
28
+ unless best_v.nil?
29
+ return Response.new(sub_v(random_quote(@data.responses[best_v[:resp]], /^#{best_k}/i.match(sentence).captures)),best_v[:emotions])
30
+ else
31
+ return Response.new(sub_v(random_quote(@data.default["dontunderstand"])),["none"])
32
+ end
22
33
  end
23
34
 
24
35
  #substitute variables
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: john-doe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pawel Mikolajewski
@@ -49,6 +49,7 @@ files:
49
49
  - Rakefile
50
50
  - VERSION
51
51
  - default.yml
52
+ - john-doe-0.1.0.gem
52
53
  - john-doe.gemspec
53
54
  - lib/john-doe.rb
54
55
  - lib/johndoe/aiml.rb