RecastAI 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8fc4edaf1b82d336f4b13e82dd68b45bacc60bd
4
- data.tar.gz: 031d2d8409dc6abd4679cfa69b9c92199205bead
3
+ metadata.gz: b8ad1ab3c3644a475ee1ef6cb9d2fc1ff9cc2576
4
+ data.tar.gz: b8aa64148bc4fa52e834baa5f7e0a1519f198459
5
5
  SHA512:
6
- metadata.gz: 97f198079573ac33474efdc4bdfd4d0c287d30eca3d1f861ce598811bc89ea3bd86793debcf7ef63271841c854505659a7f38932accd01ae94a512abec5b4086
7
- data.tar.gz: e26c419f1c4762c9fc446494ba7f9407ea1f769ce784bed6827c3ce2b534430e8312c29448c8132c2ca83d5636e62807ce9f843531336ec9c2bf15ce060ebb31
6
+ metadata.gz: 8fbb4fba5c6df33976ba39903ec228e33c152e333879ef17a9b72e646d4d85bfaf543b3de1b4842c01fd03390e15cff0734a5eb565eeef676b9d6061ff67ae1a
7
+ data.tar.gz: 86ef258e86abcebf37bc945d3cc3cf58a634416e3eab53e12bc68ce1b5919b6f1eaa9e706a51337ed35a37e94f8f4e941142509e0664a904f8b5430869ebece3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RecastAI - Ruby SDK
1
+ # Recast.AI - Ruby SDK
2
2
 
