RecastAI 1.1.1 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8ad1ab3c3644a475ee1ef6cb9d2fc1ff9cc2576
4
- data.tar.gz: b8aa64148bc4fa52e834baa5f7e0a1519f198459
3
+ metadata.gz: cb697ada3b68765c4aaa58a74aecb84b4abd6ce1
4
+ data.tar.gz: aea0d30db62c6f16036f5bfb05d4192fabb79586
5
5
  SHA512:
6
- metadata.gz: 8fbb4fba5c6df33976ba39903ec228e33c152e333879ef17a9b72e646d4d85bfaf543b3de1b4842c01fd03390e15cff0734a5eb565eeef676b9d6061ff67ae1a
7
- data.tar.gz: 86ef258e86abcebf37bc945d3cc3cf58a634416e3eab53e12bc68ce1b5919b6f1eaa9e706a51337ed35a37e94f8f4e941142509e0664a904f8b5430869ebece3
6
+ metadata.gz: 4c8345542618e865f9fe864661f68ffc1e0b5ba482cc7bc367ae50c2d055fc1c2c85dcf2ed04de031c46574d0de1b6f5adee8c489797a5a991183c91db4a6a0a
7
+ data.tar.gz: 39b7610d272e106875fa4feb59b25db4db1e802d461e2adb8e3a871ba0fe5d55744220fe798caf22fb01bcbdc1f335a1bed5318bc79fdaeae6b62581a89088b3
@@ -1,7 +1,7 @@
1
1
  Metrics/LineLength:
2
- Max: 999
2
+ Max: 9999
3
3
  Metrics/MethodLength:
4
- Max: 999
4
+ Max: 9999
5
5
  Style/Documentation:
6
6
  Enabled: false
7
7
  Style/SpaceBeforeBlockBraces:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- RecastAI (1.1.0)
4
+ RecastAI (2.0.0)
5
5
  httmultiparty (~> 0.3)
6
6
  httparty (~> 0.13)
7
7
 
@@ -61,4 +61,4 @@ DEPENDENCIES
61
61
  webmock (~> 1.24)
62
62
 
63
63
  BUNDLED WITH
64
- 1.11.2
64
+ 1.12.5
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
- responseFromText = client.text_request(YOUR_TEXT)
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::Sentence represents a sentence of the response.
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[object]: all the matched intents |
193
- | sentences() | | Array[Sentence]: all the detected sentences |
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
- ```ruby
225
- response = client.text_request(YOUR_TEXT)
219
+ ## RecastAI::Intent
226
220
 
227
- sentence = response.sentence
221
+ Each of the following methods corresponds to an Intent attribute
228
222
 
229
- locations = sentence.all('location')
230
- ```
231
-
232
- ### Getters
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 a Response attribute
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 unparsed json value of the entity |
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 use, copy, modify, merge, publish, distribute, sublicense, and/or sell
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
 
@@ -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/sentence'
13
+ require 'recastai/intent'
12
14
  require 'recastai/entity'
@@ -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(Utils::API_ENDPOINT,
29
- body: body,
30
- headers: { 'Authorization' => "Token #{token}" }
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(Utils::API_ENDPOINT,
56
- body: body,
57
- headers: { 'Authorization' => "Token #{token}" }
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)
@@ -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 }
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RecastAI
2
4
  class RecastError < Exception
3
5
  end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ module RecastAI
4
+ class Intent
5
+ attr_reader :slug
6
+ attr_reader :confidence
7
+
8
+ def initialize(intent)
9
+ @slug = intent['slug']
10
+ @confidence = intent['confidence']
11
+ end
12
+ end
13
+ end
@@ -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 :sentences
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
- @sentences = response['sentences'].map{ |s| Sentence.new(s) }
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
- @sentences.each do |sentence|
56
- sentence.entities.each do |entity|
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
- entities
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
- # Returns all entities
86
+ # Return whether or not the act is a command
85
87
  #
86
- # * *Returns* :
87
- # - An array of instances of Entity or an empty array
88
- def entities
89
- entities = []
88
+ # + *Args* :
89
+ # + *Returns* :
90
+ # - True or False
91
+ def command?
92
+ @act == Utils::ACT_COMMAND
93
+ end
90
94
 
91
- @sentences.each do |sentence|
92
- sentence.entities.each do |entity|
93
- entities << entity
94
- end
95
- end
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
- entities
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
@@ -1,13 +1,36 @@
1
+ # encoding: utf-8
2
+
1
3
  module RecastAI
2
4
  class Utils
3
5
  # Versioning
4
- MAJOR = '1'.freeze
5
- MINOR = '1'.freeze
6
- MICRO = '1'.freeze
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/v1/request'.freeze
11
- WS_ENDPOINT = 'wss://api.recast.ai/v1/request'.freeze
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
@@ -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 = %q(Recast.AI official SDK for Ruby)
14
- spec.description = %q(Recast.AI official SDK for Ruby. Allows you to make requests to your bots.)
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: 1.1.1
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-09-07 00:00:00.000000000 Z
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
@@ -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