wit_bot 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/lib/wit_bot/configuration.rb +9 -7
- data/lib/wit_bot/models/context.rb +8 -0
- data/lib/wit_bot/models/context_entities.rb +7 -0
- data/lib/wit_bot/models/message.rb +13 -1
- data/lib/wit_bot/models/message_thread.rb +17 -2
- data/lib/wit_bot/models/outcome.rb +10 -10
- data/lib/wit_bot/models/wit/entity.rb +4 -0
- data/lib/wit_bot/models/wit/entity/entity_model.rb +33 -1
- data/lib/wit_bot/models/wit/intent.rb +4 -0
- data/lib/wit_bot/version.rb +1 -1
- data/wit_bot.gemspec +5 -3
- metadata +38 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2822b54c41afb8236a1ae7c1e14480a18d589652
|
4
|
+
data.tar.gz: 1faa556ee9be09bfaec737127f8d91e5a648e811
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd98b6c765b838f0d0fb21db89bd96ba2ce61a1d2adca4272f2dd75947020b392915090dd79b14622298560325668ee23c1ffcccd73208b5e2aa8418a768ace9
|
7
|
+
data.tar.gz: 7c2f7f111dd129e6a7bbce791621fccad40678b0cca120a3e4252581eb54c852a66bd0789c93d5c1df81798d0f0fe9fed701c84e747ee1d3788413b2a9e86d4d
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.4
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module WitBot
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :token, :host, :minimum_confidence, :version
|
4
|
+
def initialize
|
5
|
+
@token = nil
|
6
|
+
@host = 'https://api.wit.ai'
|
7
|
+
@minimum_confidence = 0
|
8
|
+
@version = '20160313'
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
@@ -31,8 +31,16 @@ module WitBot
|
|
31
31
|
@location = h[:location]
|
32
32
|
self
|
33
33
|
end
|
34
|
+
|
34
35
|
def self.from_hash(json)
|
35
36
|
self.new.from_hash json
|
36
37
|
end
|
38
|
+
|
39
|
+
def ==(other)
|
40
|
+
self.state == other.state &&
|
41
|
+
self.reference_time == other.reference_time &&
|
42
|
+
self.entities == other.entities &&
|
43
|
+
self.location == other.location
|
44
|
+
end
|
37
45
|
end
|
38
46
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module WitBot
|
2
2
|
class ContextEntities
|
3
|
+
attr_reader :id
|
4
|
+
attr_accessor :values
|
5
|
+
|
3
6
|
def initialize
|
4
7
|
@hash = {}
|
5
8
|
end
|
@@ -23,5 +26,9 @@ module WitBot
|
|
23
26
|
def self.from_hash(json)
|
24
27
|
self.new.from_hash json
|
25
28
|
end
|
29
|
+
|
30
|
+
def ==(other)
|
31
|
+
self.id == other.id && self.values == other.values
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
@@ -36,6 +36,7 @@ module WitBot
|
|
36
36
|
self
|
37
37
|
end
|
38
38
|
def self.from_hash(thread, id, json)
|
39
|
+
json = json.with_indifferent_access
|
39
40
|
return Bot::Message.from_hash thread, id, json if json[:bot]
|
40
41
|
self.new(thread, json[:text], id: id).from_hash json
|
41
42
|
end
|
@@ -68,7 +69,7 @@ module WitBot
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def parse_outcomes(outcomes=@_outcomes)
|
71
|
-
outcomes.each_with_index.map { |outcome, i| Outcome.new self, outcome, i }
|
72
|
+
outcomes.each_with_index.map { |outcome, i| Outcome.new self, outcome, i } if outcomes
|
72
73
|
end
|
73
74
|
|
74
75
|
def parse_outcomes!(outcomes=@_outcomes)
|
@@ -78,5 +79,16 @@ module WitBot
|
|
78
79
|
def outcome
|
79
80
|
outcomes.first
|
80
81
|
end
|
82
|
+
|
83
|
+
def ==(other)
|
84
|
+
self.text == other.text &&
|
85
|
+
self._text == other._text &&
|
86
|
+
self.id == other.id &&
|
87
|
+
self.bot? == other.bot? &&
|
88
|
+
self.sent == other.sent &&
|
89
|
+
self._outcomes == other._outcomes &&
|
90
|
+
self.thread.equals_without_messages(other.thread) &&
|
91
|
+
self.outcomes == other.outcomes
|
92
|
+
end
|
81
93
|
end
|
82
94
|
end
|
@@ -18,7 +18,7 @@ module WitBot
|
|
18
18
|
def messages_list(user: true, bot: false)
|
19
19
|
bot_messages = bot ? @bot_messages.values : []
|
20
20
|
user_messages = user ? @messages.values : []
|
21
|
-
|
21
|
+
user_messages + bot_messages
|
22
22
|
end
|
23
23
|
|
24
24
|
def create_message(text, id=SecureRandom.uuid)
|
@@ -54,13 +54,28 @@ module WitBot
|
|
54
54
|
@messages = WitBot::Message.many_from_hash(self, m[:user])
|
55
55
|
@bot_messages = WitBot::Message.many_from_hash(self, m[:bot])
|
56
56
|
|
57
|
-
@context = Context.from_hash json[:context]
|
57
|
+
@context = Context.from_hash json[:context] if json[:context]
|
58
58
|
@metadata = json[:metadata]
|
59
59
|
self
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.from_hash(json)
|
63
|
+
json = json.with_indifferent_access
|
63
64
|
self.new(json[:id]).from_hash json
|
64
65
|
end
|
66
|
+
|
67
|
+
def ==(other)
|
68
|
+
self.id == other.id &&
|
69
|
+
self.context == other.context &&
|
70
|
+
self.bot_messages == other.bot_messages &&
|
71
|
+
self.messages == other.messages &&
|
72
|
+
self.metadata == other.metadata
|
73
|
+
end
|
74
|
+
|
75
|
+
def equals_without_messages(other)
|
76
|
+
self.id == other.id &&
|
77
|
+
self.context == other.context &&
|
78
|
+
self.metadata == other.metadata
|
79
|
+
end
|
65
80
|
end
|
66
81
|
end
|
@@ -10,16 +10,7 @@ module WitBot
|
|
10
10
|
@_text = @raw[:_text]
|
11
11
|
|
12
12
|
@intent = WitModel::Intent.find raw[:intent]
|
13
|
-
@entities =
|
14
|
-
role, all = entity_info
|
15
|
-
all = all.map { |data| WitModel::Entity.find(data[:entity], create: false).model role, data }
|
16
|
-
|
17
|
-
data = all.shift
|
18
|
-
data.others = all
|
19
|
-
|
20
|
-
entities[role] = data
|
21
|
-
entities
|
22
|
-
end.with_indifferent_access
|
13
|
+
@entities = EntityModelProxy.new raw[:entities]
|
23
14
|
|
24
15
|
raise LowConfidenceError self if i == 0 && low_confidence?
|
25
16
|
end
|
@@ -27,5 +18,14 @@ module WitBot
|
|
27
18
|
def low_confidence?
|
28
19
|
@confidence < WitBot.config.minimum_confidence
|
29
20
|
end
|
21
|
+
|
22
|
+
def ==(other)
|
23
|
+
self.message == other.message &&
|
24
|
+
self.raw == other.raw &&
|
25
|
+
self._text == other._text &&
|
26
|
+
self.confidence == other.confidence &&
|
27
|
+
self.intent == other.intent &&
|
28
|
+
self.entities == other.entities
|
29
|
+
end
|
30
30
|
end
|
31
31
|
end
|
@@ -1,6 +1,30 @@
|
|
1
1
|
module WitBot
|
2
|
+
class EntityModelProxy < HashWithIndifferentAccess
|
3
|
+
attr_reader :raw
|
4
|
+
|
5
|
+
def initialize(raw_entities)
|
6
|
+
@raw = raw_entities
|
7
|
+
|
8
|
+
super Hash[*raw_entities.map do |(role, all)|
|
9
|
+
all = all.map { |data| WitModel::Entity.find(data[:entity], create: false).model role, data }
|
10
|
+
|
11
|
+
data = all.first
|
12
|
+
|
13
|
+
data.all = all
|
14
|
+
|
15
|
+
create_getter role
|
16
|
+
|
17
|
+
[role, data]
|
18
|
+
end.flatten]
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def create_getter(var)
|
23
|
+
self.class.send(:define_method, var, -> { self[var] })
|
24
|
+
end
|
25
|
+
end
|
2
26
|
class EntityModel
|
3
|
-
attr_accessor :
|
27
|
+
attr_accessor :all
|
4
28
|
attr_reader :entity, :role, :raw, :value
|
5
29
|
|
6
30
|
def initialize(entity, role, raw)
|
@@ -18,6 +42,14 @@ module WitBot
|
|
18
42
|
@others = []
|
19
43
|
end
|
20
44
|
|
45
|
+
def others
|
46
|
+
all - [self]
|
47
|
+
end
|
48
|
+
|
49
|
+
def ==(other)
|
50
|
+
self.entity == other.entity && self.value == other.value
|
51
|
+
end
|
52
|
+
|
21
53
|
def to_s
|
22
54
|
value.to_s
|
23
55
|
end
|
data/lib/wit_bot/version.rb
CHANGED
data/wit_bot.gemspec
CHANGED
@@ -20,9 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.11"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
24
|
+
spec.add_development_dependency "simplecov", ">= 0"
|
23
25
|
|
24
|
-
spec.add_dependency "http", "
|
26
|
+
spec.add_dependency "http", ">= 1.0.2"
|
25
27
|
spec.add_dependency "activesupport", ">= 4"
|
26
|
-
spec.add_dependency "require_all", "
|
27
|
-
spec.add_dependency "awesome_print", "
|
28
|
+
spec.add_dependency "require_all", ">= 1.3.3"
|
29
|
+
spec.add_dependency "awesome_print", ">= 1.6.1"
|
28
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wit_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben (@penne12_)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,17 +39,45 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: http
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
46
74
|
- !ruby/object:Gem::Version
|
47
75
|
version: 1.0.2
|
48
76
|
type: :runtime
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- - "
|
80
|
+
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: 1.0.2
|
55
83
|
- !ruby/object:Gem::Dependency
|
@@ -70,28 +98,28 @@ dependencies:
|
|
70
98
|
name: require_all
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
|
-
- - "
|
101
|
+
- - ">="
|
74
102
|
- !ruby/object:Gem::Version
|
75
103
|
version: 1.3.3
|
76
104
|
type: :runtime
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
|
-
- - "
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: 1.3.3
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: awesome_print
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- - "
|
115
|
+
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
117
|
version: 1.6.1
|
90
118
|
type: :runtime
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- - "
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: 1.6.1
|
97
125
|
description: A better wit.ai client for Ruby. Written in Ruby. With an api for creating
|
@@ -104,6 +132,7 @@ extensions: []
|
|
104
132
|
extra_rdoc_files: []
|
105
133
|
files:
|
106
134
|
- ".gitignore"
|
135
|
+
- ".ruby-version"
|
107
136
|
- CODE_OF_CONDUCT.md
|
108
137
|
- Gemfile
|
109
138
|
- LICENSE.txt
|
@@ -171,10 +200,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
200
|
version: '0'
|
172
201
|
requirements: []
|
173
202
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.4.5
|
203
|
+
rubygems_version: 2.4.5.1
|
175
204
|
signing_key:
|
176
205
|
specification_version: 4
|
177
206
|
summary: A better wit.ai client for Ruby. Written in Ruby. With an api for creating
|
178
207
|
bots.
|
179
208
|
test_files: []
|
180
|
-
has_rdoc:
|