3
3
  [![Version](https://badge.fury.io/rb/RecastAI.svg)](https://badge.fury.io/rb/RecastAI)
4
4
 
@@ -19,63 +19,26 @@ This gem is a pure Ruby interface to the [Recast.AI](https://recast.ai) API. It
19
19
 
20
20
  ## Installation
21
21
 
22
- ### Via Gemfile
23
-
24
- From [rubygems.org](https://rubygems.org/):
25
-
26
- ```bash
27
- gem 'RecastAI'
28
- ```
29
-
30
- From [github.com](https://github.com/):
31
-
32
- ```bash
33
- gem 'RecastAI', github: 'RecastAI/SDK-ruby'
34
- ```
35
-
36
- ### Via Terminal
37
-
38
- From [rubygems.org](https://rubygems.org/):
39
-
40
22
  ```bash
41
23
  gem install 'RecastAI'
42
24
  ```
43
25
 
44
- From [github.com](https://github.com/):
45
-
46
- ```bash
47
- git clone https://github.com/RecastAI/SDK-ruby
48
- gem build recastai.gemspec
49
- gem install RecastAI-*.gem
50
- ```
51
-
52
-
53
26
  ## Usage
54
27
 
55
- ### Gem
56
-
57
28
  ```ruby
58
29
  require 'recastai'
59
30
 
60
31
  client = RecastAI::Client.new(YOUR_TOKEN, YOUR_LANGUAGE)
61
- response = client.text_request(YOUR_TEXT)
62
- #response = client.file_request(File.new(File.join(File.dirname(__FILE__), YOUR_FILE)))
63
32
 
64
- if response.intent == YOUR_EXPECTED_INTENT
65
- # Do your code...
66
- end
67
- ```
68
-
69
- ### CLI
33
+ # text request
34
+ responseFromText = client.text_request(YOUR_TEXT)
70
35
 
71
- ```bash
72
- ./bin/text YOUR_TOKEN YOUR_TEXT
73
- # => Recast.AI's response
74
- ```
36
+ # file request
37
+ responseFromFile = client.file_request(File.new(File.join(File.dirname(__FILE__), YOUR_FILE)))
75
38
 
76
- ```bash
77
- ./bin/file YOUR_TOKEN YOUR_VOICE_FILE
78
- # => Recast.AI's response
39
+ if responseFromText.intent == YOUR_EXPECTED_INTENT
40
+ # Do your code...
41
+ end
79
42
  ```
80
43
 
81
44
  ## Specs
@@ -92,139 +55,215 @@ This gem contains 5 main classes, as follows:
92
55
 
93
56
  Don't hesitate to dive into the code, it's commented ;)
94
57
 
95
- ### RecastAI::Client
58
+ ## RecastAI::Client
96
59
 
97
- The Recast.AI Client can be instanciated with a token (optional) and a language (optional) and provides the two following methods:
60
+ The Client can be instanciated with a token and a language (both optional)
98
61
 
99
- * text_request(text, options = {}) *Performs a text request*
100
- * file_request(file, options = {}) *Performs a voice file request*
62
+ ```ruby
63
+ client = RecastAI::Client.new(YOUR_TOKEN, YOUR_LANGUAGE)
64
+ ```
101
65
 
102
- On each call to `text_request` or `file_request` your can override either your token or your language by passing a hash of options.
66
+ __Your tokens__
103
67
 
104
- If no language is provided in the request, Recast.AI does the following:
68
+ [token]: https://github.com/RecastAI/SDK-NodeJs/blob/master/misc/recast-ai-tokens.png "Tokens"
105
69
 
106
- * text_request: the language of the text is detected and is used for processing if your bot has expressions for it, else your bot's primary language is used for processing.
107
- * voice_request: your bot's primary language is used for processing as we do not provide language detection for speech.
70
+ ![alt text][token]
108
71
 
109
- If a language is provided, Recast.AI does the following:
72
+ *Copy paste your request access token from your bot's settings*
110
73
 
111
- * text_request: the language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used.
112
- * voice_request: the language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used
74
+ __Your language__
113
75
 
114
- *Accepted options are :token, :language, to override the defaults provided at initialization*
76
+ ```ruby
77
+ client = RecastAI::Client.new(YOUR_TOKEN, 'en')
78
+ ```
79
+
80
+ *The language is a lowercase 639-1 isocode.*
81
+
82
+ ## Text Request
83
+
84
+ text_request(text, options = {})
85
+
86
+ If you pass a token or a language in the options parameter, it will override your default client language or token
115
87
 
116
88
  ```ruby
117
- require 'recastai'
89
+ response = client.text_request(YOUR_TEXT)
118
90
 
119
- client = RecastAI::Client.new(YOUR_TOKEN, YOUR LANGUAGE)
91
+ if response.intent == YOUR_EXPECTED_INTENT
92
+ # Do your code...
93
+ end
94
+ ```
120
95
 
121
- # Performs a text request on Recast.AI
96
+ ```ruby
97
+ # With optional parameters
122
98
  response = client.text_request(YOUR_TEXT, { token: YOUR_TOKEN, language: YOUR_LANGUAGE })
99
+ ```
100
+
101
+ __If a language is provided:__ the language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used.
102
+
103
+ __If no language is provided:__ the language of the text is detected and is used for processing if your bot has expressions for it, else your bot's primary language is used for processing.
104
+
105
+ ## File request
106
+
107
+ file_request(file, options = {})
108
+
109
+ If you pass a token or a language in the option parameter, it will override your default client language or token.
110
+
111
+ __file format: .wav__
112
+ ```ruby
113
+ response = client.file_request(File.new(File.join(File.dirname(__FILE__),YOUR_FILE)))
123
114
 
124
115
  if response.intent == YOUR_EXPECTED_INTENT
125
116
  # Do your code...
126
117
  end
118
+ ```
127
119
 
128
- # Performs a voice file request on Recast.AI
120
+ ```ruby
121
+ # with optional parameters
129
122
  response = client.file_request(File.new(File.join(File.dirname(__FILE__),YOUR_FILE)), { token: YOUR_TOKEN, language: YOUR_LANGUAGE })
123
+ ```
124
+
125
+ __If a language is provided:__ the language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used
126
+
127
+ __If no language is provided:__ your bot's primary language is used for processing as we do not provide language detection for speech.
128
+
129
+
130
+ ## RecastAI::Response
131
+
132
+ The Response is generated after a call to either file_request or text_request.
133
+
134
+ ### Get the first detected intent
135
+
136
+ | Method | Params | Return |
137
+ | ------------- |:------:| :-------------------------|
138
+ | intent() | | the first detected intent |
139
+
140
+ ```ruby
141
+ response = client.text_request(YOUR_TEXT)
130
142
 
131
143
  if response.intent == YOUR_EXPECTED_INTENT
132
144
  # Do your code...
133
145
  end
134
146
  ```
135
147
 
136
- ### RecastAI::Response
137
-
138
- The Recast.AI Response is generated after a call with the two previous methods and contains the following methods:
148
+ ### Get the first sentence
139
149
 
140
- * raw(\*) *Returns the raw unparsed response*
141
- * source(\*) *Returns the source sentence Recast.AI processed*
142
- * intents(\*) *Returns all the matched intents*
143
- * intent(\*) *Returns the first matched intent*
144
- * sentences(\*) *Returns all the detected sentences*
145
- * sentence(\*) *Returns the first detected sentence*
146
- * get(name) *Returns the first entity matching -name-*
147
- * all(name) *Returns all the entities matching -name-*
148
- * entities(\*) *Returns all the entities*
149
- * version(\*) *Returns the version of the JSON*
150
- * timestamp(\*) *Returns the timestamp at the end of the processing*
151
- * status(\*) *Returns the status of the response*
150
+ | Method | Params | Return |
151
+ | --------------- |:------:| :------------------|
152
+ | sentence() | | the first sentence |
152
153
 
153
154
  ```ruby
154
- response = client.text_request('Give me some recipes with potatoes. And cheese.')
155
+ response = client.text_request(YOUR_TEXT)
155
156
 
156
- # Get the first sentence, aka 'Give me some recipes with potatoes'
157
157
  first_sentence = response.sentence
158
+ ```
158
159
 
159
- # If the first intent matched 'recipe'...
160
- if response.intent == 'recipe'
161
- # ...get all the entities matching 'ingredient'
162
- ingredients = response.all('ingredient')
160
+ ### Get the first entity matching name
163
161
 
164
- puts "The request has been filled at #{response.timestamp}"
165
- end
162
+ | Method | Params | Return |
163
+ | ---------- |:-------------:| :------------------------|
164
+ | get(name) | name: String | the first Entity matched |
165
+
166
+ ```ruby
167
+ response = client.text_request(YOUR_TEXT)
168
+
169
+ location = response.get('location')
166
170
  ```
167
171
 
168
- ### RecastAI::Sentence
172
+ ### Get all entities matching name
173
+
174
+ | Method | Params | Return |
175
+ | ---------- |:-------------:| :------------------------|
176
+ | all(name) | name: String | all the Entities matched |
169
177
 
170
- The Recast.AI Sentence is generated by the Recast.AI Response initializer and provides the following methods:
178
+ ```ruby
179
+ response = client.text_request(YOUR_TEXT)
171
180
 
172
- * source(\*) *Returns the source of the sentence*
173
- * type(\*) *Returns the type of the sentence*
174
- * action(\*) *Returns the action of the sentence*
175
- * agent(\*) *Returns the agent of the sentence*
176
- * polarity(\*) *Returns the polarity (negation or not) of the sentence*
177
- * get(name) *Returns the first entity matching -name-*
178
- * all(name) *Returns all the entities matching -name-*
179
- * entities(\*) *Returns all the entities detected in the sentence*
181
+ locations = response.all('location')
182
+ ```
183
+
184
+ ### Getters
185
+
186
+ Each of the following methods corresponds to a Response attribute
187
+
188
+ | Method | Params | Return |
189
+ | ------------- |:------:| :---------------------------------------------------|
190
+ | raw() | | String: the raw unparsed json response |
191
+ | source() | | String: the user input |
192
+ | intents() | | Array[object]: all the matched intents |
193
+ | sentences() | | Array[Sentence]: all the detected sentences |
194
+ | version() | | String: the version of the json |
195
+ | timestamp() | | String: the timestamp at the end of the processing |
196
+ | 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 |
180
209
 
181
210
  ```ruby
182
- response = client.text_request('Tell me a joke.')
183
- # Get the first sentence
211
+ response = client.text_request(YOUR_TEXT)
212
+
184
213
  sentence = response.sentence
185
214
 
186
- if sentence.action == 'tell' && sentence.polarity == 'positive'
187
- # Tell a joke...
188
- end
215
+ location = sentence.get('location')
189
216
  ```
190
217
 
191
- ### RecastAI::Entity
218
+ ### Get all entities matching name
192
219
 
193
- The Recast.AI Entity is generated by the Recast.AI Sentence initializer and provides the following method:
220
+ | Method | Params | Return |
221
+ | ---------- |:-------------:| :------------------------|
222
+ | all(name) | name: String | all the Entities matched |
194
223
 
195
- * name(\*) *Returns the name of the entity*
196
- * raw(\*) *Returns the raw text on which the entity was detected*
224
+ ```ruby
225
+ response = client.text_request(YOUR_TEXT)
197
226
 
198
- In addition to this method, more attributes are generated depending of the nature of the entity, which can be one of the following:
227
+ sentence = response.sentence
199
228
 
200
- * hex(\*)
201
- * value(\*)
202
- * deg(\*)
203
- * formated(\*)
204
- * lng(\*)
205
- * lat(\*)
206
- * unit(\*)
207
- * code(\*)
208
- * person(\*)
209
- * number(\*)
210
- * gender(\*)
211
- * next(\*)
212
- * grain(\*)
213
- * order(\*)
229
+ locations = sentence.all('location')
230
+ ```
214
231
 
215
- ```ruby
216
- response = client.text_request('What can I cook with salmon ?')
232
+ ### Getters
217
233
 
218
- if response.intent == 'recipe'
219
- # Get the ingredient
220
- ingredient = response.get('ingredient')
234
+ Each of the following methods corresponds to a Response attribute
221
235
 
222
- puts "You asked me for a recipe with #{ingredient.value}"
223
- end
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 |
244
+
245
+ ## RecastAI::Entity
246
+
247
+ Each of the following methods corresponds to a Response attribute
248
+
249
+ | Attributes | Description |
250
+ | ----------- |:--------------------------------------------------------------|
251
+ | name | String: the name of the entity |
252
+ | raw | String: the unparsed json value of the entity |
253
+
254
+ In addition to those methods, more attributes are generated depending of the nature of the entity.
255
+ The full list can be found there: [man.recast.ai](https://man.recast.ai/#list-of-entities)
256
+
257
+ ```ruby
258
+ response = client.text_request(YOUR_TEXT)
259
+
260
+ location = response.get('location')
224
261
 
262
+ puts location.raw
263
+ puts location.name
225
264
  ```
226
265
 
227
- ### RecastAI::RecastError
266
+ ## RecastAI::RecastError
228
267
 
229
268
  The Recast.AI Error is thrown when receiving an non-200 response from Recast.AI.
230
269
 
@@ -10,5 +10,3 @@ require 'recastai/client'
10
10
  require 'recastai/response'
11
11
  require 'recastai/sentence'
12
12
  require 'recastai/entity'
13
-
14
- require 'awesome_print'
@@ -3,7 +3,7 @@ module RecastAI
3
3
  # Versioning
4
4
  MAJOR = '1'.freeze
5
5
  MINOR = '1'.freeze
6
- MICRO = '0'.freeze
6
+ MICRO = '1'.freeze
7
7
  VERSION = "#{MAJOR}.#{MINOR}.#{MICRO}".freeze
8
8
 
9
9
  # Endpoints
Binary file
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.0
4
+ version: 1.1.1
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-06-16 00:00:00.000000000 Z
11
+ date: 2016-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -121,6 +121,7 @@ files:
121
121
  - lib/recastai/utils.rb
122
122
  - misc/.gitkeep
123
123
  - misc/logo-inline.png
124
+ - misc/recast-ai-tokens.png
124
125
  - recastai.gemspec
125
126
  homepage: https://github.com/RecastAI/SDK-ruby
126
127
  licenses: