rosette_api 1.5.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/document_parameters.rb +2 -2
- data/lib/name_deduplication_parameters.rb +56 -0
- data/lib/name_parameter.rb +3 -3
- data/lib/name_similarity_parameters.rb +7 -9
- data/lib/name_translation_parameters.rb +5 -5
- data/lib/request_builder.rb +11 -11
- data/lib/rosette_api.rb +41 -3
- data/tests/tests_spec.rb +305 -207
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd2e11be02e9d5b53eb5e70f2878713438155663
|
4
|
+
data.tar.gz: 255a67fd51abe249733fc8713bba8f642cfd770a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3646013573953385758c5c87bcb92e92ab5d4215f68d34d69a3ef085b6e13ed270c9a04c16961ee694048e75d53fc1a4195477731ea1ded724900f910def4acb
|
7
|
+
data.tar.gz: 666aa84265d7adcd15440e875fd6582d3a24536cb0456f845bcf7ace86b04c6f01b26dd319fbaf5b18a79bb8735be753672bcb836aee46eb43df1f4c189e9a78
|
data/lib/document_parameters.rb
CHANGED
@@ -47,7 +47,7 @@ class DocumentParameters
|
|
47
47
|
elsif [@content, @content_uri, @file_path].all?(&:nil?)
|
48
48
|
raise BadRequestFormatError.new 'The format of the request is invalid: no content provided; must' \
|
49
49
|
' be one of an attachment, an inline "content" field, or an external "contentUri"'
|
50
|
-
elsif
|
50
|
+
elsif @rosette_options
|
51
51
|
raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash
|
52
52
|
end
|
53
53
|
end
|
@@ -57,7 +57,7 @@ class DocumentParameters
|
|
57
57
|
# Returns the new Hash.
|
58
58
|
def load_params
|
59
59
|
validate_params
|
60
|
-
to_hash.select { |_key, value|
|
60
|
+
to_hash.select { |_key, value| value }
|
61
61
|
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
62
62
|
.to_h
|
63
63
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative 'bad_request_error'
|
2
|
+
require_relative 'name_parameter'
|
3
|
+
|
4
|
+
# This class encapsulates parameters that are needed for name-deduplication in
|
5
|
+
# Rosette API.
|
6
|
+
class NameDeduplicationParameters
|
7
|
+
# Rosette API options (optional, should be a hash)
|
8
|
+
attr_accessor :rosette_options
|
9
|
+
# List of Name objects to be de-duplicated
|
10
|
+
attr_accessor :names
|
11
|
+
# Threshold for determining cluster size
|
12
|
+
attr_accessor :threshold
|
13
|
+
|
14
|
+
def initialize(names, threshold, options = {}) #:notnew:
|
15
|
+
options = {
|
16
|
+
rosette_options: nil
|
17
|
+
}.update options
|
18
|
+
@names = names
|
19
|
+
@threshold = threshold
|
20
|
+
@rosette_options = options[:rosette_options]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Validates the parameters by checking if name1 and name2 are instances of
|
24
|
+
# a String or NameParameter.
|
25
|
+
def validate_params
|
26
|
+
raise BadRequestError.new('names must be an array of name_parameter') unless @names.instance_of? Array
|
27
|
+
if @threshold
|
28
|
+
raise BadRequestError.new('threshold must be a float') unless @threshold.is_a?(Float)
|
29
|
+
raise BadRequestError.new('threshold must be in the range of 0 to 1') if @threshold.negative? || @threshold > 1
|
30
|
+
end
|
31
|
+
if @rosette_options
|
32
|
+
raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Converts this class to Hash with its keys in lower CamelCase.
|
37
|
+
#
|
38
|
+
# Returns the new Hash.
|
39
|
+
def load_params
|
40
|
+
validate_params
|
41
|
+
to_hash.select { |_key, value| value }
|
42
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
43
|
+
.to_h
|
44
|
+
end
|
45
|
+
|
46
|
+
# Converts this class to Hash.
|
47
|
+
#
|
48
|
+
# Returns the new Hash.
|
49
|
+
def to_hash
|
50
|
+
{
|
51
|
+
names: @names.map(&:load_param),
|
52
|
+
threshold: @threshold,
|
53
|
+
options: @rosette_options
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
data/lib/name_parameter.rb
CHANGED
@@ -25,9 +25,9 @@ class NameParameter
|
|
25
25
|
#
|
26
26
|
# Returns the new Hash.
|
27
27
|
def load_param
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
to_hash.select { |_key, value| value }
|
29
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
30
|
+
.to_h
|
31
31
|
end
|
32
32
|
|
33
33
|
# Converts this class to Hash.
|
@@ -27,11 +27,9 @@ class NameSimilarityParameters
|
|
27
27
|
# Validates the parameters by checking if name1 and name2 are instances of
|
28
28
|
# a String or NameParameter.
|
29
29
|
def validate_params
|
30
|
-
if [String, NameParameter].none? { |clazz| @name1.is_a? clazz }
|
31
|
-
|
32
|
-
|
33
|
-
raise BadRequestError.new('name2 option can only be an instance of a String or NameParameter')
|
34
|
-
elsif !@rosette_options.nil?
|
30
|
+
raise BadRequestError.new('name1 option can only be an instance of a String or NameParameter') if [String, NameParameter].none? { |clazz| @name1.is_a? clazz }
|
31
|
+
raise BadRequestError.new('name2 option can only be an instance of a String or NameParameter') if [String, NameParameter].none? { |clazz| @name2.is_a? clazz }
|
32
|
+
if @rosette_options
|
35
33
|
raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash
|
36
34
|
end
|
37
35
|
end
|
@@ -40,10 +38,10 @@ class NameSimilarityParameters
|
|
40
38
|
#
|
41
39
|
# Returns the new Hash.
|
42
40
|
def load_params
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
validate_params
|
42
|
+
to_hash.reject { |_key, value| value.nil? }
|
43
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
44
|
+
.to_h
|
47
45
|
end
|
48
46
|
|
49
47
|
# Converts this class to Hash.
|
@@ -49,7 +49,7 @@ class NameTranslationParameters
|
|
49
49
|
|
50
50
|
# Validates the parameters by checking if rosette_options is an instance of a Hash.
|
51
51
|
def validate_params
|
52
|
-
if
|
52
|
+
if @rosette_options
|
53
53
|
raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash
|
54
54
|
end
|
55
55
|
end
|
@@ -58,10 +58,10 @@ class NameTranslationParameters
|
|
58
58
|
#
|
59
59
|
# Returns the new Hash.
|
60
60
|
def load_params
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
validate_params
|
62
|
+
to_hash.select { |_key, value| value }
|
63
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
64
|
+
.to_h
|
65
65
|
end
|
66
66
|
|
67
67
|
# Converts this class to Hash.
|
data/lib/request_builder.rb
CHANGED
@@ -18,7 +18,6 @@ class RequestBuilder
|
|
18
18
|
# Rosette API binding version
|
19
19
|
attr_accessor :binding_version
|
20
20
|
|
21
|
-
|
22
21
|
def initialize(user_key, alternate_url, http_client, params = {}, url_parameters = nil, binding_version)
|
23
22
|
@user_key = user_key
|
24
23
|
@alternate_url = alternate_url
|
@@ -28,7 +27,6 @@ class RequestBuilder
|
|
28
27
|
|
29
28
|
return unless url_parameters
|
30
29
|
@alternate_url = @alternate_url + '?' + URI.encode_www_form(url_parameters)
|
31
|
-
|
32
30
|
end
|
33
31
|
|
34
32
|
# Prepares a plain POST request for Rosette API.
|
@@ -46,13 +44,15 @@ class RequestBuilder
|
|
46
44
|
raise RosetteAPIError.new 'connectionError', 'Failed to establish connection with Rosette API server.'
|
47
45
|
end
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
custom_headers = params['customHeaders']
|
48
|
+
|
49
|
+
if custom_headers
|
50
|
+
keys_array = custom_headers.keys
|
51
|
+
for key in keys_array
|
52
|
+
if key.to_s =~ /^X-RosetteAPI-/
|
53
|
+
request[key] = custom_headers[key]
|
54
54
|
else
|
55
|
-
|
55
|
+
raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
params.delete 'customHeaders'
|
@@ -108,15 +108,15 @@ class RequestBuilder
|
|
108
108
|
rescue
|
109
109
|
raise RosetteAPIError.new 'connectionError', 'Failed to establish connection with Rosette API server.'
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
# add any custom headers from the user
|
113
|
-
|
113
|
+
unless params['customHeaders'].nil?
|
114
114
|
keys_array = params['customHeaders'].keys
|
115
115
|
for k in keys_array
|
116
116
|
if k.to_s =~ /^X-RosetteAPI-/
|
117
117
|
request.add_field k, params['customHeaders'][k]
|
118
118
|
else
|
119
|
-
|
119
|
+
raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"'
|
120
120
|
end
|
121
121
|
end
|
122
122
|
params.delete 'customHeaders'
|
data/lib/rosette_api.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'request_builder'
|
2
2
|
require_relative 'document_parameters'
|
3
|
+
require_relative 'name_deduplication_parameters'
|
3
4
|
require_relative 'name_translation_parameters'
|
4
5
|
require_relative 'name_similarity_parameters'
|
5
6
|
require_relative 'rosette_api_error'
|
@@ -9,7 +10,7 @@ require_relative 'bad_request_format_error'
|
|
9
10
|
# This class allows you to access all Rosette API endpoints.
|
10
11
|
class RosetteAPI
|
11
12
|
# Version of Ruby binding
|
12
|
-
BINDING_VERSION = '1.
|
13
|
+
BINDING_VERSION = '1.7.0'
|
13
14
|
# Rosette API language endpoint
|
14
15
|
LANGUAGE_ENDPOINT = '/language'.freeze
|
15
16
|
# Rosette API morphology endpoint
|
@@ -22,6 +23,8 @@ class RosetteAPI
|
|
22
23
|
RELATIONSHIPS_ENDPOINT = '/relationships'.freeze
|
23
24
|
# Rosette API sentiment endpoint
|
24
25
|
SENTIMENT_ENDPOINT = '/sentiment'.freeze
|
26
|
+
# Name Deduplication endpoint
|
27
|
+
NAME_DEDUPLICATION_ENDPOINT = '/name-deduplication'.freeze
|
25
28
|
# Rosette API name-translation endpoint
|
26
29
|
NAME_TRANSLATION_ENDPOINT = '/name-translation'.freeze
|
27
30
|
# Rosette API name-similarity endpoint
|
@@ -38,6 +41,8 @@ class RosetteAPI
|
|
38
41
|
TEXT_EMBEDDING = '/text-embedding'.freeze
|
39
42
|
# Syntactic Dependencies endpoint
|
40
43
|
SYNTACTIC_DEPENDENCIES_ENDPOINT = '/syntax/dependencies'.freeze
|
44
|
+
# Transliteration endpoint
|
45
|
+
TRANSLITERATION_ENDPOINT = '/transliteration'.freeze
|
41
46
|
|
42
47
|
# Rosette API key
|
43
48
|
attr_accessor :user_key
|
@@ -228,6 +233,22 @@ class RosetteAPI
|
|
228
233
|
.send_post_request
|
229
234
|
end
|
230
235
|
|
236
|
+
# De-duplicates a list of names.
|
237
|
+
#
|
238
|
+
# ==== Attributes
|
239
|
+
#
|
240
|
+
# * +params+ - NameDeduplicationParameters helps to build the request body in RequestBuilder.
|
241
|
+
#
|
242
|
+
# Returns the list of deduplicated names.
|
243
|
+
def get_name_deduplication(params)
|
244
|
+
check_params params, 'Expects a NameDeduplicationParameters type as an argument', NameDeduplicationParameters
|
245
|
+
|
246
|
+
params = params.load_params
|
247
|
+
|
248
|
+
RequestBuilder.new(@user_key, @alternate_url + NAME_DEDUPLICATION_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION)
|
249
|
+
.send_post_request
|
250
|
+
end
|
251
|
+
|
231
252
|
# Translates a given name to a supported specified language.
|
232
253
|
#
|
233
254
|
# ==== Attributes
|
@@ -235,7 +256,7 @@ class RosetteAPI
|
|
235
256
|
# * +params+ - NameTranslationParameters helps to build the request body in RequestBuilder.
|
236
257
|
#
|
237
258
|
# Returns the translation of a name.
|
238
|
-
def
|
259
|
+
def get_name_translation(params)
|
239
260
|
check_params params, 'Expects a NameTranslationParameters type as an argument', NameTranslationParameters
|
240
261
|
|
241
262
|
params = params.load_params
|
@@ -252,7 +273,7 @@ class RosetteAPI
|
|
252
273
|
# * +params+ - NameSimilarityParameters helps to build the request body in RequestBuilder.
|
253
274
|
#
|
254
275
|
# Returns the confidence score of matching 2 names.
|
255
|
-
def
|
276
|
+
def get_name_similarity(params)
|
256
277
|
check_params params, 'Expects a NameSimilarityParameters type as an argument', NameSimilarityParameters
|
257
278
|
|
258
279
|
params = params.load_params
|
@@ -327,6 +348,23 @@ class RosetteAPI
|
|
327
348
|
.send_post_request
|
328
349
|
end
|
329
350
|
|
351
|
+
#
|
352
|
+
# Returns the transliteration of the content
|
353
|
+
#
|
354
|
+
# ==== Attributes
|
355
|
+
#
|
356
|
+
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
|
357
|
+
#
|
358
|
+
# Returns the transliteration of the input.
|
359
|
+
def get_transliteration(params)
|
360
|
+
check_params params, 'Expects a DocumentParameters type as an argument', DocumentParameters
|
361
|
+
|
362
|
+
params = params.load_params
|
363
|
+
|
364
|
+
RequestBuilder.new(@user_key, @alternate_url + TRANSLITERATION_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION)
|
365
|
+
.send_post_request
|
366
|
+
end
|
367
|
+
|
330
368
|
# Gets information about the Rosette API, returns name, build number
|
331
369
|
# and build time.
|
332
370
|
def info
|
data/tests/tests_spec.rb
CHANGED
@@ -7,22 +7,22 @@ WebMock.disable_net_connect!(allow_localhost: true)
|
|
7
7
|
|
8
8
|
describe RosetteAPI do
|
9
9
|
RSpec.configure do |config|
|
10
|
-
|
11
|
-
|
10
|
+
config.before(:example) { @content = 'Sample Content' }
|
11
|
+
config.before(:example) { @json = {content: 'Sample Content'}.to_json }
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '.get_language' do
|
15
15
|
before do
|
16
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/language')
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/language')
|
17
|
+
.with(body: @json,
|
18
|
+
headers: { 'Accept' => 'application/json',
|
19
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
20
|
+
'Content-Type' => 'application/json',
|
21
|
+
'User-Agent' => 'Ruby',
|
22
|
+
'X-Rosetteapi-Key' => '0123456789',
|
23
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
24
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
25
|
+
.to_return(status: 200, body: '{"test": "language"}', headers: {})
|
26
26
|
end
|
27
27
|
it 'test language' do
|
28
28
|
params = DocumentParameters.new
|
@@ -40,25 +40,23 @@ describe RosetteAPI do
|
|
40
40
|
|
41
41
|
it 'badRequestFormat: the format of the request is invalid: no content provided;' do
|
42
42
|
params = DocumentParameters.new
|
43
|
-
expect { RosetteAPI.new('0123456789')
|
44
|
-
.get_language(params) }
|
45
|
-
.to raise_error(BadRequestFormatError)
|
43
|
+
expect { RosetteAPI.new('0123456789').get_language(params) }.to raise_error(BadRequestFormatError)
|
46
44
|
end
|
47
45
|
|
48
46
|
end
|
49
47
|
|
50
48
|
describe '.get_morphology_complete' do
|
51
49
|
before do
|
52
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/complete')
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
50
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/complete')
|
51
|
+
.with(body: @json,
|
52
|
+
headers: { 'Accept' => 'application/json',
|
53
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
54
|
+
'Content-Type' => 'application/json',
|
55
|
+
'User-Agent' => 'Ruby',
|
56
|
+
'X-Rosetteapi-Key' => '0123456789',
|
57
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
58
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
59
|
+
.to_return(status: 200, body: '{"test": "morphology/complete"}', headers: {})
|
62
60
|
end
|
63
61
|
it 'test morphology complete' do
|
64
62
|
params = DocumentParameters.new
|
@@ -70,16 +68,16 @@ describe RosetteAPI do
|
|
70
68
|
|
71
69
|
describe '.get_compound_components' do
|
72
70
|
before do
|
73
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/compound-components')
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
71
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/compound-components')
|
72
|
+
.with(body: @json,
|
73
|
+
headers: { 'Accept' => 'application/json',
|
74
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
75
|
+
'Content-Type' => 'application/json',
|
76
|
+
'User-Agent' => 'Ruby',
|
77
|
+
'X-Rosetteapi-Key' => '0123456789',
|
78
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
79
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
80
|
+
.to_return(status: 200, body: '{"test": "morphology/compound-components"}', headers: {})
|
83
81
|
end
|
84
82
|
it 'test morphology compound components' do
|
85
83
|
params = DocumentParameters.new
|
@@ -91,16 +89,16 @@ describe RosetteAPI do
|
|
91
89
|
|
92
90
|
describe '.get_han_readings' do
|
93
91
|
before do
|
94
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/han-readings')
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
92
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/han-readings')
|
93
|
+
.with(body: @json,
|
94
|
+
headers: { 'Accept' => 'application/json',
|
95
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
96
|
+
'Content-Type' => 'application/json',
|
97
|
+
'User-Agent' => 'Ruby',
|
98
|
+
'X-Rosetteapi-Key' => '0123456789',
|
99
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
100
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
101
|
+
.to_return(status: 200, body: '{"test": "morphology/han-readings"}', headers: {})
|
104
102
|
end
|
105
103
|
it 'test morphology han readings' do
|
106
104
|
params = DocumentParameters.new
|
@@ -112,16 +110,16 @@ describe RosetteAPI do
|
|
112
110
|
|
113
111
|
describe '.get_parts_of_speech' do
|
114
112
|
before do
|
115
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/parts-of-speech')
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
113
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/parts-of-speech')
|
114
|
+
.with(body: @json,
|
115
|
+
headers: { 'Accept' => 'application/json',
|
116
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
117
|
+
'Content-Type' => 'application/json',
|
118
|
+
'User-Agent' => 'Ruby',
|
119
|
+
'X-Rosetteapi-Key' => '0123456789',
|
120
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
121
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
122
|
+
.to_return(status: 200, body: '{"test": "morphology/parts-of-speech"}', headers: {})
|
125
123
|
end
|
126
124
|
it 'test morphology parts of speech' do
|
127
125
|
params = DocumentParameters.new
|
@@ -133,16 +131,16 @@ describe RosetteAPI do
|
|
133
131
|
|
134
132
|
describe '.get_lemmas' do
|
135
133
|
before do
|
136
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/lemmas')
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
134
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/lemmas')
|
135
|
+
.with(body: @json,
|
136
|
+
headers: { 'Accept' => 'application/json',
|
137
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
138
|
+
'Content-Type' => 'application/json',
|
139
|
+
'User-Agent' => 'Ruby',
|
140
|
+
'X-Rosetteapi-Key' => '0123456789',
|
141
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
142
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
143
|
+
.to_return(status: 200, body: '{"test": "morphology/lemmas"}', headers: {})
|
146
144
|
end
|
147
145
|
it 'test morphology lemmas' do
|
148
146
|
params = DocumentParameters.new
|
@@ -154,16 +152,16 @@ describe RosetteAPI do
|
|
154
152
|
|
155
153
|
describe '.get_entities' do
|
156
154
|
before do
|
157
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/entities')
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
155
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/entities')
|
156
|
+
.with(body: @json,
|
157
|
+
headers: { 'Accept' => 'application/json',
|
158
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
159
|
+
'Content-Type' => 'application/json',
|
160
|
+
'User-Agent' => 'Ruby',
|
161
|
+
'X-Rosetteapi-Key' => '0123456789',
|
162
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
163
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
164
|
+
.to_return(status: 200, body: '{"test": "entities"}', headers: {})
|
167
165
|
end
|
168
166
|
it 'test entities' do
|
169
167
|
params = DocumentParameters.new
|
@@ -175,17 +173,17 @@ describe RosetteAPI do
|
|
175
173
|
|
176
174
|
describe '.get_entities_no_qids' do
|
177
175
|
before do
|
178
|
-
no_qids_json = {:
|
179
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/entities')
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
176
|
+
no_qids_json = { content: 'Sample Content', options: { linkEntities: false } }.to_json
|
177
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/entities')
|
178
|
+
.with(body: no_qids_json,
|
179
|
+
headers: { 'Accept' => 'application/json',
|
180
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
181
|
+
'Content-Type' => 'application/json',
|
182
|
+
'User-Agent' => 'Ruby',
|
183
|
+
'X-Rosetteapi-Key' => '0123456789',
|
184
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
185
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
186
|
+
.to_return(status: 200, body: '{"test": "entities"}', headers: {})
|
189
187
|
end
|
190
188
|
it 'test entities without qids' do
|
191
189
|
params = DocumentParameters.new
|
@@ -206,21 +204,21 @@ describe RosetteAPI do
|
|
206
204
|
|
207
205
|
describe '.get_categories' do
|
208
206
|
before do
|
209
|
-
categories_json = {:
|
210
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/categories')
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
207
|
+
categories_json = { contentUri: 'http://google.com' }.to_json
|
208
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/categories')
|
209
|
+
.with(body: categories_json,
|
210
|
+
headers: { 'Accept' => 'application/json',
|
211
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
212
|
+
'Content-Type' => 'application/json',
|
213
|
+
'User-Agent' => 'Ruby',
|
214
|
+
'X-Rosetteapi-Key' => '0123456789',
|
215
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
216
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
217
|
+
.to_return(status: 200, body: '{"test": "categories"}', headers: {})
|
220
218
|
end
|
221
219
|
it 'test categories' do
|
222
220
|
params = DocumentParameters.new
|
223
|
-
params.content_uri =
|
221
|
+
params.content_uri = 'http://google.com'
|
224
222
|
response = RosetteAPI.new('0123456789').get_categories(params)
|
225
223
|
expect(response).instance_of? Hash
|
226
224
|
end
|
@@ -228,16 +226,16 @@ describe RosetteAPI do
|
|
228
226
|
|
229
227
|
describe '.get_relationships' do
|
230
228
|
before do
|
231
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/relationships')
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
229
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/relationships')
|
230
|
+
.with(body: @json,
|
231
|
+
headers: { 'Accept' => 'application/json',
|
232
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
233
|
+
'Content-Type' => 'application/json',
|
234
|
+
'User-Agent' => 'Ruby',
|
235
|
+
'X-Rosetteapi-Key' => '0123456789',
|
236
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
237
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
238
|
+
.to_return(status: 200, body: '{"test": "relationships"}', headers: {})
|
241
239
|
end
|
242
240
|
it 'test relationships' do
|
243
241
|
params = DocumentParameters.new
|
@@ -249,79 +247,179 @@ describe RosetteAPI do
|
|
249
247
|
|
250
248
|
describe '.name_translation' do
|
251
249
|
before do
|
252
|
-
name_translation_json = {:
|
253
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/name-translation')
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
to_return(:
|
250
|
+
name_translation_json = { name: 'معمر محمد أبو منيار القذاف', targetLanguage: 'eng', targetScript: 'Latn' }.to_json
|
251
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/name-translation')
|
252
|
+
.with(body: name_translation_json,
|
253
|
+
headers: { 'Accept' => 'application/json',
|
254
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
255
|
+
'Content-Type' => 'application/json',
|
256
|
+
'User-Agent' => 'Ruby',
|
257
|
+
'X-Rosetteapi-Key' => '0123456789',
|
258
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
259
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
260
|
+
.to_return(status: 200, body: '{"test": "name-translation"}', headers: {})
|
263
261
|
end
|
264
262
|
it 'test name translation' do
|
265
263
|
params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng')
|
266
264
|
params.target_script = 'Latn'
|
267
|
-
response = RosetteAPI.new('0123456789').
|
265
|
+
response = RosetteAPI.new('0123456789').get_name_translation(params)
|
268
266
|
expect(response).instance_of? Hash
|
269
267
|
end
|
270
268
|
|
271
|
-
it 'badRequest: Expects
|
269
|
+
it 'badRequest: Expects NameTranslationParameters type as an argument' do
|
272
270
|
params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊')
|
273
|
-
expect { RosetteAPI.new('0123456789').
|
271
|
+
expect { RosetteAPI.new('0123456789').get_name_translation(params) }.to raise_error(BadRequestError)
|
274
272
|
end
|
275
273
|
end
|
276
274
|
|
277
275
|
describe '.name_similarity' do
|
278
276
|
before do
|
279
|
-
name_similarity_json = {:
|
280
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity')
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
277
|
+
name_similarity_json = { name1: 'Michael Jackson', name2: '迈克尔·杰克逊' }.to_json
|
278
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity')
|
279
|
+
.with(body: name_similarity_json,
|
280
|
+
headers: { 'Accept' => 'application/json',
|
281
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
282
|
+
'Content-Type' => 'application/json',
|
283
|
+
'User-Agent' => 'Ruby',
|
284
|
+
'X-Rosetteapi-Key' => '0123456789',
|
285
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
286
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
287
|
+
.to_return(status: 200, body: '{"test": "name-similarity"}', headers: {})
|
290
288
|
end
|
291
289
|
it 'test name similarity' do
|
292
290
|
params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊')
|
293
|
-
response = RosetteAPI.new('0123456789').
|
291
|
+
response = RosetteAPI.new('0123456789').get_name_similarity(params)
|
294
292
|
expect(response).instance_of? Hash
|
295
293
|
end
|
296
294
|
|
297
295
|
it 'badRequestFormat: name1 option can only be an instance of a String or NameParameter' do
|
298
296
|
params = NameSimilarityParameters.new(123, 'Michael Jackson')
|
299
|
-
expect { RosetteAPI.new('0123456789').
|
297
|
+
expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError)
|
300
298
|
end
|
301
299
|
|
302
300
|
it 'badRequestFormat: name2 option can only be an instance of a String or NameParameter' do
|
303
301
|
params = NameSimilarityParameters.new('Michael Jackson', 123)
|
304
|
-
expect { RosetteAPI.new('0123456789').
|
302
|
+
expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError)
|
305
303
|
end
|
306
304
|
|
307
305
|
it 'badRequest: Expects NameSimilarityParameters type as an argument' do
|
308
306
|
params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng')
|
309
|
-
expect { RosetteAPI.new('0123456789').
|
307
|
+
expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
describe '.name_deduplication' do
|
312
|
+
names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| NameParameter.new(n) }
|
313
|
+
before do
|
314
|
+
names_json = { names: names.map(&:load_param), threshold: 0.75 }.to_json
|
315
|
+
|
316
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/name-deduplication')
|
317
|
+
.with(body: names_json,
|
318
|
+
headers: {'Accept' => 'application/json',
|
319
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
320
|
+
'Content-Type' => 'application/json',
|
321
|
+
'User-Agent' => 'Ruby',
|
322
|
+
'X-Rosetteapi-Key' => '0123456789',
|
323
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
324
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
325
|
+
.to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {})
|
326
|
+
|
327
|
+
nothresh_json = { names: names.map(&:load_param) }.to_json
|
328
|
+
|
329
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/name-deduplication')
|
330
|
+
.with(body: nothresh_json,
|
331
|
+
headers: {'Accept' => 'application/json',
|
332
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
333
|
+
'Content-Type' => 'application/json',
|
334
|
+
'User-Agent' => 'Ruby',
|
335
|
+
'X-Rosetteapi-Key' => '0123456789',
|
336
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
337
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
338
|
+
.to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {})
|
339
|
+
end
|
340
|
+
it 'test name deduplication' do
|
341
|
+
params = NameDeduplicationParameters.new(names, 0.75)
|
342
|
+
response = RosetteAPI.new('0123456789').get_name_deduplication(params)
|
343
|
+
expect(response).instance_of? Hash
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'test null threshold' do
|
347
|
+
params = NameDeduplicationParameters.new(names, nil)
|
348
|
+
response = RosetteAPI.new('0123456789').get_name_deduplication(params)
|
349
|
+
expect(response).instance_of? Hash
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'badRequestFormat: names must be an array of name_parameter' do
|
353
|
+
params = NameDeduplicationParameters.new('Michael Jackson', 0.75)
|
354
|
+
expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError)
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'badRequestFormat: threshold must be a float' do
|
358
|
+
params = NameDeduplicationParameters.new(names, 123)
|
359
|
+
expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError)
|
360
|
+
end
|
361
|
+
|
362
|
+
it 'badRequest: threshold must be in the range of 0 to 1' do
|
363
|
+
params = NameDeduplicationParameters.new(names, 1.5)
|
364
|
+
expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError)
|
365
|
+
end
|
366
|
+
|
367
|
+
it 'badRequest: rosette_options can only be an instance of a Hash' do
|
368
|
+
params = NameDeduplicationParameters.new(names, 0.5)
|
369
|
+
params.rosette_options = 1
|
370
|
+
expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
describe '.transliteration' do
|
375
|
+
content = 'Kareem Abdul Jabbar holds the record for most points in the NBA'
|
376
|
+
|
377
|
+
before do
|
378
|
+
transliteration_json = { content: content }.to_json
|
379
|
+
|
380
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/transliteration')
|
381
|
+
.with(body: transliteration_json,
|
382
|
+
headers: {'Accept' => 'application/json',
|
383
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
384
|
+
'Content-Type' => 'application/json',
|
385
|
+
'User-Agent' => 'Ruby',
|
386
|
+
'X-Rosetteapi-Key' => '0123456789',
|
387
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
388
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
389
|
+
.to_return(status: 200, body: '{"test": "transliteration"}', headers: {})
|
390
|
+
end
|
391
|
+
it 'test transliteration' do
|
392
|
+
params = DocumentParameters.new
|
393
|
+
params.content = content
|
394
|
+
response = RosetteAPI.new('0123456789').get_transliteration(params)
|
395
|
+
expect(response).instance_of? Hash
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'badRequest: content must be provided' do
|
399
|
+
params = DocumentParameters.new
|
400
|
+
expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestFormatError)
|
401
|
+
end
|
402
|
+
|
403
|
+
it 'badRequest: rosette_options can only be an instance of a Hash' do
|
404
|
+
params = DocumentParameters.new
|
405
|
+
params.content = content
|
406
|
+
params.rosette_options = 1
|
407
|
+
expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError)
|
310
408
|
end
|
311
409
|
end
|
312
410
|
|
313
411
|
describe '.get_tokens' do
|
314
412
|
before do
|
315
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/tokens')
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
413
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/tokens')
|
414
|
+
.with(body: @json,
|
415
|
+
headers: { 'Accept' => 'application/json',
|
416
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
417
|
+
'Content-Type' => 'application/json',
|
418
|
+
'User-Agent' => 'Ruby',
|
419
|
+
'X-Rosetteapi-Key' => '0123456789',
|
420
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
421
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
422
|
+
.to_return(status: 200, body: '{"test": "tokens"}', headers: {})
|
325
423
|
end
|
326
424
|
it 'test tokens' do
|
327
425
|
params = DocumentParameters.new
|
@@ -333,16 +431,16 @@ describe RosetteAPI do
|
|
333
431
|
|
334
432
|
describe '.get_sentences' do
|
335
433
|
before do
|
336
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/sentences')
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
434
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/sentences')
|
435
|
+
.with(body: @json,
|
436
|
+
headers: { 'Accept' => 'application/json',
|
437
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
438
|
+
'Content-Type' => 'application/json',
|
439
|
+
'User-Agent' => 'Ruby',
|
440
|
+
'X-Rosetteapi-Key' => '0123456789',
|
441
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
442
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
443
|
+
.to_return(status: 200, body: '{"test": "sentences"}', headers: {})
|
346
444
|
end
|
347
445
|
it 'test sentences' do
|
348
446
|
params = DocumentParameters.new
|
@@ -354,12 +452,12 @@ describe RosetteAPI do
|
|
354
452
|
|
355
453
|
describe '.info' do
|
356
454
|
before do
|
357
|
-
stub_request(:get, 'https://api.rosette.com/rest/v1/info')
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
455
|
+
stub_request(:get, 'https://api.rosette.com/rest/v1/info')
|
456
|
+
.with(headers: { 'Accept' => '*/*',
|
457
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
458
|
+
'User-Agent' => 'Ruby',
|
459
|
+
'X-Rosetteapi-Key' => '0123456789' })
|
460
|
+
.to_return(status: 200, body: '{"test": "info"}', headers: {})
|
363
461
|
end
|
364
462
|
it 'test info' do
|
365
463
|
response = RosetteAPI.new('0123456789').info
|
@@ -369,12 +467,12 @@ describe RosetteAPI do
|
|
369
467
|
|
370
468
|
describe '.ping' do
|
371
469
|
before do
|
372
|
-
stub_request(:get, 'https://api.rosette.com/rest/v1/ping')
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
470
|
+
stub_request(:get, 'https://api.rosette.com/rest/v1/ping')
|
471
|
+
.with(headers: { 'Accept' => '*/*',
|
472
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
473
|
+
'User-Agent' => 'Ruby',
|
474
|
+
'X-Rosetteapi-Key' => '0123456789' })
|
475
|
+
.to_return(status: 200, body: '{"test": "ping"}', headers: {})
|
378
476
|
end
|
379
477
|
it 'test ping' do
|
380
478
|
response = RosetteAPI.new('0123456789').ping
|
@@ -384,35 +482,35 @@ describe RosetteAPI do
|
|
384
482
|
|
385
483
|
describe '.get_language_custom_header' do
|
386
484
|
before do
|
387
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/language')
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
485
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/language')
|
486
|
+
.with(body: @json,
|
487
|
+
headers: { 'Accept' => 'application/json',
|
488
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
489
|
+
'Content-Type' => 'application/json',
|
490
|
+
'User-Agent' => 'Ruby',
|
491
|
+
'X-Rosetteapi-Key' => '0123456789',
|
492
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
493
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0',
|
494
|
+
'X-RosetteApi-App' => 'ruby-app' })
|
495
|
+
.to_return(status: 200, body: '{"test": "language"}', headers: {})
|
398
496
|
end
|
399
497
|
|
400
498
|
it 'test custom_headers is invalid' do
|
401
499
|
params = DocumentParameters.new
|
402
500
|
params.content = 'Por favor Senorita, says the man.?'
|
403
|
-
params.custom_headers = {
|
501
|
+
params.custom_headers = {'test' => 'ruby-app'}
|
404
502
|
expect { RosetteAPI.new('0123456789').get_language(params) }.to raise_error(RosetteAPIError)
|
405
503
|
end
|
406
504
|
end
|
407
505
|
|
408
506
|
describe '.error_409_incompatible_client_version' do
|
409
507
|
before do
|
410
|
-
stub_request(:get, 'https://api.rosette.com/rest/v1/info')
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
508
|
+
stub_request(:get, 'https://api.rosette.com/rest/v1/info')
|
509
|
+
.with(headers: { 'Accept' => '*/*',
|
510
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
511
|
+
'User-Agent' => 'Ruby',
|
512
|
+
'X-Rosetteapi-Key' => '0123456789' })
|
513
|
+
.to_return(status: 409, body: '{"code": "incompatibleClientVersion"}', headers: {})
|
416
514
|
end
|
417
515
|
it 'test error 409 properly handled' do
|
418
516
|
expect { RosetteAPI.new('0123456789').info }.to raise_error(RosetteAPIError)
|
@@ -421,16 +519,16 @@ describe RosetteAPI do
|
|
421
519
|
|
422
520
|
describe '.get_text_embedding' do
|
423
521
|
before do
|
424
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/text-embedding')
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
522
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/text-embedding')
|
523
|
+
.with(body: @json,
|
524
|
+
headers: { 'Accept' => 'application/json',
|
525
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
526
|
+
'Content-Type' => 'application/json',
|
527
|
+
'User-Agent' => 'Ruby',
|
528
|
+
'X-Rosetteapi-Key' => '0123456789',
|
529
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
530
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
531
|
+
.to_return(status: 200, body: '{"test": "language"}', headers: {})
|
434
532
|
end
|
435
533
|
it 'test text_embedding' do
|
436
534
|
params = DocumentParameters.new
|
@@ -442,16 +540,16 @@ describe RosetteAPI do
|
|
442
540
|
|
443
541
|
describe '.get_syntax_dependencies' do
|
444
542
|
before do
|
445
|
-
stub_request(:post, 'https://api.rosette.com/rest/v1/syntax/dependencies')
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
543
|
+
stub_request(:post, 'https://api.rosette.com/rest/v1/syntax/dependencies')
|
544
|
+
.with(body: @json,
|
545
|
+
headers: { 'Accept' => 'application/json',
|
546
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
547
|
+
'Content-Type' => 'application/json',
|
548
|
+
'User-Agent' => 'Ruby',
|
549
|
+
'X-Rosetteapi-Key' => '0123456789',
|
550
|
+
'X-Rosetteapi-Binding' => 'ruby',
|
551
|
+
'X-Rosetteapi-Binding-Version' => '1.7.0' })
|
552
|
+
.to_return(status: 200, body: '{"test": "language"}', headers: {})
|
455
553
|
end
|
456
554
|
it 'test syntax_dependencies' do
|
457
555
|
params = DocumentParameters.new
|
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.7.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:
|
11
|
+
date: 2017-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubysl-securerandom
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/bad_request_error.rb
|
36
36
|
- lib/bad_request_format_error.rb
|
37
37
|
- lib/document_parameters.rb
|
38
|
+
- lib/name_deduplication_parameters.rb
|
38
39
|
- lib/name_parameter.rb
|
39
40
|
- lib/name_similarity_parameters.rb
|
40
41
|
- lib/name_translation_parameters.rb
|
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
63
|
version: '0'
|
63
64
|
requirements: []
|
64
65
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.6.
|
66
|
+
rubygems_version: 2.6.12
|
66
67
|
signing_key:
|
67
68
|
specification_version: 2
|
68
69
|
summary: Rosette API gem that supports multilingual text-analytics.
|