rosette_api 1.5.0 → 1.7.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: 518dc7208214566ddaeb979cba5bb276c7f05558
4
- data.tar.gz: 840bcfdfe10f7de5fab352ab164d8c94fa36f325
3
+ metadata.gz: cd2e11be02e9d5b53eb5e70f2878713438155663
4
+ data.tar.gz: 255a67fd51abe249733fc8713bba8f642cfd770a
5
5
  SHA512:
6
- metadata.gz: d6a861e66e8893f501759c33099098e03e4ab8438f37c3780c36d2304af0afb6823c58fcde40b8e59416ceaed4ce190362efb1fbfaa3bc390a8748b4365c3cd8
7
- data.tar.gz: 083ec97fa03d5c621c197e132247d6caed164b22a7628aa20d53add57daa9eebe2fa0b11d6f3b017823c6583f396ff0b9afbba5187fad939be35411323712960
6
+ metadata.gz: 3646013573953385758c5c87bcb92e92ab5d4215f68d34d69a3ef085b6e13ed270c9a04c16961ee694048e75d53fc1a4195477731ea1ded724900f910def4acb
7
+ data.tar.gz: 666aa84265d7adcd15440e875fd6582d3a24536cb0456f845bcf7ace86b04c6f01b26dd319fbaf5b18a79bb8735be753672bcb836aee46eb43df1f4c189e9a78
@@ -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 !@rosette_options.nil?
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| !value.nil? }
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
@@ -25,9 +25,9 @@ class NameParameter
25
25
  #
26
26
  # Returns the new Hash.
27
27
  def load_param
