rosette_api 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/request_builder.rb +9 -10
- data/lib/rosette_api.rb +39 -17
- data/tests/tests_spec.rb +91 -82
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 043eec6c3ad8b685d39a800f0ac35e3cc4eed855
|
4
|
+
data.tar.gz: cae1f598d5dcc1d8a3253af1479aa9f2c180ebdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7772af70981b1b2d49ecd0249a587ecbaeb800696f66527c0efb7b4d34ece71eaf56281a7e92ab75bb2c6ca936d5cfcaa328712eb45ce0fdea7738e30e5daf7d
|
7
|
+
data.tar.gz: d30c2a814a7dcfedb1e6aacfd720fa0e16925707cc537e68ada5b4c69a572353ba6a2f640ecd0c610d16f765923222862925b26963b7a3ae44e07f28b97f5ce8
|
data/lib/request_builder.rb
CHANGED
@@ -9,6 +9,8 @@ require_relative 'rosette_api_error'
|
|
9
9
|
class RequestBuilder
|
10
10
|
# Alternate Rosette API URL
|
11
11
|
attr_reader :alternate_url
|
12
|
+
# Rosette API HTTP client
|
13
|
+
attr_reader :http_client
|
12
14
|
# Parameters to build the body of the request from
|
13
15
|
attr_accessor :params
|
14
16
|
# Rosette API key
|
@@ -16,12 +18,15 @@ class RequestBuilder
|
|
16
18
|
# Rosette API binding version
|
17
19
|
attr_accessor :binding_version
|
18
20
|
|
19
|
-
|
21
|
+
|
22
|
+
def initialize(user_key, alternate_url, http_client, params = {}, binding_version) #:notnew:
|
20
23
|
@user_key = user_key
|
21
24
|
@alternate_url = alternate_url
|
25
|
+
@http_client = http_client
|
22
26
|
@params = params
|
23
27
|
@retries = 5
|
24
28
|
@binding_version = binding_version
|
29
|
+
|
25
30
|
end
|
26
31
|
|
27
32
|
# Prepares a plain POST request for Rosette API.
|
@@ -34,8 +39,6 @@ class RequestBuilder
|
|
34
39
|
def prepare_plain_request(params)
|
35
40
|
begin
|
36
41
|
uri = URI.parse @alternate_url
|
37
|
-
http = Net::HTTP.new uri.host, uri.port
|
38
|
-
http.use_ssl = uri.scheme == 'https'
|
39
42
|
request = Net::HTTP::Post.new uri.request_uri
|
40
43
|
rescue
|
41
44
|
raise RosetteAPIError.new 'connectionError', 'Failed to establish connection with Rosette API server.'
|
@@ -60,7 +63,7 @@ class RequestBuilder
|
|
60
63
|
request['X-RosetteAPI-Binding-Version'] = @binding_version
|
61
64
|
request.body = params.to_json
|
62
65
|
|
63
|
-
[
|
66
|
+
[@http_client, request]
|
64
67
|
end
|
65
68
|
|
66
69
|
# Prepares a multipart/form-data POST request for Rosette API.
|
@@ -99,8 +102,6 @@ class RequestBuilder
|
|
99
102
|
# Create the HTTP objects
|
100
103
|
begin
|
101
104
|
uri = URI.parse @alternate_url
|
102
|
-
http = Net::HTTP.new uri.host, uri.port
|
103
|
-
http.use_ssl = uri.scheme == 'https'
|
104
105
|
request = Net::HTTP::Post.new uri.request_uri
|
105
106
|
rescue
|
106
107
|
raise RosetteAPIError.new 'connectionError', 'Failed to establish connection with Rosette API server.'
|
@@ -125,7 +126,7 @@ class RequestBuilder
|
|
125
126
|
request.add_field 'X-RosetteAPI-Binding-Version', @binding_version
|
126
127
|
request.body = post_body.join
|
127
128
|
|
128
|
-
[
|
129
|
+
[@http_client, request]
|
129
130
|
end
|
130
131
|
|
131
132
|
# Sends a GET request to Rosette API.
|
@@ -134,8 +135,6 @@ class RequestBuilder
|
|
134
135
|
def send_get_request
|
135
136
|
begin
|
136
137
|
uri = URI.parse @alternate_url
|
137
|
-
http = Net::HTTP.new uri.host, uri.port
|
138
|
-
http.use_ssl = uri.scheme == 'https'
|
139
138
|
|
140
139
|
request = Net::HTTP::Get.new uri.request_uri
|
141
140
|
rescue
|
@@ -143,7 +142,7 @@ class RequestBuilder
|
|
143
142
|
end
|
144
143
|
request['X-RosetteAPI-Key'] = @user_key
|
145
144
|
|
146
|
-
self.get_response
|
145
|
+
self.get_response @http_client, request
|
147
146
|
end
|
148
147
|
|
149
148
|
# Sends a POST request to Rosette API.
|
data/lib/rosette_api.rb
CHANGED
@@ -9,7 +9,7 @@ require_relative 'bad_request_format_error'
|
|
9
9
|
# This class allows you to access all Rosette API endpoints.
|
10
10
|
class RosetteAPI
|
11
11
|
# Version of Ruby binding
|
12
|
-
BINDING_VERSION = '1.
|
12
|
+
BINDING_VERSION = '1.3.0'
|
13
13
|
# Rosette API language endpoint
|
14
14
|
LANGUAGE_ENDPOINT = '/language'
|
15
15
|
# Rosette API morphology endpoint
|
@@ -34,6 +34,8 @@ class RosetteAPI
|
|
34
34
|
INFO = '/info'
|
35
35
|
# Rosette API ping endpoint
|
36
36
|
PING = '/ping'
|
37
|
+
# Text Embedding endpoint
|
38
|
+
TEXT_EMBEDDING = '/text-embedding'
|
37
39
|
|
38
40
|
# Rosette API key
|
39
41
|
attr_accessor :user_key
|
@@ -49,6 +51,10 @@ class RosetteAPI
|
|
49
51
|
if @alternate_url.to_s.end_with?('/')
|
50
52
|
@alternate_url = alternate_url.to_s.slice(0..-2)
|
51
53
|
end
|
54
|
+
|
55
|
+
uri = URI.parse alternate_url
|
56
|
+
@http_client = Net::HTTP.new uri.host, uri.port
|
57
|
+
@http_client.use_ssl = uri.scheme == 'https'
|
52
58
|
end
|
53
59
|
|
54
60
|
# Identifies in which language(s) the input is written.
|
@@ -63,7 +69,7 @@ class RosetteAPI
|
|
63
69
|
|
64
70
|
params = params.load_params
|
65
71
|
|
66
|
-
RequestBuilder.new(@user_key, @alternate_url + LANGUAGE_ENDPOINT, params, BINDING_VERSION)
|
72
|
+
RequestBuilder.new(@user_key, @alternate_url + LANGUAGE_ENDPOINT, @http_client, params, BINDING_VERSION)
|
67
73
|
.send_post_request
|
68
74
|
end
|
69
75
|
|
@@ -81,7 +87,7 @@ class RosetteAPI
|
|
81
87
|
|
82
88
|
params = params.load_params
|
83
89
|
|
84
|
-
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/complete', params, BINDING_VERSION)
|
90
|
+
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/complete', @http_client, params, BINDING_VERSION)
|
85
91
|
.send_post_request
|
86
92
|
end
|
87
93
|
|
@@ -98,7 +104,7 @@ class RosetteAPI
|
|
98
104
|
|
99
105
|
params = params.load_params
|
100
106
|
|
101
|
-
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/compound-components', params, BINDING_VERSION)
|
107
|
+
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/compound-components', @http_client, params, BINDING_VERSION)
|
102
108
|
.send_post_request
|
103
109
|
end
|
104
110
|
|
@@ -115,7 +121,7 @@ class RosetteAPI
|
|
115
121
|
|
116
122
|
params = params.load_params
|
117
123
|
|
118
|
-
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/han-readings', params, BINDING_VERSION)
|
124
|
+
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/han-readings', @http_client, params, BINDING_VERSION)
|
119
125
|
.send_post_request
|
120
126
|
end
|
121
127
|
|
@@ -131,7 +137,7 @@ class RosetteAPI
|
|
131
137
|
|
132
138
|
params = params.load_params
|
133
139
|
|
134
|
-
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/lemmas', params, BINDING_VERSION)
|
140
|
+
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/lemmas', @http_client, params, BINDING_VERSION)
|
135
141
|
.send_post_request
|
136
142
|
end
|
137
143
|
|
@@ -148,7 +154,7 @@ class RosetteAPI
|
|
148
154
|
|
149
155
|
params = params.load_params
|
150
156
|
|
151
|
-
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/parts-of-speech', params, BINDING_VERSION)
|
157
|
+
RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/parts-of-speech', @http_client, params, BINDING_VERSION)
|
152
158
|
.send_post_request
|
153
159
|
end
|
154
160
|
|
@@ -168,7 +174,7 @@ class RosetteAPI
|
|
168
174
|
params = params.load_params
|
169
175
|
|
170
176
|
endpoint = resolve_entities ? (ENTITIES_ENDPOINT + '/linked') : ENTITIES_ENDPOINT
|
171
|
-
RequestBuilder.new(@user_key, @alternate_url + endpoint, params, BINDING_VERSION)
|
177
|
+
RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client, params, BINDING_VERSION)
|
172
178
|
.send_post_request
|
173
179
|
end
|
174
180
|
|
@@ -200,7 +206,7 @@ class RosetteAPI
|
|
200
206
|
|
201
207
|
params = params.load_params
|
202
208
|
|
203
|
-
RequestBuilder.new(@user_key, @alternate_url + CATEGORIES_ENDPOINT, params, BINDING_VERSION)
|
209
|
+
RequestBuilder.new(@user_key, @alternate_url + CATEGORIES_ENDPOINT, @http_client, params, BINDING_VERSION)
|
204
210
|
.send_post_request
|
205
211
|
end
|
206
212
|
|
@@ -216,7 +222,7 @@ class RosetteAPI
|
|
216
222
|
|
217
223
|
params = params.load_params
|
218
224
|
|
219
|
-
RequestBuilder.new(@user_key, @alternate_url + RELATIONSHIPS_ENDPOINT, params, BINDING_VERSION)
|
225
|
+
RequestBuilder.new(@user_key, @alternate_url + RELATIONSHIPS_ENDPOINT, @http_client, params, BINDING_VERSION)
|
220
226
|
.send_post_request
|
221
227
|
end
|
222
228
|
|
@@ -232,7 +238,7 @@ class RosetteAPI
|
|
232
238
|
|
233
239
|
params = params.load_params
|
234
240
|
|
235
|
-
RequestBuilder.new(@user_key, @alternate_url + SENTIMENT_ENDPOINT, params, BINDING_VERSION)
|
241
|
+
RequestBuilder.new(@user_key, @alternate_url + SENTIMENT_ENDPOINT, @http_client, params, BINDING_VERSION)
|
236
242
|
.send_post_request
|
237
243
|
end
|
238
244
|
|
@@ -248,7 +254,7 @@ class RosetteAPI
|
|
248
254
|
|
249
255
|
params = params.load_params
|
250
256
|
|
251
|
-
RequestBuilder.new(@user_key, @alternate_url + NAME_TRANSLATION_ENDPOINT, params, BINDING_VERSION)
|
257
|
+
RequestBuilder.new(@user_key, @alternate_url + NAME_TRANSLATION_ENDPOINT, @http_client, params, BINDING_VERSION)
|
252
258
|
.send_post_request
|
253
259
|
end
|
254
260
|
|
@@ -265,7 +271,7 @@ class RosetteAPI
|
|
265
271
|
|
266
272
|
params = params.load_params
|
267
273
|
|
268
|
-
RequestBuilder.new(@user_key, @alternate_url + NAME_SIMILARITY_ENDPOINT, params, BINDING_VERSION)
|
274
|
+
RequestBuilder.new(@user_key, @alternate_url + NAME_SIMILARITY_ENDPOINT, @http_client, params, BINDING_VERSION)
|
269
275
|
.send_post_request
|
270
276
|
end
|
271
277
|
|
@@ -281,7 +287,7 @@ class RosetteAPI
|
|
281
287
|
|
282
288
|
params = params.load_params
|
283
289
|
|
284
|
-
RequestBuilder.new(@user_key, @alternate_url + TOKENS_ENDPOINT, params, BINDING_VERSION)
|
290
|
+
RequestBuilder.new(@user_key, @alternate_url + TOKENS_ENDPOINT, @http_client, params, BINDING_VERSION)
|
285
291
|
.send_post_request
|
286
292
|
end
|
287
293
|
|
@@ -297,21 +303,37 @@ class RosetteAPI
|
|
297
303
|
|
298
304
|
params = params.load_params
|
299
305
|
|
300
|
-
RequestBuilder.new(@user_key, @alternate_url + SENTENCES_ENDPOINT, params, BINDING_VERSION)
|
306
|
+
RequestBuilder.new(@user_key, @alternate_url + SENTENCES_ENDPOINT, @http_client, params, BINDING_VERSION)
|
307
|
+
.send_post_request
|
308
|
+
end
|
309
|
+
#
|
310
|
+
# Returns the vectors associated with the text
|
311
|
+
#
|
312
|
+
# ==== Attributes
|
313
|
+
#
|
314
|
+
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
|
315
|
+
#
|
316
|
+
# Returns list of linguistic sentences of the input.
|
317
|
+
def get_text_embedding(params)
|
318
|
+
check_params params
|
319
|
+
|
320
|
+
params = params.load_params
|
321
|
+
|
322
|
+
RequestBuilder.new(@user_key, @alternate_url + TEXT_EMBEDDING, @http_client, params, BINDING_VERSION)
|
301
323
|
.send_post_request
|
302
324
|
end
|
303
325
|
|
304
326
|
# Gets information about the Rosette API, returns name, build number
|
305
327
|
# and build time.
|
306
328
|
def info
|
307
|
-
RequestBuilder.new(@user_key, @alternate_url + INFO, BINDING_VERSION)
|
329
|
+
RequestBuilder.new(@user_key, @alternate_url + INFO, @http_client, BINDING_VERSION)
|
308
330
|
.send_get_request
|
309
331
|
end
|
310
332
|
|
311
333
|
# Pings the Rosette API for a response indicting that the service is
|
312
334
|
# available.
|
313
335
|
def ping
|
314
|
-
RequestBuilder.new(@user_key, @alternate_url + PING, BINDING_VERSION)
|
336
|
+
RequestBuilder.new(@user_key, @alternate_url + PING, @http_client, BINDING_VERSION)
|
315
337
|
.send_get_request
|
316
338
|
end
|
317
339
|
|
data/tests/tests_spec.rb
CHANGED
@@ -6,24 +6,27 @@ require 'json'
|
|
6
6
|
WebMock.disable_net_connect!(allow_localhost: true)
|
7
7
|
|
8
8
|
describe RosetteAPI do
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.before(:example) { @content = 'Sample Content' }
|
11
|
+
config.before(:example) { @json = {:content => "Sample Content"}.to_json }
|
12
|
+
end
|
9
13
|
|
10
14
|
describe '.get_language' do
|
11
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/language.json'))
|
12
15
|
before do
|
13
16
|
stub_request(:post, 'https://api.rosette.com/rest/v1/language').
|
14
|
-
with(body
|
15
|
-
headers
|
17
|
+
with(:body => @json,
|
18
|
+
:headers => {'Accept' => 'application/json',
|
16
19
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
17
20
|
'Content-Type' => 'application/json',
|
18
21
|
'User-Agent' => 'Ruby',
|
19
22
|
'X-Rosetteapi-Key' => '0123456789',
|
20
23
|
'X-Rosetteapi-Binding' => 'ruby',
|
21
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
22
|
-
to_return(status
|
24
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
25
|
+
to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {})
|
23
26
|
end
|
24
27
|
it 'test language' do
|
25
28
|
params = DocumentParameters.new
|
26
|
-
params.content =
|
29
|
+
params.content = @content
|
27
30
|
response = RosetteAPI.new('0123456789').get_language(params)
|
28
31
|
expect(response).instance_of? Hash
|
29
32
|
end
|
@@ -45,156 +48,148 @@ describe RosetteAPI do
|
|
45
48
|
end
|
46
49
|
|
47
50
|
describe '.get_morphology_complete' do
|
48
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_complete.json'))
|
49
51
|
before do
|
50
52
|
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/complete').
|
51
|
-
with(body
|
53
|
+
with(:body => @json,
|
52
54
|
headers: {'Accept' => 'application/json',
|
53
55
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
54
56
|
'Content-Type' => 'application/json',
|
55
57
|
'User-Agent' => 'Ruby',
|
56
58
|
'X-Rosetteapi-Key' => '0123456789',
|
57
59
|
'X-Rosetteapi-Binding' => 'ruby',
|
58
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
59
|
-
to_return(status
|
60
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
61
|
+
to_return(:status => 200, :body => "{\"test\": \"morphology/complete\"}", :headers => {})
|
60
62
|
end
|
61
63
|
it 'test morphology complete' do
|
62
64
|
params = DocumentParameters.new
|
63
|
-
params.content =
|
65
|
+
params.content = @content
|
64
66
|
response = RosetteAPI.new('0123456789').get_morphology_complete(params)
|
65
67
|
expect(response).instance_of? Hash
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
69
71
|
describe '.get_compound_components' do
|
70
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_compound_components.json'))
|
71
72
|
before do
|
72
73
|
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/compound-components').
|
73
|
-
with(body
|
74
|
+
with(:body => @json,
|
74
75
|
headers: {'Accept' => 'application/json',
|
75
76
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
76
77
|
'Content-Type' => 'application/json',
|
77
78
|
'User-Agent' => 'Ruby',
|
78
79
|
'X-Rosetteapi-Key' => '0123456789',
|
79
80
|
'X-Rosetteapi-Binding' => 'ruby',
|
80
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
81
|
-
to_return(status
|
81
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
82
|
+
to_return(:status => 200, :body => "{\"test\": \"morphology/compound-components\"}", :headers => {})
|
82
83
|
end
|
83
84
|
it 'test morphology compound components' do
|
84
85
|
params = DocumentParameters.new
|
85
|
-
params.content =
|
86
|
+
params.content = @content
|
86
87
|
response = RosetteAPI.new('0123456789').get_compound_components(params)
|
87
88
|
expect(response).instance_of? Hash
|
88
89
|
end
|
89
90
|
end
|
90
91
|
|
91
92
|
describe '.get_han_readings' do
|
92
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_han_readings.json')), encoding: 'utf-8'
|
93
93
|
before do
|
94
94
|
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/han-readings').
|
95
|
-
with(body
|
95
|
+
with(:body => @json,
|
96
96
|
headers: {'Accept' => 'application/json',
|
97
97
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
98
98
|
'Content-Type' => 'application/json',
|
99
99
|
'User-Agent' => 'Ruby',
|
100
100
|
'X-Rosetteapi-Key' => '0123456789',
|
101
101
|
'X-Rosetteapi-Binding' => 'ruby',
|
102
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
103
|
-
to_return(status
|
102
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
103
|
+
to_return(:status => 200, :body => "{\"test\": \"morphology/han-readings\"}", :headers => {})
|
104
104
|
end
|
105
105
|
it 'test morphology han readings' do
|
106
106
|
params = DocumentParameters.new
|
107
|
-
params.content =
|
107
|
+
params.content = @content
|
108
108
|
response = RosetteAPI.new('0123456789').get_han_readings(params)
|
109
109
|
expect(response).instance_of? Hash
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
describe '.get_parts_of_speech' do
|
114
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_parts_of_speech.json'))
|
115
114
|
before do
|
116
115
|
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/parts-of-speech').
|
117
|
-
with(body
|
116
|
+
with(:body => @json,
|
118
117
|
headers: {'Accept' => 'application/json',
|
119
118
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
120
119
|
'Content-Type' => 'application/json',
|
121
120
|
'User-Agent' => 'Ruby',
|
122
121
|
'X-Rosetteapi-Key' => '0123456789',
|
123
122
|
'X-Rosetteapi-Binding' => 'ruby',
|
124
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
125
|
-
to_return(status
|
123
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
124
|
+
to_return(:status => 200, :body => "{\"test\": \"morphology/parts-of-speech\"}", :headers => {})
|
126
125
|
end
|
127
126
|
it 'test morphology parts of speech' do
|
128
127
|
params = DocumentParameters.new
|
129
|
-
params.content =
|
128
|
+
params.content = @content
|
130
129
|
response = RosetteAPI.new('0123456789').get_parts_of_speech(params)
|
131
130
|
expect(response).instance_of? Hash
|
132
131
|
end
|
133
132
|
end
|
134
133
|
|
135
134
|
describe '.get_lemmas' do
|
136
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_lemmas.json'))
|
137
135
|
before do
|
138
136
|
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/lemmas').
|
139
|
-
with(body
|
137
|
+
with(:body => @json,
|
140
138
|
headers: {'Accept' => 'application/json',
|
141
139
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
142
140
|
'Content-Type' => 'application/json',
|
143
141
|
'User-Agent' => 'Ruby',
|
144
142
|
'X-Rosetteapi-Key' => '0123456789',
|
145
143
|
'X-Rosetteapi-Binding' => 'ruby',
|
146
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
147
|
-
to_return(status
|
144
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
145
|
+
to_return(:status => 200, :body => "{\"test\": \"morphology/lemmas\"}", :headers => {})
|
148
146
|
end
|
149
147
|
it 'test morphology lemmas' do
|
150
148
|
params = DocumentParameters.new
|
151
|
-
params.content =
|
149
|
+
params.content = @content
|
152
150
|
response = RosetteAPI.new('0123456789').get_lemmas(params)
|
153
151
|
expect(response).instance_of? Hash
|
154
152
|
end
|
155
153
|
end
|
156
154
|
|
157
155
|
describe '.get_entities' do
|
158
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/entities.json')), encoding: 'utf-8'
|
159
156
|
before do
|
160
157
|
stub_request(:post, 'https://api.rosette.com/rest/v1/entities').
|
161
|
-
with(body
|
158
|
+
with(:body => @json,
|
162
159
|
headers: {'Accept' => 'application/json',
|
163
160
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
164
161
|
'Content-Type' => 'application/json',
|
165
162
|
'User-Agent' => 'Ruby',
|
166
163
|
'X-Rosetteapi-Key' => '0123456789',
|
167
164
|
'X-Rosetteapi-Binding' => 'ruby',
|
168
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
169
|
-
to_return(status
|
165
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
166
|
+
to_return(:status => 200, :body => "{\"test\": \"entities\"}", :headers => {})
|
170
167
|
end
|
171
168
|
it 'test entities' do
|
172
169
|
params = DocumentParameters.new
|
173
|
-
params.content =
|
174
|
-
' cameo in Boston this… http://dlvr.it/BnsFfS'
|
170
|
+
params.content = @content
|
175
171
|
response = RosetteAPI.new('0123456789').get_entities(params)
|
176
172
|
expect(response).instance_of? Hash
|
177
173
|
end
|
178
174
|
end
|
179
175
|
|
180
176
|
describe '.get_entities_no_qids' do
|
181
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/entities_no_qids.json'))
|
182
177
|
before do
|
178
|
+
no_qids_json = {:content => "Sample Content", :options => {:linkEntities => false}}.to_json
|
183
179
|
stub_request(:post, 'https://api.rosette.com/rest/v1/entities').
|
184
|
-
with(body
|
180
|
+
with(:body => no_qids_json,
|
185
181
|
headers: {'Accept' => 'application/json',
|
186
182
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
187
183
|
'Content-Type' => 'application/json',
|
188
184
|
'User-Agent' => 'Ruby',
|
189
185
|
'X-Rosetteapi-Key' => '0123456789',
|
190
186
|
'X-Rosetteapi-Binding' => 'ruby',
|
191
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
192
|
-
to_return(status
|
187
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
188
|
+
to_return(:status => 200, :body => "{\"test\": \"entities\"}", :headers => {})
|
193
189
|
end
|
194
190
|
it 'test entities without qids' do
|
195
191
|
params = DocumentParameters.new
|
196
|
-
params.content =
|
197
|
-
' Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon.'
|
192
|
+
params.content = @content
|
198
193
|
params.rosette_options = { linkEntities: false}
|
199
194
|
response = RosetteAPI.new('0123456789').get_entities(params)
|
200
195
|
expect(response).instance_of? Hash
|
@@ -210,62 +205,61 @@ describe RosetteAPI do
|
|
210
205
|
end
|
211
206
|
|
212
207
|
describe '.get_categories' do
|
213
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/categories.json'))
|
214
208
|
before do
|
209
|
+
categories_json = {:contentUri => "http://google.com"}.to_json
|
215
210
|
stub_request(:post, 'https://api.rosette.com/rest/v1/categories').
|
216
|
-
with(body
|
211
|
+
with(:body => categories_json,
|
217
212
|
headers: {'Accept' => 'application/json',
|
218
213
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
219
214
|
'Content-Type' => 'application/json',
|
220
215
|
'User-Agent' => 'Ruby',
|
221
216
|
'X-Rosetteapi-Key' => '0123456789',
|
222
217
|
'X-Rosetteapi-Binding' => 'ruby',
|
223
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
224
|
-
to_return(status
|
218
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
219
|
+
to_return(:status => 200, :body => "{\"test\": \"categories\"}", :headers => {})
|
225
220
|
end
|
226
221
|
it 'test categories' do
|
227
222
|
params = DocumentParameters.new
|
228
|
-
params.content_uri =
|
223
|
+
params.content_uri = "http://google.com"
|
229
224
|
response = RosetteAPI.new('0123456789').get_categories(params)
|
230
225
|
expect(response).instance_of? Hash
|
231
226
|
end
|
232
227
|
end
|
233
228
|
|
234
229
|
describe '.get_relationships' do
|
235
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/relationships.json'))
|
236
230
|
before do
|
237
231
|
stub_request(:post, 'https://api.rosette.com/rest/v1/relationships').
|
238
|
-
with(body
|
232
|
+
with(:body => @json,
|
239
233
|
headers: {'Accept' => 'application/json',
|
240
234
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
241
235
|
'Content-Type' => 'application/json',
|
242
236
|
'User-Agent' => 'Ruby',
|
243
237
|
'X-Rosetteapi-Key' => '0123456789',
|
244
238
|
'X-Rosetteapi-Binding' => 'ruby',
|
245
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
246
|
-
to_return(status
|
239
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
240
|
+
to_return(:status => 200, :body => "{\"test\": \"relationships\"}", :headers => {})
|
247
241
|
end
|
248
242
|
it 'test relationships' do
|
249
243
|
params = DocumentParameters.new
|
250
|
-
params.content =
|
244
|
+
params.content = @content
|
251
245
|
response = RosetteAPI.new('0123456789').get_relationships(params)
|
252
246
|
expect(response).instance_of? Hash
|
253
247
|
end
|
254
248
|
end
|
255
249
|
|
256
250
|
describe '.name_translation' do
|
257
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/name_translation.json')), encoding: 'utf-8'
|
258
251
|
before do
|
252
|
+
name_translation_json = {:name => "معمر محمد أبو منيار القذاف", :targetLanguage => "eng", :targetScript => "Latn"}.to_json
|
259
253
|
stub_request(:post, 'https://api.rosette.com/rest/v1/name-translation').
|
260
|
-
with(body
|
254
|
+
with(:body => name_translation_json,
|
261
255
|
headers: {'Accept' => 'application/json',
|
262
256
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
263
257
|
'Content-Type' => 'application/json',
|
264
258
|
'User-Agent' => 'Ruby',
|
265
259
|
'X-Rosetteapi-Key' => '0123456789',
|
266
260
|
'X-Rosetteapi-Binding' => 'ruby',
|
267
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
268
|
-
to_return(status
|
261
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
262
|
+
to_return(:status => 200, :body => "{\"test\": \"name-translation\"}", :headers => {})
|
269
263
|
end
|
270
264
|
it 'test name translation' do
|
271
265
|
params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng')
|
@@ -281,18 +275,18 @@ describe RosetteAPI do
|
|
281
275
|
end
|
282
276
|
|
283
277
|
describe '.name_similarity' do
|
284
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/name_similarity.json')), encoding: 'utf-8'
|
285
278
|
before do
|
279
|
+
name_similarity_json = {:name1 => "Michael Jackson", :name2 => "迈克尔·杰克逊"}.to_json
|
286
280
|
stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity').
|
287
|
-
with(body
|
281
|
+
with(:body => name_similarity_json,
|
288
282
|
headers: {'Accept' => 'application/json',
|
289
283
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
290
284
|
'Content-Type' => 'application/json',
|
291
285
|
'User-Agent' => 'Ruby',
|
292
286
|
'X-Rosetteapi-Key' => '0123456789',
|
293
287
|
'X-Rosetteapi-Binding' => 'ruby',
|
294
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
295
|
-
to_return(status
|
288
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
289
|
+
to_return(:status => 200, :body => "{\"test\": \"name-similarity\"}", :headers => {})
|
296
290
|
end
|
297
291
|
it 'test name similarity' do
|
298
292
|
params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊')
|
@@ -317,47 +311,42 @@ describe RosetteAPI do
|
|
317
311
|
end
|
318
312
|
|
319
313
|
describe '.get_tokens' do
|
320
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/tokens.json')), encoding: 'utf-8'
|
321
314
|
before do
|
322
315
|
stub_request(:post, 'https://api.rosette.com/rest/v1/tokens').
|
323
|
-
with(body
|
316
|
+
with(:body => @json,
|
324
317
|
headers: {'Accept' => 'application/json',
|
325
318
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
326
319
|
'Content-Type' => 'application/json',
|
327
320
|
'User-Agent' => 'Ruby',
|
328
321
|
'X-Rosetteapi-Key' => '0123456789',
|
329
322
|
'X-Rosetteapi-Binding' => 'ruby',
|
330
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
331
|
-
to_return(status
|
323
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
324
|
+
to_return(:status => 200, :body => "{\"test\": \"tokens\"}", :headers => {})
|
332
325
|
end
|
333
326
|
it 'test tokens' do
|
334
327
|
params = DocumentParameters.new
|
335
|
-
params.content =
|
328
|
+
params.content = @content
|
336
329
|
response = RosetteAPI.new('0123456789').get_tokens(params)
|
337
330
|
expect(response).instance_of? Hash
|
338
331
|
end
|
339
332
|
end
|
340
333
|
|
341
334
|
describe '.get_sentences' do
|
342
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/sentences.json'))
|
343
335
|
before do
|
344
336
|
stub_request(:post, 'https://api.rosette.com/rest/v1/sentences').
|
345
|
-
with(body
|
337
|
+
with(:body => @json,
|
346
338
|
headers: {'Accept' => 'application/json',
|
347
339
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
348
340
|
'Content-Type' => 'application/json',
|
349
341
|
'User-Agent' => 'Ruby',
|
350
342
|
'X-Rosetteapi-Key' => '0123456789',
|
351
343
|
'X-Rosetteapi-Binding' => 'ruby',
|
352
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
353
|
-
to_return(status
|
344
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
345
|
+
to_return(:status => 200, :body => "{\"test\": \"sentences\"}", :headers => {})
|
354
346
|
end
|
355
347
|
it 'test sentences' do
|
356
348
|
params = DocumentParameters.new
|
357
|
-
params.content =
|
358
|
-
' the wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was' \
|
359
|
-
' walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that' \
|
360
|
-
' golden valley:\nThis land was made for you and me.'
|
349
|
+
params.content = @content
|
361
350
|
response = RosetteAPI.new('0123456789').get_sentences(params)
|
362
351
|
expect(response).instance_of? Hash
|
363
352
|
end
|
@@ -370,7 +359,7 @@ describe RosetteAPI do
|
|
370
359
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
371
360
|
'User-Agent' => 'Ruby',
|
372
361
|
'X-Rosetteapi-Key' => '0123456789'}).
|
373
|
-
to_return(status
|
362
|
+
to_return(:status => 200, :body => "{\"test\": \"info\"}", :headers => {})
|
374
363
|
end
|
375
364
|
it 'test info' do
|
376
365
|
response = RosetteAPI.new('0123456789').info
|
@@ -385,7 +374,7 @@ describe RosetteAPI do
|
|
385
374
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
386
375
|
'User-Agent' => 'Ruby',
|
387
376
|
'X-Rosetteapi-Key' => '0123456789'}).
|
388
|
-
to_return(status
|
377
|
+
to_return(:status => 200, :body => "{\"test\": \"ping\"}", :headers => {})
|
389
378
|
end
|
390
379
|
it 'test ping' do
|
391
380
|
response = RosetteAPI.new('0123456789').ping
|
@@ -394,25 +383,24 @@ describe RosetteAPI do
|
|
394
383
|
end
|
395
384
|
|
396
385
|
describe '.get_language_custom_header' do
|
397
|
-
request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/language.json'))
|
398
386
|
before do
|
399
387
|
stub_request(:post, 'https://api.rosette.com/rest/v1/language').
|
400
|
-
with(body
|
388
|
+
with(:body => @json,
|
401
389
|
headers: {'Accept' => 'application/json',
|
402
390
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
403
391
|
'Content-Type' => 'application/json',
|
404
392
|
'User-Agent' => 'Ruby',
|
405
393
|
'X-Rosetteapi-Key' => '0123456789',
|
406
394
|
'X-Rosetteapi-Binding' => 'ruby',
|
407
|
-
'X-Rosetteapi-Binding-Version' => '1.
|
395
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0',
|
408
396
|
'X-RosetteApi-App' => 'ruby-app'}).
|
409
|
-
to_return(status
|
397
|
+
to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {})
|
410
398
|
end
|
411
399
|
|
412
400
|
it 'test custom_headers is invalid' do
|
413
401
|
params = DocumentParameters.new
|
414
402
|
params.content = 'Por favor Senorita, says the man.?'
|
415
|
-
params.custom_headers = {
|
403
|
+
params.custom_headers = {"test" => "ruby-app"}
|
416
404
|
expect { RosetteAPI.new('0123456789').get_language(params) }.to raise_error(RosetteAPIError)
|
417
405
|
end
|
418
406
|
end
|
@@ -424,12 +412,33 @@ describe RosetteAPI do
|
|
424
412
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
425
413
|
'User-Agent' => 'Ruby',
|
426
414
|
'X-Rosetteapi-Key' => '0123456789'}).
|
427
|
-
to_return(status
|
415
|
+
to_return(:status => 409, :body => "{\"code\": \"incompatibleClientVersion\"}", :headers => {})
|
428
416
|
end
|
429
417
|
it 'test error 409 properly handled' do
|
430
418
|
expect { RosetteAPI.new('0123456789').info }.to raise_error(RosetteAPIError)
|
431
419
|
end
|
432
420
|
end
|
433
421
|
|
422
|
+
describe '.get_text_embedding' do
|
423
|
+
before do
|
424
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/text-embedding').
|
425
|
+
with(:body => @json,
|
426
|
+
:headers => {'Accept' => 'application/json',
|
427
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
428
|
+
'Content-Type' => 'application/json',
|
429
|
+
'User-Agent' => 'Ruby',
|
430
|
+
'X-Rosetteapi-Key' => '0123456789',
|
431
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
432
|
+
'X-Rosetteapi-Binding-Version' => '1.3.0'}).
|
433
|
+
to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {})
|
434
|
+
end
|
435
|
+
it 'test text_embedding' do
|
436
|
+
params = DocumentParameters.new
|
437
|
+
params.content = @content
|
438
|
+
response = RosetteAPI.new('0123456789').get_text_embedding(params)
|
439
|
+
expect(response).instance_of? Hash
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
434
443
|
|
435
444
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rosette_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Basis Technology Corp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubysl-securerandom
|