RecastAI 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/Gemfile.lock +2 -2
- data/README.md +55 -71
- data/lib/recastai.rb +3 -1
- data/lib/recastai/client.rb +12 -8
- data/lib/recastai/entity.rb +4 -0
- data/lib/recastai/errors.rb +2 -0
- data/lib/recastai/intent.rb +13 -0
- data/lib/recastai/response.rb +160 -35
- data/lib/recastai/utils.rb +28 -5
- data/recastai.gemspec +2 -2
- metadata +3 -3
- data/lib/recastai/sentence.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb697ada3b68765c4aaa58a74aecb84b4abd6ce1
|
4
|
+
data.tar.gz: aea0d30db62c6f16036f5bfb05d4192fabb79586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c8345542618e865f9fe864661f68ffc1e0b5ba482cc7bc367ae50c2d055fc1c2c85dcf2ed04de031c46574d0de1b6f5adee8c489797a5a991183c91db4a6a0a
|
7
|
+
data.tar.gz: 39b7610d272e106875fa4feb59b25db4db1e802d461e2adb8e3a871ba0fe5d55744220fe798caf22fb01bcbdc1f335a1bed5318bc79fdaeae6b62581a89088b3
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -31,12 +31,8 @@ require 'recastai'
|
|
31
31
|
client = RecastAI::Client.new(YOUR_TOKEN, YOUR_LANGUAGE)
|
32
32
|
|
33
33
|
# text request
|
34
|
-
|
35
|
-
|
36
|
-
# file request
|
37
|
-
responseFromFile = client.file_request(File.new(File.join(File.dirname(__FILE__), YOUR_FILE)))
|
38
|
-
|
39
|
-
if responseFromText.intent == YOUR_EXPECTED_INTENT
|
34
|
+
response = client.text_request(YOUR_TEXT)
|
35
|
+
if response.intent.slug == YOUR_EXPECTED_INTENT
|
40
36
|
# Do your code...
|
41
37
|
end
|
42
38
|
```
|
@@ -49,11 +45,11 @@ This gem contains 5 main classes, as follows:
|
|
49
45
|
|
50
46
|
* RecastAI::Client is the client allowing you to make requests.
|
51
47
|
* RecastAI::Response contains the response from [Recast.AI](https://recast.ai).
|
52
|
-
* RecastAI::
|
48
|
+
* RecastAI::Intent represents an intent of the response.
|
53
49
|
* RecastAI::Entity represents an entity found by Recast.AI in your user's input.
|
54
50
|
* RecastAI::RecastError is the error thrown by the gem.
|
55
51
|
|
56
|
-
Don't hesitate to dive into the code, it's commented
|
52
|
+
Don't hesitate to dive into the code, it's commented :)
|
57
53
|
|
58
54
|
## RecastAI::Client
|
59
55
|
|
@@ -112,7 +108,7 @@ __file format: .wav__
|
|
112
108
|
```ruby
|
113
109
|
response = client.file_request(File.new(File.join(File.dirname(__FILE__),YOUR_FILE)))
|
114
110
|
|
115
|
-
if response.intent == YOUR_EXPECTED_INTENT
|
111
|
+
if response.intent.slug == YOUR_EXPECTED_INTENT
|
116
112
|
# Do your code...
|
117
113
|
end
|
118
114
|
```
|
@@ -140,23 +136,11 @@ The Response is generated after a call to either file_request or text_request.
|
|
140
136
|
```ruby
|
141
137
|
response = client.text_request(YOUR_TEXT)
|
142
138
|
|
143
|
-
if response.intent == YOUR_EXPECTED_INTENT
|
139
|
+
if response.intent.slug == YOUR_EXPECTED_INTENT
|
144
140
|
# Do your code...
|
145
141
|
end
|
146
142
|
```
|
147
143
|
|
148
|
-
### Get the first sentence
|
149
|
-
|
150
|
-
| Method | Params | Return |
|
151
|
-
| --------------- |:------:| :------------------|
|
152
|
-
| sentence() | | the first sentence |
|
153
|
-
|
154
|
-
```ruby
|
155
|
-
response = client.text_request(YOUR_TEXT)
|
156
|
-
|
157
|
-
first_sentence = response.sentence
|
158
|
-
```
|
159
|
-
|
160
144
|
### Get the first entity matching name
|
161
145
|
|
162
146
|
| Method | Params | Return |
|
@@ -181,6 +165,38 @@ response = client.text_request(YOUR_TEXT)
|
|
181
165
|
locations = response.all('location')
|
182
166
|
```
|
183
167
|
|
168
|
+
|
169
|
+
|
170
|
+
### Act helpers
|
171
|
+
|
172
|
+
| Method | Params | Return |
|
173
|
+
| ------------- |:------:| :----------------------------------------------------- |
|
174
|
+
| assert? | | Bool: whether or not the sentence is an assertion |
|
175
|
+
| command? | | Bool: whether or not the sentence is a command |
|
176
|
+
| wh\_query? | | Bool: whether or not the sentence is a question |
|
177
|
+
| yn\_query? | | Bool: whether or not the sentence is a query |
|
178
|
+
|
179
|
+
### Type helpers
|
180
|
+
|
181
|
+
| Method | Params | Return |
|
182
|
+
| ------------- |:------:| :----------------------------------------------------- |
|
183
|
+
| abbreviation? | | Bool: is the answer of the sentence an abbreviation? |
|
184
|
+
| entity? | | Bool: is the answer of the sentence an entity? |
|
185
|
+
| description? | | Bool: is the answer of the sentence an description? |
|
186
|
+
| human? | | Bool: is the answer of the sentence an human? |
|
187
|
+
| location? | | Bool: is the answer of the sentence a location? |
|
188
|
+
| number? | | Bool: is the answer of the sentence an number? |
|
189
|
+
|
190
|
+
### Sentiment helpers
|
191
|
+
|
192
|
+
| Method | Params | Return |
|
193
|
+
| ------------- |:------:| :----------------------------------------------------- |
|
194
|
+
| vpositive? | | Bool: is the sentence very positive? |
|
195
|
+
| positive? | | Bool: is the sentence positive? |
|
196
|
+
| neutral? | | Bool: is the sentence neutral? |
|
197
|
+
| negative? | | Bool: is the sentence negative? |
|
198
|
+
| vnegative? | | Bool: is the sentence very negative? |
|
199
|
+
|
184
200
|
### Getters
|
185
201
|
|
186
202
|
Each of the following methods corresponds to a Response attribute
|
@@ -188,68 +204,36 @@ Each of the following methods corresponds to a Response attribute
|
|
188
204
|
| Method | Params | Return |
|
189
205
|
| ------------- |:------:| :---------------------------------------------------|
|
190
206
|
| raw() | | String: the raw unparsed json response |
|
207
|
+
| uuid() | | String: the universal unique id of the request |
|
191
208
|
| source() | | String: the user input |
|
192
|
-
| intents() | | Array[
|
193
|
-
|
|
209
|
+
| intents() | | Array[Intent]: all the matched intents |
|
210
|
+
| act() | | String: the act of the sentence |
|
211
|
+
| type() | | String: the type of the sentence |
|
212
|
+
| sentiment() | | String: the sentiment of the sentence |
|
213
|
+
| entities() | | Array[Entity]: all the detected entities |
|
214
|
+
| language() | | String: the language of the sentence |
|
194
215
|
| version() | | String: the version of the json |
|
195
216
|
| timestamp() | | String: the timestamp at the end of the processing |
|
196
217
|
| status() | | String: the status of the response |
|
197
|
-
| type() | | String: the type of the response |
|
198
|
-
|
199
|
-
|
200
|
-
## RecastAI::Sentence
|
201
|
-
|
202
|
-
The Sentence is generated by the Recast.AI Response initializer
|
203
|
-
|
204
|
-
### Get the first entity matching name
|
205
|
-
|
206
|
-
| Method | Params | Return |
|
207
|
-
| ---------- |:-------------:| :------------------------|
|
208
|
-
| get(name) | name: String | the first Entity matched |
|
209
|
-
|
210
|
-
```ruby
|
211
|
-
response = client.text_request(YOUR_TEXT)
|
212
|
-
|
213
|
-
sentence = response.sentence
|
214
|
-
|
215
|
-
location = sentence.get('location')
|
216
|
-
```
|
217
|
-
|
218
|
-
### Get all entities matching name
|
219
|
-
|
220
|
-
| Method | Params | Return |
|
221
|
-
| ---------- |:-------------:| :------------------------|
|
222
|
-
| all(name) | name: String | all the Entities matched |
|
223
218
|
|
224
|
-
|
225
|
-
response = client.text_request(YOUR_TEXT)
|
219
|
+
## RecastAI::Intent
|
226
220
|
|
227
|
-
|
221
|
+
Each of the following methods corresponds to an Intent attribute
|
228
222
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
Each of the following methods corresponds to a Response attribute
|
235
|
-
|
236
|
-
| Method | Params | Return |
|
237
|
-
| ----------- |:------:| :----------------------------------------------------|
|
238
|
-
| source | | String: the source of the sentence |
|
239
|
-
| type | | String: the type of the sentence |
|
240
|
-
| action | | String: The action of the sentence |
|
241
|
-
| agent | | String: the agent of the sentence |
|
242
|
-
| polarity | | String: the polarity of the sentence |
|
243
|
-
| entities | | Array[Entity]: the entities detected in the sentence |
|
223
|
+
| Attributes | Description |
|
224
|
+
| ----------- |:--------------------------------------------------------------|
|
225
|
+
| slug | String: the slug of the intent |
|
226
|
+
| confidence | Float: the unparsed json value of the intent |
|
244
227
|
|
245
228
|
## RecastAI::Entity
|
246
229
|
|
247
|
-
Each of the following methods corresponds to
|
230
|
+
Each of the following methods corresponds to an Entity attribute
|
248
231
|
|
249
232
|
| Attributes | Description |
|
250
233
|
| ----------- |:--------------------------------------------------------------|
|
251
234
|
| name | String: the name of the entity |
|
252
|
-
| raw | String: the
|
235
|
+
| raw | String: the raw value extracted from the sentence |
|
236
|
+
| confidence | Float: the detection score between 0 and 1 excluded |
|
253
237
|
|
254
238
|
In addition to those methods, more attributes are generated depending of the nature of the entity.
|
255
239
|
The full list can be found there: [man.recast.ai](https://man.recast.ai/#list-of-entities)
|
@@ -288,7 +272,7 @@ Copyright (c) [2016] [Recast.AI](https://recast.ai)
|
|
288
272
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
289
273
|
of this software and associated documentation files (the "Software"), to deal
|
290
274
|
in the Software without restriction, including without limitation the rights
|
291
|
-
to
|
275
|
+
to tsuse, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
292
276
|
copies of the Software, and to permit persons to whom the Software is
|
293
277
|
furnished to do so, subject to the following conditions:
|
294
278
|
|
data/lib/recastai.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
4
|
|
3
5
|
require 'httparty'
|
@@ -8,5 +10,5 @@ require 'recastai/utils'
|
|
8
10
|
require 'recastai/errors'
|
9
11
|
require 'recastai/client'
|
10
12
|
require 'recastai/response'
|
11
|
-
require 'recastai/
|
13
|
+
require 'recastai/intent'
|
12
14
|
require 'recastai/entity'
|
data/lib/recastai/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module RecastAI
|
2
4
|
class Client
|
3
5
|
attr_accessor :token
|
@@ -25,10 +27,11 @@ module RecastAI
|
|
25
27
|
|
26
28
|
body = { 'text' => text }
|
27
29
|
body['language'] = language unless language.nil?
|
28
|
-
response = HTTParty.post(
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
response = HTTParty.post(
|
31
|
+
Utils::API_ENDPOINT,
|
32
|
+
body: body,
|
33
|
+
headers: { 'Authorization' => "Token #{token}" }
|
34
|
+
)
|
32
35
|
raise(RecastError.new(response.message)) if response.code != 200
|
33
36
|
|
34
37
|
Response.new(response.body)
|
@@ -52,10 +55,11 @@ module RecastAI
|
|
52
55
|
|
53
56
|
body = { 'voice' => File.new(file) }
|
54
57
|
body['language'] = language unless language.nil?
|
55
|
-
response = HTTMultiParty.post(
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
response = HTTMultiParty.post(
|
59
|
+
Utils::API_ENDPOINT,
|
60
|
+
body: body,
|
61
|
+
headers: { 'Authorization' => "Token #{token}" }
|
62
|
+
)
|
59
63
|
raise(RecastError.new(response.message)) if response.code != 200
|
60
64
|
|
61
65
|
Response.new(response.body)
|
data/lib/recastai/entity.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module RecastAI
|
2
4
|
class Entity
|
3
5
|
attr_reader :name
|
@@ -5,6 +7,8 @@ module RecastAI
|
|
5
7
|
def initialize(name, data)
|
6
8
|
@name = name
|
7
9
|
|
10
|
+
# For each pair key, value, set a instance variable
|
11
|
+
# and an attr_reader named k and returning v
|
8
12
|
data.each_pair do |k, v|
|
9
13
|
self.instance_variable_set("@#{k}", v)
|
10
14
|
self.define_singleton_method(k.to_sym){ v }
|
data/lib/recastai/errors.rb
CHANGED
data/lib/recastai/response.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module RecastAI
|
2
4
|
class Response
|
3
5
|
attr_reader :raw
|
6
|
+
attr_reader :uuid
|
4
7
|
attr_reader :source
|
5
8
|
attr_reader :intents
|
6
|
-
attr_reader :
|
9
|
+
attr_reader :act
|
10
|
+
attr_reader :type
|
11
|
+
attr_reader :sentiment
|
12
|
+
attr_reader :entities
|
7
13
|
attr_reader :language
|
8
14
|
attr_reader :version
|
9
15
|
attr_reader :timestamp
|
@@ -15,9 +21,13 @@ module RecastAI
|
|
15
21
|
response = JSON.parse(response)
|
16
22
|
response = response['results']
|
17
23
|
|
24
|
+
@uuid = response['uuid']
|
18
25
|
@source = response['source']
|
19
|
-
@intents = response['intents']
|
20
|
-
@
|
26
|
+
@intents = response['intents'].map{ |i| Intent.new(i) }
|
27
|
+
@act = response['act']
|
28
|
+
@type = response['type']
|
29
|
+
@sentiment = response['sentiment']
|
30
|
+
@entities = response['entities'].flat_map{ |n, e| e.map{ |ee| Entity.new(n, ee) } }
|
21
31
|
@language = response['language']
|
22
32
|
@version = response['version']
|
23
33
|
@timestamp = response['timestamp']
|
@@ -34,16 +44,6 @@ module RecastAI
|
|
34
44
|
@intents.any? ? @intents.first : nil
|
35
45
|
end
|
36
46
|
|
37
|
-
##
|
38
|
-
# Returns the first sentence provided there is one
|
39
|
-
#
|
40
|
-
# * *Args* :
|
41
|
-
# * *Returns* :
|
42
|
-
# - A Sentence or nil
|
43
|
-
def sentence
|
44
|
-
@sentences.any? ? @sentences.first : nil
|
45
|
-
end
|
46
|
-
|
47
47
|
##
|
48
48
|
# Returns the first entity whose name matches the parameter
|
49
49
|
#
|
@@ -52,10 +52,8 @@ module RecastAI
|
|
52
52
|
# * *Returns* :
|
53
53
|
# - An instance of Entity or nil
|
54
54
|
def get(name)
|
55
|
-
@
|
56
|
-
|
57
|
-
return entity if entity.name.casecmp(name.to_s) == 0
|
58
|
-
end
|
55
|
+
@entities.each do |entity|
|
56
|
+
return entity if entity.name.casecmp(name.to_s) == 0
|
59
57
|
end
|
60
58
|
|
61
59
|
nil
|
@@ -69,32 +67,159 @@ module RecastAI
|
|
69
67
|
# * *Returns* :
|
70
68
|
# - An array of instances of Entity or an empty array
|
71
69
|
def all(name)
|
72
|
-
entities
|
73
|
-
|
74
|
-
@sentences.each do |sentence|
|
75
|
-
sentence.entities.each do |entity|
|
76
|
-
entities << entity if entity.name.casecmp(name.to_s) == 0
|
77
|
-
end
|
70
|
+
@entities.select do |entity|
|
71
|
+
entity.name.casecmp(name.to_s) == 0
|
78
72
|
end
|
73
|
+
end
|
79
74
|
|
80
|
-
|
75
|
+
##
|
76
|
+
# Return whether or not the act is an assertion
|
77
|
+
#
|
78
|
+
# + *Args* :
|
79
|
+
# + *Returns* :
|
80
|
+
# - True or False
|
81
|
+
def assert?
|
82
|
+
@act == Utils::ACT_ASSERT
|
81
83
|
end
|
82
84
|
|
83
85
|
##
|
84
|
-
#
|
86
|
+
# Return whether or not the act is a command
|
85
87
|
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
|
89
|
-
|
88
|
+
# + *Args* :
|
89
|
+
# + *Returns* :
|
90
|
+
# - True or False
|
91
|
+
def command?
|
92
|
+
@act == Utils::ACT_COMMAND
|
93
|
+
end
|
90
94
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
95
|
+
##
|
96
|
+
# Return whether or not the act is a wh-query
|
97
|
+
#
|
98
|
+
# + *Args* :
|
99
|
+
# + *Returns* :
|
100
|
+
# - True or False
|
101
|
+
def wh_query?
|
102
|
+
@act == Utils::ACT_WH_QUERY
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# Return whether or not the act is a yn-query
|
107
|
+
#
|
108
|
+
# + *Args* :
|
109
|
+
# + *Returns* :
|
110
|
+
# - True or False
|
111
|
+
def yn_query?
|
112
|
+
@act == Utils::ACT_YN_QUERY
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Return whether or not the type is an abbreviation
|
117
|
+
#
|
118
|
+
# + *Args* :
|
119
|
+
# + *Returns* :
|
120
|
+
# - True or False
|
121
|
+
def abbreviation?
|
122
|
+
!@type.index(Utils::TYPE_ABBREVIATION).nil?
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Return whether or not the type is an entity
|
127
|
+
#
|
128
|
+
# + *Args* :
|
129
|
+
# + *Returns* :
|
130
|
+
# - True or False
|
131
|
+
def entity?
|
132
|
+
!@type.index(Utils::TYPE_ENTITY).nil?
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Return whether or not the type is a description
|
137
|
+
#
|
138
|
+
# + *Args* :
|
139
|
+
# + *Returns* :
|
140
|
+
# - True or False
|
141
|
+
def description?
|
142
|
+
!@type.index(Utils::TYPE_DESCRIPTION).nil?
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# Return whether or not the type is a human
|
147
|
+
#
|
148
|
+
# + *Args* :
|
149
|
+
# + *Returns* :
|
150
|
+
# - True or False
|
151
|
+
def human?
|
152
|
+
!@type.index(Utils::TYPE_HUMAN).nil?
|
153
|
+
end
|
154
|
+
|
155
|
+
##
|
156
|
+
# Return whether or not the type is a location
|
157
|
+
#
|
158
|
+
# + *Args* :
|
159
|
+
# + *Returns* :
|
160
|
+
# - True or False
|
161
|
+
def location?
|
162
|
+
!@type.index(Utils::TYPE_LOCATION).nil?
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Return whether or not the type is a number
|
167
|
+
#
|
168
|
+
# + *Args* :
|
169
|
+
# + *Returns* :
|
170
|
+
# - True or False
|
171
|
+
def number?
|
172
|
+
!@type.index(Utils::TYPE_NUMBER).nil?
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Return whether or not the sentiment is very positive
|
177
|
+
#
|
178
|
+
# + *Args* :
|
179
|
+
# + *Returns* :
|
180
|
+
# - True or False
|
181
|
+
def vpositive?
|
182
|
+
@sentiment == Utils::SENTIMENT_VPOSITIVE
|
183
|
+
end
|
184
|
+
|
185
|
+
##
|
186
|
+
# Return whether or not the sentiment is positive
|
187
|
+
#
|
188
|
+
# + *Args* :
|
189
|
+
# + *Returns* :
|
190
|
+
# - True or False
|
191
|
+
def positive?
|
192
|
+
@sentiment == Utils::SENTIMENT_POSITIVE
|
193
|
+
end
|
194
|
+
|
195
|
+
##
|
196
|
+
# Return whether or not the sentiment is neutral
|
197
|
+
#
|
198
|
+
# + *Args* :
|
199
|
+
# + *Returns* :
|
200
|
+
# - True or False
|
201
|
+
def neutral?
|
202
|
+
@sentiment == Utils::SENTIMENT_NEUTRAL
|
203
|
+
end
|
204
|
+
|
205
|
+
##
|
206
|
+
# Return whether or not the sentiment is negative
|
207
|
+
#
|
208
|
+
# + *Args* :
|
209
|
+
# + *Returns* :
|
210
|
+
# - True or False
|
211
|
+
def negative?
|
212
|
+
@sentiment == Utils::SENTIMENT_NEGATIVE
|
213
|
+
end
|
96
214
|
|
97
|
-
|
215
|
+
##
|
216
|
+
# Return whether or not the sentiment is very negative
|
217
|
+
#
|
218
|
+
# + *Args* :
|
219
|
+
# + *Returns* :
|
220
|
+
# - True or False
|
221
|
+
def vnegative?
|
222
|
+
@sentiment == Utils::SENTIMENT_VNEGATIVE
|
98
223
|
end
|
99
224
|
end
|
100
225
|
end
|
data/lib/recastai/utils.rb
CHANGED
@@ -1,13 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module RecastAI
|
2
4
|
class Utils
|
3
5
|
# Versioning
|
4
|
-
MAJOR
|
5
|
-
MINOR
|
6
|
-
MICRO
|
6
|
+
MAJOR = '2'.freeze
|
7
|
+
MINOR = '0'.freeze
|
8
|
+
MICRO = '0'.freeze
|
7
9
|
VERSION = "#{MAJOR}.#{MINOR}.#{MICRO}".freeze
|
8
10
|
|
9
11
|
# Endpoints
|
10
|
-
API_ENDPOINT = 'https://api.recast.ai/
|
11
|
-
WS_ENDPOINT
|
12
|
+
API_ENDPOINT = 'https://api.recast.ai/v2/request'.freeze
|
13
|
+
WS_ENDPOINT = 'wss://api.recast.ai/v2/request'.freeze
|
14
|
+
|
15
|
+
# Act constants
|
16
|
+
ACT_ASSERT = 'assert'.freeze
|
17
|
+
ACT_COMMAND = 'command'.freeze
|
18
|
+
ACT_WH_QUERY = 'wh-query'.freeze
|
19
|
+
ACT_YN_QUERY = 'yn-query'.freeze
|
20
|
+
|
21
|
+
# Type constants
|
22
|
+
TYPE_ABBREVIATION = 'abbr:'.freeze
|
23
|
+
TYPE_ENTITY = 'enty:'.freeze
|
24
|
+
TYPE_DESCRIPTION = 'desc:'.freeze
|
25
|
+
TYPE_HUMAN = 'hum:'.freeze
|
26
|
+
TYPE_LOCATION = 'loc:'.freeze
|
27
|
+
TYPE_NUMBER = 'num:'.freeze
|
28
|
+
|
29
|
+
# Sentiment constants
|
30
|
+
SENTIMENT_VPOSITIVE = 'vpositive'.freeze
|
31
|
+
SENTIMENT_POSITIVE = 'positive'.freeze
|
32
|
+
SENTIMENT_NEUTRAL = 'neutral'.freeze
|
33
|
+
SENTIMENT_NEGATIVE = 'negative'.freeze
|
34
|
+
SENTIMENT_VNEGATIVE = 'vnegative'.freeze
|
12
35
|
end
|
13
36
|
end
|
data/recastai.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.name = 'RecastAI'
|
11
11
|
spec.version = RecastAI::Utils::VERSION
|
12
12
|
spec.date = Date.today
|
13
|
-
spec.summary =
|
14
|
-
spec.description =
|
13
|
+
spec.summary = 'Recast.AI official SDK for Ruby'
|
14
|
+
spec.description = 'Recast.AI official SDK for Ruby. Allows you to make requests to your bots.'
|
15
15
|
spec.homepage = 'https://github.com/RecastAI/SDK-ruby'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
spec.authors = ['Paul Renvoisé']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RecastAI
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Renvoisé
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -116,8 +116,8 @@ files:
|
|
116
116
|
- lib/recastai/client.rb
|
117
117
|
- lib/recastai/entity.rb
|
118
118
|
- lib/recastai/errors.rb
|
119
|
+
- lib/recastai/intent.rb
|
119
120
|
- lib/recastai/response.rb
|
120
|
-
- lib/recastai/sentence.rb
|
121
121
|
- lib/recastai/utils.rb
|
122
122
|
- misc/.gitkeep
|
123
123
|
- misc/logo-inline.png
|
data/lib/recastai/sentence.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
module RecastAI
|
2
|
-
class Sentence
|
3
|
-
attr_reader :source
|
4
|
-
attr_reader :type
|
5
|
-
attr_reader :action
|
6
|
-
attr_reader :agent
|
7
|
-
attr_reader :polarity
|
8
|
-
attr_reader :entities
|
9
|
-
|
10
|
-
def initialize(sentence)
|
11
|
-
@source = sentence['source']
|
12
|
-
@type = sentence['type']
|
13
|
-
@action = sentence['action']
|
14
|
-
@agent = sentence['agent']
|
15
|
-
@polarity = sentence['polarity']
|
16
|
-
@entities = sentence['entities'].flat_map{ |n, e| e.map{ |ee| Entity.new(n, ee) } }
|
17
|
-
end
|
18
|
-
|
19
|
-
##
|
20
|
-
# Returns the first entity whose name matches the parameter
|
21
|
-
#
|
22
|
-
# * *Args* :
|
23
|
-
# - +name+ - String, the entity's name
|
24
|
-
# * *Returns* :
|
25
|
-
# - An instance of Entity or nil
|
26
|
-
def get(name)
|
27
|
-
@entities.each do |entity|
|
28
|
-
return entity if entity.name.casecmp(name.to_s) == 0
|
29
|
-
end
|
30
|
-
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
|
34
|
-
##
|
35
|
-
# Returns all entities whose names matches the parameter
|
36
|
-
#
|
37
|
-
# * *Args* :
|
38
|
-
# - +name+ - String, the entities' names
|
39
|
-
# * *Returns* :
|
40
|
-
# - An array of instances of Entity or an empty array
|
41
|
-
def all(name)
|
42
|
-
entities = []
|
43
|
-
|
44
|
-
@entities.each do |entity|
|
45
|
-
entities << entity if entity.name.casecmp(name.to_s) == 0
|
46
|
-
end
|
47
|
-
|
48
|
-
entities
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|