28
- self.to_hash.select { |_key, value| !value.nil? }
29
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
30
- .to_h
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
- raise BadRequestError.new('name1 option can only be an instance of a String or NameParameter')
32
- elsif [String, NameParameter].none? { |clazz| @name2.is_a? clazz }
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
- self.validate_params
44
- self.to_hash.select { |_key, value| !value.nil? }
45
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
46
- .to_h
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 !@rosette_options.nil?
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
- self.validate_params
62
- self.to_hash.select { |_key, value| !value.nil? }
63
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
64
- .to_h
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.
@@ -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
- if params['customHeaders']
50
- keys_array = params['customHeaders'].keys
51
- for k in keys_array
52
- if k.to_s =~ /^X-RosetteAPI-/
53
- request[k] = params['customHeaders'][k]
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
- raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"'
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
- if params['customHeaders'] != nil
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
- raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"'
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.5.0'
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 name_translation(params)
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 name_similarity(params)
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
- config.before(:example) { @content = 'Sample Content' }
11
- config.before(:example) { @json = {:content => "Sample Content"}.to_json }
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
- 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.5.0'}).
25
- to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {})
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
- with(:body => @json,
54
- headers: {'Accept' => 'application/json',
55
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
56
- 'Content-Type' => 'application/json',
57
- 'User-Agent' => 'Ruby',
58
- 'X-Rosetteapi-Key' => '0123456789',
59
- 'X-Rosetteapi-Binding' => 'ruby',
60
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
61
- to_return(:status => 200, :body => "{\"test\": \"morphology/complete\"}", :headers => {})
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
- with(:body => @json,
75
- headers: {'Accept' => 'application/json',
76
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
77
- 'Content-Type' => 'application/json',
78
- 'User-Agent' => 'Ruby',
79
- 'X-Rosetteapi-Key' => '0123456789',
80
- 'X-Rosetteapi-Binding' => 'ruby',
81
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
82
- to_return(:status => 200, :body => "{\"test\": \"morphology/compound-components\"}", :headers => {})
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
- with(:body => @json,
96
- headers: {'Accept' => 'application/json',
97
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
98
- 'Content-Type' => 'application/json',
99
- 'User-Agent' => 'Ruby',
100
- 'X-Rosetteapi-Key' => '0123456789',
101
- 'X-Rosetteapi-Binding' => 'ruby',
102
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
103
- to_return(:status => 200, :body => "{\"test\": \"morphology/han-readings\"}", :headers => {})
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
- with(:body => @json,
117
- headers: {'Accept' => 'application/json',
118
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
119
- 'Content-Type' => 'application/json',
120
- 'User-Agent' => 'Ruby',
121
- 'X-Rosetteapi-Key' => '0123456789',
122
- 'X-Rosetteapi-Binding' => 'ruby',
123
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
124
- to_return(:status => 200, :body => "{\"test\": \"morphology/parts-of-speech\"}", :headers => {})
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
- with(:body => @json,
138
- headers: {'Accept' => 'application/json',
139
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
140
- 'Content-Type' => 'application/json',
141
- 'User-Agent' => 'Ruby',
142
- 'X-Rosetteapi-Key' => '0123456789',
143
- 'X-Rosetteapi-Binding' => 'ruby',
144
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
145
- to_return(:status => 200, :body => "{\"test\": \"morphology/lemmas\"}", :headers => {})
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
- with(:body => @json,
159
- headers: {'Accept' => 'application/json',
160
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
161
- 'Content-Type' => 'application/json',
162
- 'User-Agent' => 'Ruby',
163
- 'X-Rosetteapi-Key' => '0123456789',
164
- 'X-Rosetteapi-Binding' => 'ruby',
165
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
166
- to_return(:status => 200, :body => "{\"test\": \"entities\"}", :headers => {})
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 = {:content => "Sample Content", :options => {:linkEntities => false}}.to_json
179
- stub_request(:post, 'https://api.rosette.com/rest/v1/entities').
180
- with(:body => no_qids_json,
181
- headers: {'Accept' => 'application/json',
182
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
183
- 'Content-Type' => 'application/json',
184
- 'User-Agent' => 'Ruby',
185
- 'X-Rosetteapi-Key' => '0123456789',
186
- 'X-Rosetteapi-Binding' => 'ruby',
187
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
188
- to_return(:status => 200, :body => "{\"test\": \"entities\"}", :headers => {})
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 = {:contentUri => "http://google.com"}.to_json
210
- stub_request(:post, 'https://api.rosette.com/rest/v1/categories').
211
- with(:body => categories_json,
212
- headers: {'Accept' => 'application/json',
213
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
214
- 'Content-Type' => 'application/json',
215
- 'User-Agent' => 'Ruby',
216
- 'X-Rosetteapi-Key' => '0123456789',
217
- 'X-Rosetteapi-Binding' => 'ruby',
218
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
219
- to_return(:status => 200, :body => "{\"test\": \"categories\"}", :headers => {})
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 = "http://google.com"
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
- with(:body => @json,
233
- headers: {'Accept' => 'application/json',
234
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
235
- 'Content-Type' => 'application/json',
236
- 'User-Agent' => 'Ruby',
237
- 'X-Rosetteapi-Key' => '0123456789',
238
- 'X-Rosetteapi-Binding' => 'ruby',
239
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
240
- to_return(:status => 200, :body => "{\"test\": \"relationships\"}", :headers => {})
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 = {:name => "معمر محمد أبو منيار القذاف", :targetLanguage => "eng", :targetScript => "Latn"}.to_json
253
- stub_request(:post, 'https://api.rosette.com/rest/v1/name-translation').
254
- with(:body => name_translation_json,
255
- headers: {'Accept' => 'application/json',
256
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
257
- 'Content-Type' => 'application/json',
258
- 'User-Agent' => 'Ruby',
259
- 'X-Rosetteapi-Key' => '0123456789',
260
- 'X-Rosetteapi-Binding' => 'ruby',
261
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
262
- to_return(:status => 200, :body => "{\"test\": \"name-translation\"}", :headers => {})
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').name_translation(params)
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 NameTransaltionParameters type as an argument' do
269
+ it 'badRequest: Expects NameTranslationParameters type as an argument' do
272
270
  params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊')
273
- expect { RosetteAPI.new('0123456789').name_translation(params) }.to raise_error(BadRequestError)
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 = {:name1 => "Michael Jackson", :name2 => "迈克尔·杰克逊"}.to_json
280
- stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity').
281
- with(:body => name_similarity_json,
282
- headers: {'Accept' => 'application/json',
283
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
284
- 'Content-Type' => 'application/json',
285
- 'User-Agent' => 'Ruby',
286
- 'X-Rosetteapi-Key' => '0123456789',
287
- 'X-Rosetteapi-Binding' => 'ruby',
288
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
289
- to_return(:status => 200, :body => "{\"test\": \"name-similarity\"}", :headers => {})
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').name_similarity(params)
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').name_similarity(params) }.to raise_error(BadRequestError)
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').name_similarity(params) }.to raise_error(BadRequestError)
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').name_similarity(params) }.to raise_error(BadRequestError)
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
- with(:body => @json,
317
- headers: {'Accept' => 'application/json',
318
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
319
- 'Content-Type' => 'application/json',
320
- 'User-Agent' => 'Ruby',
321
- 'X-Rosetteapi-Key' => '0123456789',
322
- 'X-Rosetteapi-Binding' => 'ruby',
323
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
324
- to_return(:status => 200, :body => "{\"test\": \"tokens\"}", :headers => {})
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
- with(:body => @json,
338
- headers: {'Accept' => 'application/json',
339
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
340
- 'Content-Type' => 'application/json',
341
- 'User-Agent' => 'Ruby',
342
- 'X-Rosetteapi-Key' => '0123456789',
343
- 'X-Rosetteapi-Binding' => 'ruby',
344
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
345
- to_return(:status => 200, :body => "{\"test\": \"sentences\"}", :headers => {})
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
- with(headers: {'Accept' => '*/*',
359
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
360
- 'User-Agent' => 'Ruby',
361
- 'X-Rosetteapi-Key' => '0123456789'}).
362
- to_return(:status => 200, :body => "{\"test\": \"info\"}", :headers => {})
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
- with(headers: {'Accept' => '*/*',
374
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
375
- 'User-Agent' => 'Ruby',
376
- 'X-Rosetteapi-Key' => '0123456789'}).
377
- to_return(:status => 200, :body => "{\"test\": \"ping\"}", :headers => {})
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
- with(:body => @json,
389
- headers: {'Accept' => 'application/json',
390
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
391
- 'Content-Type' => 'application/json',
392
- 'User-Agent' => 'Ruby',
393
- 'X-Rosetteapi-Key' => '0123456789',
394
- 'X-Rosetteapi-Binding' => 'ruby',
395
- 'X-Rosetteapi-Binding-Version' => '1.5.0',
396
- 'X-RosetteApi-App' => 'ruby-app'}).
397
- to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {})
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 = {"test" => "ruby-app"}
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
- with(headers: {'Accept' => '*/*',
412
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
413
- 'User-Agent' => 'Ruby',
414
- 'X-Rosetteapi-Key' => '0123456789'}).
415
- to_return(:status => 409, :body => "{\"code\": \"incompatibleClientVersion\"}", :headers => {})
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
- 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.5.0'}).
433
- to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {})
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
- with(:body => @json,
447
- :headers => {'Accept' => 'application/json',
448
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
449
- 'Content-Type' => 'application/json',
450
- 'User-Agent' => 'Ruby',
451
- 'X-Rosetteapi-Key' => '0123456789',
452
- 'X-Rosetteapi-Binding' => 'ruby',
453
- 'X-Rosetteapi-Binding-Version' => '1.5.0'}).
454
- to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {})
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.5.0
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: 2016-12-19 00:00:00.000000000 Z
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.7
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.