From 296df91c2d84ee4b01c940fd6cb3ab21ab66ee1d Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 9 Jan 2017 09:36:46 -0500 Subject: [PATCH 01/17] RCB-488 - Removed social-media from syntax_dependencies example --- examples/syntax_dependencies.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/syntax_dependencies.rb b/examples/syntax_dependencies.rb index 95c36c9..f74ce44 100644 --- a/examples/syntax_dependencies.rb +++ b/examples/syntax_dependencies.rb @@ -10,7 +10,7 @@ syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday." begin - params = DocumentParameters.new(content: syntax_dependencies_data, genre: 'social-media') + params = DocumentParameters.new(content: syntax_dependencies_data) response = rosette_api.get_syntax_dependencies(params) puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error From 429d8e293aa6c690f2aca45070e3190336c86e9b Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 18 Apr 2017 14:29:05 -0400 Subject: [PATCH 02/17] Name Deduplication - Added parameters - Added unit tests - Updated API --- examples/syntax_dependencies.rb | 10 +++--- lib/document_parameters.rb | 4 +-- lib/name_deduplication_parameters.rb | 52 ++++++++++++++++++++++++++++ lib/request_builder.rb | 10 +++--- lib/rosette_api.rb | 20 +++++++++++ tests/tests_spec.rb | 48 ++++++++++++++++++++++++- 6 files changed, 130 insertions(+), 14 deletions(-) create mode 100644 lib/name_deduplication_parameters.rb diff --git a/examples/syntax_dependencies.rb b/examples/syntax_dependencies.rb index f74ce44..4b40327 100644 --- a/examples/syntax_dependencies.rb +++ b/examples/syntax_dependencies.rb @@ -8,11 +8,11 @@ rosette_api = RosetteAPI.new(api_key, url) end -syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday." +syntax_dependencies_data = 'Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday.' begin - params = DocumentParameters.new(content: syntax_dependencies_data) - response = rosette_api.get_syntax_dependencies(params) - puts JSON.pretty_generate(response) + params = DocumentParameters.new(content: syntax_dependencies_data) + response = rosette_api.get_syntax_dependencies(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/lib/document_parameters.rb b/lib/document_parameters.rb index 71fa99a..18123c4 100644 --- a/lib/document_parameters.rb +++ b/lib/document_parameters.rb @@ -47,7 +47,7 @@ def validate_params elsif [@content, @content_uri, @file_path].all?(&:nil?) raise BadRequestFormatError.new 'The format of the request is invalid: no content provided; must' \ ' be one of an attachment, an inline "content" field, or an external "contentUri"' - elsif !@rosette_options.nil? + elsif !@rosette_options raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash end end @@ -57,7 +57,7 @@ def validate_params # Returns the new Hash. def load_params validate_params - to_hash.select { |_key, value| !value.nil? } + to_hash.select { |_key, value| !value } .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } .to_h end diff --git a/lib/name_deduplication_parameters.rb b/lib/name_deduplication_parameters.rb new file mode 100644 index 0000000..bfea3f2 --- /dev/null +++ b/lib/name_deduplication_parameters.rb @@ -0,0 +1,52 @@ +require_relative 'bad_request_error' +require_relative 'name_parameter' + +# This class encapsulates parameters that are needed for name-deduplication in +# Rosette API. +class NameDeduplicationParameters + # Rosette API options (optional, should be a hash) + attr_accessor :rosette_options + # List of Name objects to be de-duplicated + attr_accessor :names + # Threshold for determining cluster size + attr_accessor :threshold + + def initialize(names, threshold, options = {}) #:notnew: + options = { + rosette_options: nil + }.update options + @names = names + @threshold = threshold + @rosette_options = options[:rosette_options] + end + + # Validates the parameters by checking if name1 and name2 are instances of + # a String or NameParameter. + def validate_params + raise BadRequestError.new('names must be an array of name_parameter') unless @names.instance_of? Array + raise BadRequestError.new('threshold must be a float') unless @threshold.is_a?(Float) + raise BadRequestError.new('threshold must be in the range of 0 to 1') if @threshold < 0 || @threshold > 1 + raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash + end + + # Converts this class to Hash with its keys in lower CamelCase. + # + # Returns the new Hash. + def load_params + validate_params + to_hash.select { |_key, value| value } + .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } + .to_h + end + + # Converts this class to Hash. + # + # Returns the new Hash. + def to_hash + { + name1: @names, + name2: @threshold, + options: @rosette_options + } + end +end diff --git a/lib/request_builder.rb b/lib/request_builder.rb index 1735440..799ad48 100644 --- a/lib/request_builder.rb +++ b/lib/request_builder.rb @@ -18,7 +18,6 @@ class RequestBuilder # Rosette API binding version attr_accessor :binding_version - def initialize(user_key, alternate_url, http_client, params = {}, url_parameters = nil, binding_version) @user_key = user_key @alternate_url = alternate_url @@ -28,7 +27,6 @@ def initialize(user_key, alternate_url, http_client, params = {}, url_parameters return unless url_parameters @alternate_url = @alternate_url + '?' + URI.encode_www_form(url_parameters) - end # Prepares a plain POST request for Rosette API. @@ -52,7 +50,7 @@ def prepare_plain_request(params) if k.to_s =~ /^X-RosetteAPI-/ request[k] = params['customHeaders'][k] else - raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"' + raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"' end end params.delete 'customHeaders' @@ -108,15 +106,15 @@ def prepare_multipart_request(params) rescue raise RosetteAPIError.new 'connectionError', 'Failed to establish connection with Rosette API server.' end - + # add any custom headers from the user - if params['customHeaders'] != nil + unless params['customHeaders'].nil? keys_array = params['customHeaders'].keys for k in keys_array if k.to_s =~ /^X-RosetteAPI-/ request.add_field k, params['customHeaders'][k] else - raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"' + raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"' end end params.delete 'customHeaders' diff --git a/lib/rosette_api.rb b/lib/rosette_api.rb index df2627f..e4d500a 100644 --- a/lib/rosette_api.rb +++ b/lib/rosette_api.rb @@ -22,6 +22,8 @@ class RosetteAPI RELATIONSHIPS_ENDPOINT = '/relationships'.freeze # Rosette API sentiment endpoint SENTIMENT_ENDPOINT = '/sentiment'.freeze + # Name Deduplication endpoint + NAME_DEDUPLICATION_ENDPOINT = 'name-deduplication'.freeze # Rosette API name-translation endpoint NAME_TRANSLATION_ENDPOINT = '/name-translation'.freeze # Rosette API name-similarity endpoint @@ -38,6 +40,8 @@ class RosetteAPI TEXT_EMBEDDING = '/text-embedding'.freeze # Syntactic Dependencies endpoint SYNTACTIC_DEPENDENCIES_ENDPOINT = '/syntax/dependencies'.freeze + # Transliteration endpoint + TRANSLITERATION_ENDPOINT = 'transliteration'.freeze # Rosette API key attr_accessor :user_key @@ -228,6 +232,22 @@ def get_sentiment(params) .send_post_request end + # De-duplicates a list of names. + # + # ==== Attributes + # + # * +params+ - NameDeduplicationParameters helps to build the request body in RequestBuilder. + # + # Returns the list of deduplicated names. + def name_deduplication(params) + check_params params, 'Expects a NameDeduplicationParameters type as an argument', NameDeduplicationParameters + + params = params.load_params + + RequestBuilder.new(@user_key, @alternate_url + NAME_DEDUPLICATION_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) + .send_post_request + end + # Translates a given name to a supported specified language. # # ==== Attributes diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index 4ab6629..59bdb07 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -305,11 +305,57 @@ end it 'badRequest: Expects NameSimilarityParameters type as an argument' do - params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng') + params = NameSimilarityParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng') expect { RosetteAPI.new('0123456789').name_similarity(params) }.to raise_error(BadRequestError) end end + describe '.name_deduplication' do + before do + names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } + + stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity') + .with(body: names.to_json, + headers: {'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"name-deduplication\"}', headers: {}) + end + it 'test name deduplication' do + names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } + params = NameDeduplicationParameters.new(names, 0.75) + response = RosetteAPI.new('0123456789').name_deduplication(params) + expect(response).instance_of? Hash + end + + it 'badRequestFormat: names must be an array of name_parameter' do + params = NameDeduplicationParameters.new('Michael Jackson', 0.75) + expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) + end + + it 'badRequestFormat: threshold must be a float' do + names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } + params = NameDeduplicationParameters.new(names, 123) + expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) + end + + it 'badRequest: threshold must be in the range of 0 to 1' do + names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } + params = NameDeduplicationParameters.new(names, 1.5) + expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) + end + + it 'badRequest: rosette_options can only be an instance of a Hash' do + names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } + params = NameDeduplicationParameters.new(names, 0.5, 'options') + expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) + end + end + describe '.get_tokens' do before do stub_request(:post, 'https://api.rosette.com/rest/v1/tokens'). From 4fcf55426b619065fc4199c4cd51f161b1cdedba Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 18 Apr 2017 14:58:39 -0400 Subject: [PATCH 03/17] Code cleanup - tests_spec.rb --- tests/tests_spec.rb | 398 ++++++++++++++++++++++---------------------- 1 file changed, 198 insertions(+), 200 deletions(-) diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index 59bdb07..2b9322c 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -7,22 +7,22 @@ describe RosetteAPI do RSpec.configure do |config| - config.before(:example) { @content = 'Sample Content' } - config.before(:example) { @json = {:content => "Sample Content"}.to_json } + config.before(:example) { @content = 'Sample Content' } + config.before(:example) { @json = {content: 'Sample Content'}.to_json } end describe '.get_language' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/language'). - with(:body => @json, - :headers => {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/language') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"language\"}', headers: {}) end it 'test language' do params = DocumentParameters.new @@ -40,25 +40,23 @@ it 'badRequestFormat: the format of the request is invalid: no content provided;' do params = DocumentParameters.new - expect { RosetteAPI.new('0123456789') - .get_language(params) } - .to raise_error(BadRequestFormatError) + expect { RosetteAPI.new('0123456789').get_language(params) }.to raise_error(BadRequestFormatError) end end describe '.get_morphology_complete' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/complete'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"morphology/complete\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/complete') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"morphology/complete\"}', headers: {}) end it 'test morphology complete' do params = DocumentParameters.new @@ -70,16 +68,16 @@ describe '.get_compound_components' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/compound-components'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"morphology/compound-components\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/compound-components') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"morphology/compound-components\"}', headers: {}) end it 'test morphology compound components' do params = DocumentParameters.new @@ -91,16 +89,16 @@ describe '.get_han_readings' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/han-readings'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"morphology/han-readings\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/han-readings') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"morphology/han-readings\"}', headers: {}) end it 'test morphology han readings' do params = DocumentParameters.new @@ -112,16 +110,16 @@ describe '.get_parts_of_speech' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/parts-of-speech'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"morphology/parts-of-speech\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/parts-of-speech') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"morphology/parts-of-speech\"}', headers: {}) end it 'test morphology parts of speech' do params = DocumentParameters.new @@ -133,16 +131,16 @@ describe '.get_lemmas' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/lemmas'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"morphology/lemmas\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/lemmas') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"morphology/lemmas\"}', headers: {}) end it 'test morphology lemmas' do params = DocumentParameters.new @@ -154,16 +152,16 @@ describe '.get_entities' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/entities'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"entities\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/entities') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"entities\"}', headers: {}) end it 'test entities' do params = DocumentParameters.new @@ -175,17 +173,17 @@ describe '.get_entities_no_qids' do before do - no_qids_json = {:content => "Sample Content", :options => {:linkEntities => false}}.to_json - stub_request(:post, 'https://api.rosette.com/rest/v1/entities'). - with(:body => no_qids_json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"entities\"}", :headers => {}) + no_qids_json = { content: 'Sample Content', options: { linkEntities: false } }.to_json + stub_request(:post, 'https://api.rosette.com/rest/v1/entities') + .with(body: no_qids_json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"entities\"}', headers: {}) end it 'test entities without qids' do params = DocumentParameters.new @@ -206,21 +204,21 @@ describe '.get_categories' do before do - categories_json = {:contentUri => "http://google.com"}.to_json - stub_request(:post, 'https://api.rosette.com/rest/v1/categories'). - with(:body => categories_json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"categories\"}", :headers => {}) + categories_json = { contentUri: 'http://google.com' }.to_json + stub_request(:post, 'https://api.rosette.com/rest/v1/categories') + .with(body: categories_json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"categories\"}', headers: {}) end it 'test categories' do params = DocumentParameters.new - params.content_uri = "http://google.com" + params.content_uri = 'http://google.com' response = RosetteAPI.new('0123456789').get_categories(params) expect(response).instance_of? Hash end @@ -228,16 +226,16 @@ describe '.get_relationships' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/relationships'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"relationships\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/relationships') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"relationships\"}', headers: {}) end it 'test relationships' do params = DocumentParameters.new @@ -249,17 +247,17 @@ describe '.name_translation' do before do - name_translation_json = {:name => "معمر محمد أبو منيار القذاف", :targetLanguage => "eng", :targetScript => "Latn"}.to_json - stub_request(:post, 'https://api.rosette.com/rest/v1/name-translation'). - with(:body => name_translation_json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"name-translation\"}", :headers => {}) + name_translation_json = { name: 'معمر محمد أبو منيار القذاف', targetLanguage: 'eng', targetScript: 'Latn' }.to_json + stub_request(:post, 'https://api.rosette.com/rest/v1/name-translation') + .with(body: name_translation_json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"name-translation\"}', headers: {}) end it 'test name translation' do params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng') @@ -276,17 +274,17 @@ describe '.name_similarity' do before do - name_similarity_json = {:name1 => "Michael Jackson", :name2 => "迈克尔·杰克逊"}.to_json - stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity'). - with(:body => name_similarity_json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"name-similarity\"}", :headers => {}) + name_similarity_json = { name1: 'Michael Jackson', name2: '迈克尔·杰克逊' }.to_json + stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity') + .with(body: name_similarity_json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"name-similarity\"}', headers: {}) end it 'test name similarity' do params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊') @@ -358,16 +356,16 @@ describe '.get_tokens' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/tokens'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"tokens\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/tokens') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"tokens\"}', header: {}) end it 'test tokens' do params = DocumentParameters.new @@ -379,16 +377,16 @@ describe '.get_sentences' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/sentences'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"sentences\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/sentences') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"sentences\"}', headers: {}) end it 'test sentences' do params = DocumentParameters.new @@ -400,12 +398,12 @@ describe '.info' do before do - stub_request(:get, 'https://api.rosette.com/rest/v1/info'). - with(headers: {'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(:status => 200, :body => "{\"test\": \"info\"}", :headers => {}) + stub_request(:get, 'https://api.rosette.com/rest/v1/info') + .with(headers: { 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789' }) + .to_return(status: 200, body: '{\"test\": \"info\"}', headers: {}) end it 'test info' do response = RosetteAPI.new('0123456789').info @@ -415,12 +413,12 @@ describe '.ping' do before do - stub_request(:get, 'https://api.rosette.com/rest/v1/ping'). - with(headers: {'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(:status => 200, :body => "{\"test\": \"ping\"}", :headers => {}) + stub_request(:get, 'https://api.rosette.com/rest/v1/ping') + .with(headers: { 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789' }) + .to_return(status: 200, body: '{\"test\": \"ping\"}', headers: {}) end it 'test ping' do response = RosetteAPI.new('0123456789').ping @@ -430,35 +428,35 @@ describe '.get_language_custom_header' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/language'). - with(:body => @json, - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0', - 'X-RosetteApi-App' => 'ruby-app'}). - to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/language') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0', + 'X-RosetteApi-App' => 'ruby-app' }) + .to_return(status: 200, body: '{\"test\": \"language\"}', headers: {}) end it 'test custom_headers is invalid' do params = DocumentParameters.new params.content = 'Por favor Senorita, says the man.?' - params.custom_headers = {"test" => "ruby-app"} + params.custom_headers = {'test' => 'ruby-app'} expect { RosetteAPI.new('0123456789').get_language(params) }.to raise_error(RosetteAPIError) end end describe '.error_409_incompatible_client_version' do before do - stub_request(:get, 'https://api.rosette.com/rest/v1/info'). - with(headers: {'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(:status => 409, :body => "{\"code\": \"incompatibleClientVersion\"}", :headers => {}) + stub_request(:get, 'https://api.rosette.com/rest/v1/info') + .with(headers: { 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789' }) + .to_return(status: 409, body: '{\"code\": \"incompatibleClientVersion\"}', headers: {}) end it 'test error 409 properly handled' do expect { RosetteAPI.new('0123456789').info }.to raise_error(RosetteAPIError) @@ -467,16 +465,16 @@ describe '.get_text_embedding' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/text-embedding'). - with(:body => @json, - :headers => {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/text-embedding') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"language\"}', headers: {}) end it 'test text_embedding' do params = DocumentParameters.new @@ -488,16 +486,16 @@ describe '.get_syntax_dependencies' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/syntax/dependencies'). - with(:body => @json, - :headers => {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789', - 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0'}). - to_return(:status => 200, :body => "{\"test\": \"language\"}", :headers => {}) + stub_request(:post, 'https://api.rosette.com/rest/v1/syntax/dependencies') + .with(body: @json, + headers: { 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{\"test\": \"language\"}', headers: {}) end it 'test syntax_dependencies' do params = DocumentParameters.new From ed657372cbc067d926f508833116349d4ec3ecbe Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 19 Apr 2017 14:46:33 -0400 Subject: [PATCH 04/17] Name deduplication - Added endpoint - Added parameters - Added unit tests - Added example --- examples/categories.rb | 10 ++--- examples/name_deduplication.rb | 20 ++++++++++ lib/document_parameters.rb | 4 +- lib/name_deduplication_parameters.rb | 10 +++-- lib/name_similarity_parameters.rb | 16 ++++---- lib/name_translation_parameters.rb | 10 ++--- lib/rosette_api.rb | 3 +- tests/tests_spec.rb | 60 ++++++++++++++-------------- 8 files changed, 76 insertions(+), 57 deletions(-) create mode 100644 examples/name_deduplication.rb diff --git a/examples/categories.rb b/examples/categories.rb index 8ec4971..a2e6328 100644 --- a/examples/categories.rb +++ b/examples/categories.rb @@ -8,11 +8,11 @@ rosette_api = RosetteAPI.new(api_key, url) end -categories_url_data = "http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/" +categories_url_data = 'http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/' begin - params = DocumentParameters.new(content_uri: categories_url_data) - response = rosette_api.get_categories(params) - puts JSON.pretty_generate(response) + params = DocumentParameters.new(content_uri: categories_url_data) + response = rosette_api.get_categories(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/name_deduplication.rb b/examples/name_deduplication.rb new file mode 100644 index 0000000..53d7af9 --- /dev/null +++ b/examples/name_deduplication.rb @@ -0,0 +1,20 @@ +require 'rosette_api' + +api_key, url = ARGV + +if !url + rosette_api = RosetteAPI.new(api_key) +else + rosette_api = RosetteAPI.new(api_key, url) +end + +dedup_list = ['John Smith', 'Johnathon Smith', 'Fred Jones'] +threshold = 0.75 +names = dedup_list.map { |n| NameParameter.new(n) } +begin + params = NameDeduplicationParameters.new(names, threshold) + response = rosette_api.name_deduplication(params) + puts JSON.pretty_generate(response) +rescue RosetteAPIError => rosette_api_error + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) +end diff --git a/lib/document_parameters.rb b/lib/document_parameters.rb index 18123c4..edbfd68 100644 --- a/lib/document_parameters.rb +++ b/lib/document_parameters.rb @@ -47,7 +47,7 @@ def validate_params elsif [@content, @content_uri, @file_path].all?(&:nil?) raise BadRequestFormatError.new 'The format of the request is invalid: no content provided; must' \ ' be one of an attachment, an inline "content" field, or an external "contentUri"' - elsif !@rosette_options + elsif @rosette_options raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash end end @@ -57,7 +57,7 @@ def validate_params # Returns the new Hash. def load_params validate_params - to_hash.select { |_key, value| !value } + to_hash.select { |_key, value| value } .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } .to_h end diff --git a/lib/name_deduplication_parameters.rb b/lib/name_deduplication_parameters.rb index bfea3f2..ea1b22f 100644 --- a/lib/name_deduplication_parameters.rb +++ b/lib/name_deduplication_parameters.rb @@ -25,8 +25,10 @@ def initialize(names, threshold, options = {}) #:notnew: def validate_params raise BadRequestError.new('names must be an array of name_parameter') unless @names.instance_of? Array raise BadRequestError.new('threshold must be a float') unless @threshold.is_a?(Float) - raise BadRequestError.new('threshold must be in the range of 0 to 1') if @threshold < 0 || @threshold > 1 - raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash + raise BadRequestError.new('threshold must be in the range of 0 to 1') if @threshold.negative? || @threshold > 1 + if @rosette_options + raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash + end end # Converts this class to Hash with its keys in lower CamelCase. @@ -44,8 +46,8 @@ def load_params # Returns the new Hash. def to_hash { - name1: @names, - name2: @threshold, + names: @names, + threshold: @threshold, options: @rosette_options } end diff --git a/lib/name_similarity_parameters.rb b/lib/name_similarity_parameters.rb index d6c4607..c3e69dd 100644 --- a/lib/name_similarity_parameters.rb +++ b/lib/name_similarity_parameters.rb @@ -27,11 +27,9 @@ def initialize(name1, name2, options = {}) #:notnew: # Validates the parameters by checking if name1 and name2 are instances of # a String or NameParameter. def validate_params - if [String, NameParameter].none? { |clazz| @name1.is_a? clazz } - raise BadRequestError.new('name1 option can only be an instance of a String or NameParameter') - elsif [String, NameParameter].none? { |clazz| @name2.is_a? clazz } - raise BadRequestError.new('name2 option can only be an instance of a String or NameParameter') - elsif !@rosette_options.nil? + raise BadRequestError.new('name1 option can only be an instance of a String or NameParameter') if [String, NameParameter].none? { |clazz| @name1.is_a? clazz } + raise BadRequestError.new('name2 option can only be an instance of a String or NameParameter') if [String, NameParameter].none? { |clazz| @name2.is_a? clazz } + if @rosette_options raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash end end @@ -40,10 +38,10 @@ def validate_params # # Returns the new Hash. def load_params - self.validate_params - self.to_hash.select { |_key, value| !value.nil? } - .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } - .to_h + validate_params + to_hash.reject { |_key, value| value.nil? } + .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } + .to_h end # Converts this class to Hash. diff --git a/lib/name_translation_parameters.rb b/lib/name_translation_parameters.rb index f8135b0..9dc0265 100644 --- a/lib/name_translation_parameters.rb +++ b/lib/name_translation_parameters.rb @@ -49,7 +49,7 @@ def initialize(name, target_language, options = {}) #:notnew: # Validates the parameters by checking if rosette_options is an instance of a Hash. def validate_params - if !@rosette_options.nil? + if @rosette_options raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash end end @@ -58,10 +58,10 @@ def validate_params # # Returns the new Hash. def load_params - self.validate_params - self.to_hash.select { |_key, value| !value.nil? } - .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } - .to_h + validate_params + to_hash.select { |_key, value| value } + .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } + .to_h end # Converts this class to Hash. diff --git a/lib/rosette_api.rb b/lib/rosette_api.rb index e4d500a..81e9d36 100644 --- a/lib/rosette_api.rb +++ b/lib/rosette_api.rb @@ -1,5 +1,6 @@ require_relative 'request_builder' require_relative 'document_parameters' +require_relative 'name_deduplication_parameters' require_relative 'name_translation_parameters' require_relative 'name_similarity_parameters' require_relative 'rosette_api_error' @@ -23,7 +24,7 @@ class RosetteAPI # Rosette API sentiment endpoint SENTIMENT_ENDPOINT = '/sentiment'.freeze # Name Deduplication endpoint - NAME_DEDUPLICATION_ENDPOINT = 'name-deduplication'.freeze + NAME_DEDUPLICATION_ENDPOINT = '/name-deduplication'.freeze # Rosette API name-translation endpoint NAME_TRANSLATION_ENDPOINT = '/name-translation'.freeze # Rosette API name-similarity endpoint diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index 2b9322c..a195de9 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -22,7 +22,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"language\"}', headers: {}) + .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test language' do params = DocumentParameters.new @@ -56,7 +56,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"morphology/complete\"}', headers: {}) + .to_return(status: 200, body: '{"test": "morphology/complete"}', headers: {}) end it 'test morphology complete' do params = DocumentParameters.new @@ -77,7 +77,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"morphology/compound-components\"}', headers: {}) + .to_return(status: 200, body: '{"test": "morphology/compound-components"}', headers: {}) end it 'test morphology compound components' do params = DocumentParameters.new @@ -98,7 +98,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"morphology/han-readings\"}', headers: {}) + .to_return(status: 200, body: '{"test": "morphology/han-readings"}', headers: {}) end it 'test morphology han readings' do params = DocumentParameters.new @@ -119,7 +119,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"morphology/parts-of-speech\"}', headers: {}) + .to_return(status: 200, body: '{"test": "morphology/parts-of-speech"}', headers: {}) end it 'test morphology parts of speech' do params = DocumentParameters.new @@ -140,7 +140,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"morphology/lemmas\"}', headers: {}) + .to_return(status: 200, body: '{"test": "morphology/lemmas"}', headers: {}) end it 'test morphology lemmas' do params = DocumentParameters.new @@ -161,7 +161,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"entities\"}', headers: {}) + .to_return(status: 200, body: '{"test": "entities"}', headers: {}) end it 'test entities' do params = DocumentParameters.new @@ -183,7 +183,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"entities\"}', headers: {}) + .to_return(status: 200, body: '{"test": "entities"}', headers: {}) end it 'test entities without qids' do params = DocumentParameters.new @@ -214,7 +214,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"categories\"}', headers: {}) + .to_return(status: 200, body: '{"test": "categories"}', headers: {}) end it 'test categories' do params = DocumentParameters.new @@ -235,7 +235,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"relationships\"}', headers: {}) + .to_return(status: 200, body: '{"test": "relationships"}', headers: {}) end it 'test relationships' do params = DocumentParameters.new @@ -257,7 +257,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"name-translation\"}', headers: {}) + .to_return(status: 200, body: '{"test": "name-translation"}', headers: {}) end it 'test name translation' do params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng') @@ -266,7 +266,7 @@ expect(response).instance_of? Hash end - it 'badRequest: Expects NameTransaltionParameters type as an argument' do + it 'badRequest: Expects NameTranslationParameters type as an argument' do params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊') expect { RosetteAPI.new('0123456789').name_translation(params) }.to raise_error(BadRequestError) end @@ -284,7 +284,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"name-similarity\"}', headers: {}) + .to_return(status: 200, body: '{"test": "name-similarity"}', headers: {}) end it 'test name similarity' do params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊') @@ -303,17 +303,18 @@ end it 'badRequest: Expects NameSimilarityParameters type as an argument' do - params = NameSimilarityParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng') + params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng') expect { RosetteAPI.new('0123456789').name_similarity(params) }.to raise_error(BadRequestError) end end describe '.name_deduplication' do + names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| NameParameter.new(n) } before do - names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } + names_json = { names: names, threshold: 0.75 }.to_json - stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity') - .with(body: names.to_json, + stub_request(:post, 'https://api.rosette.com/rest/v1/name-deduplication') + .with(body: names_json, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', @@ -321,10 +322,9 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"name-deduplication\"}', headers: {}) + .to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {}) end it 'test name deduplication' do - names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } params = NameDeduplicationParameters.new(names, 0.75) response = RosetteAPI.new('0123456789').name_deduplication(params) expect(response).instance_of? Hash @@ -336,20 +336,18 @@ end it 'badRequestFormat: threshold must be a float' do - names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } params = NameDeduplicationParameters.new(names, 123) expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) end it 'badRequest: threshold must be in the range of 0 to 1' do - names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } params = NameDeduplicationParameters.new(names, 1.5) expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) end it 'badRequest: rosette_options can only be an instance of a Hash' do - names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| new NameParameter(n) } - params = NameDeduplicationParameters.new(names, 0.5, 'options') + params = NameDeduplicationParameters.new(names, 0.5) + params.rosette_options = 1 expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) end end @@ -365,7 +363,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"tokens\"}', header: {}) + .to_return(status: 200, body: '{"test": "tokens"}', headers: {}) end it 'test tokens' do params = DocumentParameters.new @@ -386,7 +384,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"sentences\"}', headers: {}) + .to_return(status: 200, body: '{"test": "sentences"}', headers: {}) end it 'test sentences' do params = DocumentParameters.new @@ -403,7 +401,7 @@ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789' }) - .to_return(status: 200, body: '{\"test\": \"info\"}', headers: {}) + .to_return(status: 200, body: '{"test": "info"}', headers: {}) end it 'test info' do response = RosetteAPI.new('0123456789').info @@ -418,7 +416,7 @@ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789' }) - .to_return(status: 200, body: '{\"test\": \"ping\"}', headers: {}) + .to_return(status: 200, body: '{"test": "ping"}', headers: {}) end it 'test ping' do response = RosetteAPI.new('0123456789').ping @@ -438,7 +436,7 @@ 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0', 'X-RosetteApi-App' => 'ruby-app' }) - .to_return(status: 200, body: '{\"test\": \"language\"}', headers: {}) + .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test custom_headers is invalid' do @@ -456,7 +454,7 @@ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789' }) - .to_return(status: 409, body: '{\"code\": \"incompatibleClientVersion\"}', headers: {}) + .to_return(status: 409, body: '{"code": "incompatibleClientVersion"}', headers: {}) end it 'test error 409 properly handled' do expect { RosetteAPI.new('0123456789').info }.to raise_error(RosetteAPIError) @@ -474,7 +472,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"language\"}', headers: {}) + .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test text_embedding' do params = DocumentParameters.new @@ -495,7 +493,7 @@ 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) - .to_return(status: 200, body: '{\"test\": \"language\"}', headers: {}) + .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test syntax_dependencies' do params = DocumentParameters.new From 1de6b3d2953acfc99932bac1ff40ddd9b3f8c7d0 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 19 Apr 2017 16:30:34 -0400 Subject: [PATCH 05/17] Transliteration - added endpoint - added example - added unit tests - cleaned up examples --- examples/name_similarity.rb | 14 +++---- examples/name_translation.rb | 10 ++--- examples/ping.rb | 6 +-- examples/relationships.rb | 10 ++--- examples/sentences.rb | 10 ++--- examples/sentiment.rb | 10 ++--- examples/text_embedding.rb | 8 ++-- examples/tokens.rb | 10 ++--- examples/transliteration.rb | 26 ++++++++++++ lib/name_parameter.rb | 6 +-- lib/rosette_api.rb | 20 ++++++++- lib/transliteration_parameters.rb | 67 +++++++++++++++++++++++++++++++ tests/tests_spec.rb | 62 ++++++++++++++++++++++++++++ 13 files changed, 216 insertions(+), 43 deletions(-) create mode 100644 examples/transliteration.rb create mode 100644 lib/transliteration_parameters.rb diff --git a/examples/name_similarity.rb b/examples/name_similarity.rb index f776a49..4e18310 100644 --- a/examples/name_similarity.rb +++ b/examples/name_similarity.rb @@ -8,13 +8,13 @@ rosette_api = RosetteAPI.new(api_key, url) end -matched_name_data1 = "Michael Jackson" -matched_name_data2 = "迈克尔·杰克逊" +matched_name_data1 = 'Michael Jackson' +matched_name_data2 = '迈克尔·杰克逊' begin - name1 = NameParameter.new(matched_name_data1, entity_type: 'PERSON', language:'eng') - params = NameSimilarityParameters.new(name1, matched_name_data2) - response = rosette_api.name_similarity(params) - puts JSON.pretty_generate(response) + name1 = NameParameter.new(matched_name_data1, entity_type: 'PERSON', language: 'eng') + params = NameSimilarityParameters.new(name1, matched_name_data2) + response = rosette_api.name_similarity(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/name_translation.rb b/examples/name_translation.rb index b48ba1d..3d19acd 100644 --- a/examples/name_translation.rb +++ b/examples/name_translation.rb @@ -8,11 +8,11 @@ rosette_api = RosetteAPI.new(api_key, url) end -translated_name_data = "معمر محمد أبو منيار القذاف" +translated_name_data = 'معمر محمد أبو منيار القذاف' begin - params = NameTranslationParameters.new(translated_name_data, 'eng', target_script: 'Latn') - response = rosette_api.name_translation(params) - puts JSON.pretty_generate(response) + params = NameTranslationParameters.new(translated_name_data, 'eng', target_script: 'Latn') + response = rosette_api.name_translation(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/ping.rb b/examples/ping.rb index b96bcdc..8c9150c 100644 --- a/examples/ping.rb +++ b/examples/ping.rb @@ -8,8 +8,8 @@ rosette_api = RosetteAPI.new(api_key, url) end begin - response = rosette_api.ping - puts JSON.pretty_generate(response) + response = rosette_api.ping + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/relationships.rb b/examples/relationships.rb index 913a81d..d7b1e0b 100644 --- a/examples/relationships.rb +++ b/examples/relationships.rb @@ -10,10 +10,10 @@ relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist." begin - params = DocumentParameters.new(content: relationships_text_data) - params.rosette_options = { accuracyMode: 'PRECISION' } - response = rosette_api.get_relationships(params) - puts JSON.pretty_generate(response) + params = DocumentParameters.new(content: relationships_text_data) + params.rosette_options = { accuracyMode: 'PRECISION' } + response = rosette_api.get_relationships(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/sentences.rb b/examples/sentences.rb index 86f3734..afdb362 100644 --- a/examples/sentences.rb +++ b/examples/sentences.rb @@ -11,10 +11,10 @@ sentences_data = "This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me." begin - params = DocumentParameters.new - params.content = sentences_data - response = rosette_api.get_sentences(params) - puts JSON.pretty_generate(response) + params = DocumentParameters.new + params.content = sentences_data + response = rosette_api.get_sentences(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/sentiment.rb b/examples/sentiment.rb index b0c6fba..016017a 100644 --- a/examples/sentiment.rb +++ b/examples/sentiment.rb @@ -9,14 +9,14 @@ rosette_api = RosetteAPI.new(api_key, url) end -file = Tempfile.new(%w(foo .html)) +file = Tempfile.new(%w[foo .html]) sentiment_file_data = 'New Ghostbusters Film

Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”

' file.write(sentiment_file_data) file.close begin - params = DocumentParameters.new(file_path: file.path, language: 'eng') - response = rosette_api.get_sentiment(params) - puts JSON.pretty_generate(response) + params = DocumentParameters.new(file_path: file.path, language: 'eng') + response = rosette_api.get_sentiment(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/text_embedding.rb b/examples/text_embedding.rb index 882760a..35e3cc4 100644 --- a/examples/text_embedding.rb +++ b/examples/text_embedding.rb @@ -10,9 +10,9 @@ embeddings_data = 'Cambridge, Massachusetts' begin - params = DocumentParameters.new(content: embeddings_data) - response = rosette_api.get_text_embedding(params) - puts JSON.pretty_generate(response) + params = DocumentParameters.new(content: embeddings_data) + response = rosette_api.get_text_embedding(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/tokens.rb b/examples/tokens.rb index cebf3fc..de53adb 100644 --- a/examples/tokens.rb +++ b/examples/tokens.rb @@ -8,11 +8,11 @@ rosette_api = RosetteAPI.new(api_key, url) end -tokens_data = "北京大学生物系主任办公室内部会议" +tokens_data = '北京大学生物系主任办公室内部会议' begin - params = DocumentParameters.new(content: tokens_data) - response = rosette_api.get_tokens(params) - puts JSON.pretty_generate(response) + params = DocumentParameters.new(content: tokens_data) + response = rosette_api.get_tokens(params) + puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error - printf("Rosette API Error (%s): %s", rosette_api_error.status_code, rosette_api_error.message) + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) end diff --git a/examples/transliteration.rb b/examples/transliteration.rb new file mode 100644 index 0000000..242c94e --- /dev/null +++ b/examples/transliteration.rb @@ -0,0 +1,26 @@ +require 'rosette_api' + +api_key, url = ARGV + +if !url + rosette_api = RosetteAPI.new(api_key) +else + rosette_api = RosetteAPI.new(api_key, url) +end + +transliteration_content_data = 'Kareem Abdul Jabbar holds the records for most points in the NBA' +transliteration_target_language = 'eng' +transliteration_target_script = 'Latn' +transliteration_source_language = 'ara' +transliteration_source_script = 'Latn' +begin + params = TransliterationParameters.new(transliteration_content_data, + transliteration_target_language, + transliteration_target_script, + transliteration_source_language, + transliteration_source_script) + response = rosette_api.transliteration(params) + puts JSON.pretty_generate(response) +rescue RosetteAPIError => rosette_api_error + printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) +end diff --git a/lib/name_parameter.rb b/lib/name_parameter.rb index a67b484..421d5ed 100644 --- a/lib/name_parameter.rb +++ b/lib/name_parameter.rb @@ -25,9 +25,9 @@ def initialize(text, options = {}) #:notnew: # # Returns the new Hash. def load_param - self.to_hash.select { |_key, value| !value.nil? } - .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } - .to_h + to_hash.select { |_key, value| value } + .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } + .to_h end # Converts this class to Hash. diff --git a/lib/rosette_api.rb b/lib/rosette_api.rb index 81e9d36..835e2bb 100644 --- a/lib/rosette_api.rb +++ b/lib/rosette_api.rb @@ -3,6 +3,7 @@ require_relative 'name_deduplication_parameters' require_relative 'name_translation_parameters' require_relative 'name_similarity_parameters' +require_relative 'transliteration_parameters' require_relative 'rosette_api_error' require_relative 'bad_request_error' require_relative 'bad_request_format_error' @@ -42,7 +43,7 @@ class RosetteAPI # Syntactic Dependencies endpoint SYNTACTIC_DEPENDENCIES_ENDPOINT = '/syntax/dependencies'.freeze # Transliteration endpoint - TRANSLITERATION_ENDPOINT = 'transliteration'.freeze + TRANSLITERATION_ENDPOINT = '/transliteration'.freeze # Rosette API key attr_accessor :user_key @@ -348,6 +349,23 @@ def get_syntax_dependencies(params) .send_post_request end + # + # Returns the transliteration of the content + # + # ==== Attributes + # + # * +params+ - TransliterationParameters helps to build the request body in RequestBuilder. + # + # Returns the transliteration of the input. + def get_transliteration(params) + check_params params, 'Expects a TransliterationParameters type as an argument', TransliterationParameters + + params = params.load_params + + RequestBuilder.new(@user_key, @alternate_url + TRANSLITERATION_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) + .send_post_request + end + # Gets information about the Rosette API, returns name, build number # and build time. def info diff --git a/lib/transliteration_parameters.rb b/lib/transliteration_parameters.rb new file mode 100644 index 0000000..2d597bb --- /dev/null +++ b/lib/transliteration_parameters.rb @@ -0,0 +1,67 @@ +require_relative 'bad_request_error' + +# This class encapsulates parameters that are needed for transliteration in +# Rosette API. +class TransliterationParameters + # Rosette API options (optional, should be a hash) + attr_accessor :rosette_options + # Content to be transliterated + attr_accessor :content + # Target Language + attr_accessor :target_language + # Target Script + attr_accessor :target_script + # Source Language + attr_accessor :source_language + # Source Script + attr_accessor :source_script + + def initialize(content, target_language, target_script, source_language, source_script, options = {}) #:notnew: + options = { + rosette_options: nil + }.update options + @content = content + @target_language = target_language + @target_script = target_script + @source_language = source_language + @source_script = source_script + @rosette_options = options[:rosette_options] + end + + # Validates the parameters by checking if name1 and name2 are instances of + # a String or NameParameter. + def validate_params + raise BadRequestError.new('content must be provided') unless @content + raise BadRequestError.new('target_language must be provided') unless @target_anguage + raise BadRequestError.new('target_script must be provided') unless @target_script + raise BadRequestError.new('source_language must be provided') unless @source_language + raise BadRequestError.new('source_script must be provided') unless @source_script + if @rosette_options + raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash + end + end + + # Converts this class to Hash with its keys in lower CamelCase. + # + # Returns the new Hash. + def load_params + validate_params + to_hash.select { |_key, value| value } + .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } + .to_h + end + + # Converts this class to Hash. + # + # Returns the new Hash. + def to_hash + { + content: @content, + targetLanguage: @target_language, + targetScript: @target_script, + sourceLanguage: @source_language, + sourceScript: @source_script, + options: @rosette_options + } + end +end diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index a195de9..5f07b93 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -352,6 +352,68 @@ end end + describe '.transliteration' do + content = 'Kareem Abdul Jabbar holds the record for most points in the NBA' + target_language = 'eng' + target_script = 'Latn' + source_language = 'ara' + source_script = 'Latn' + before do + transliteration_json = { content: content, + target_language: target_language, + target_script: target_script, + source_language: source_language, + source_script: source_script }.to_json + + stub_request(:post, 'https://api.rosette.com/rest/v1/transliteration') + .with(body: transliteration_json, + headers: {'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{"test": "transliteration"}', headers: {}) + end + it 'test transliteration' do + params = TransliterationParameters.new(content, target_language, target_script, source_language, source_script) + response = RosetteAPI.new('0123456789').name_deduplication(params) + expect(response).instance_of? Hash + end + + it 'badRequest: content must be provided' do + params = TransliterationParameters.new(nil, target_language, target_script, source_language, source_script) + expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + end + + it 'badRequest: source_language must be provided' do + params = TransliterationParameters.new(content, nil, target_script, source_language, source_script) + expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + end + + it 'badRequest: source_script must be provided' do + params = TransliterationParameters.new(content, target_language, nil, source_language, source_script) + expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + end + + it 'badRequest: target_language must be provided' do + params = TransliterationParameters.new(content, target_language, target_script, nil, source_script) + expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + end + + it 'badRequest: source_language must be provided' do + params = TransliterationParameters.new(content, target_language, target_script, source_language, nil) + expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + end + + it 'badRequest: rosette_options can only be an instance of a Hash' do + params = TransliterationParameters.new(content, target_language, target_script, source_language, source_script) + params.rosette_options = 1 + expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + end + end + describe '.get_tokens' do before do stub_request(:post, 'https://api.rosette.com/rest/v1/tokens') From e17cd6d337b476a236d93f2e06985b9e80d818d9 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 19 Apr 2017 16:54:16 -0400 Subject: [PATCH 06/17] Unit test fixes and cleanup - hash names snake_case converted to cameCase automatically - renamed name_similarity and name_translation api methods to get_name_similarity and get_name_translation to match the rest of the api endpoint calls --- examples/name_deduplication.rb | 2 +- examples/name_similarity.rb | 2 +- examples/name_translation.rb | 2 +- examples/transliteration.rb | 2 +- lib/rosette_api.rb | 6 ++--- lib/transliteration_parameters.rb | 10 +++---- tests/tests_spec.rb | 44 +++++++++++++++---------------- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/examples/name_deduplication.rb b/examples/name_deduplication.rb index 53d7af9..d1e06a8 100644 --- a/examples/name_deduplication.rb +++ b/examples/name_deduplication.rb @@ -13,7 +13,7 @@ names = dedup_list.map { |n| NameParameter.new(n) } begin params = NameDeduplicationParameters.new(names, threshold) - response = rosette_api.name_deduplication(params) + response = rosette_api.get_name_deduplication(params) puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) diff --git a/examples/name_similarity.rb b/examples/name_similarity.rb index 4e18310..f03683a 100644 --- a/examples/name_similarity.rb +++ b/examples/name_similarity.rb @@ -13,7 +13,7 @@ begin name1 = NameParameter.new(matched_name_data1, entity_type: 'PERSON', language: 'eng') params = NameSimilarityParameters.new(name1, matched_name_data2) - response = rosette_api.name_similarity(params) + response = rosette_api.get_name_similarity(params) puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) diff --git a/examples/name_translation.rb b/examples/name_translation.rb index 3d19acd..0d3ca25 100644 --- a/examples/name_translation.rb +++ b/examples/name_translation.rb @@ -11,7 +11,7 @@ translated_name_data = 'معمر محمد أبو منيار القذاف' begin params = NameTranslationParameters.new(translated_name_data, 'eng', target_script: 'Latn') - response = rosette_api.name_translation(params) + response = rosette_api.get_name_translation(params) puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) diff --git a/examples/transliteration.rb b/examples/transliteration.rb index 242c94e..e2c4d3b 100644 --- a/examples/transliteration.rb +++ b/examples/transliteration.rb @@ -19,7 +19,7 @@ transliteration_target_script, transliteration_source_language, transliteration_source_script) - response = rosette_api.transliteration(params) + response = rosette_api.get_transliteration(params) puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) diff --git a/lib/rosette_api.rb b/lib/rosette_api.rb index 835e2bb..e279e4e 100644 --- a/lib/rosette_api.rb +++ b/lib/rosette_api.rb @@ -241,7 +241,7 @@ def get_sentiment(params) # * +params+ - NameDeduplicationParameters helps to build the request body in RequestBuilder. # # Returns the list of deduplicated names. - def name_deduplication(params) + def get_name_deduplication(params) check_params params, 'Expects a NameDeduplicationParameters type as an argument', NameDeduplicationParameters params = params.load_params @@ -257,7 +257,7 @@ def name_deduplication(params) # * +params+ - NameTranslationParameters helps to build the request body in RequestBuilder. # # Returns the translation of a name. - def name_translation(params) + def get_name_translation(params) check_params params, 'Expects a NameTranslationParameters type as an argument', NameTranslationParameters params = params.load_params @@ -274,7 +274,7 @@ def name_translation(params) # * +params+ - NameSimilarityParameters helps to build the request body in RequestBuilder. # # Returns the confidence score of matching 2 names. - def name_similarity(params) + def get_name_similarity(params) check_params params, 'Expects a NameSimilarityParameters type as an argument', NameSimilarityParameters params = params.load_params diff --git a/lib/transliteration_parameters.rb b/lib/transliteration_parameters.rb index 2d597bb..d7c6661 100644 --- a/lib/transliteration_parameters.rb +++ b/lib/transliteration_parameters.rb @@ -32,7 +32,7 @@ def initialize(content, target_language, target_script, source_language, source_ # a String or NameParameter. def validate_params raise BadRequestError.new('content must be provided') unless @content - raise BadRequestError.new('target_language must be provided') unless @target_anguage + raise BadRequestError.new('target_language must be provided') unless @target_language raise BadRequestError.new('target_script must be provided') unless @target_script raise BadRequestError.new('source_language must be provided') unless @source_language raise BadRequestError.new('source_script must be provided') unless @source_script @@ -57,10 +57,10 @@ def load_params def to_hash { content: @content, - targetLanguage: @target_language, - targetScript: @target_script, - sourceLanguage: @source_language, - sourceScript: @source_script, + target_language: @target_language, + target_script: @target_script, + source_language: @source_language, + source_script: @source_script, options: @rosette_options } end diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index 5f07b93..81af70c 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -262,13 +262,13 @@ it 'test name translation' do params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng') params.target_script = 'Latn' - response = RosetteAPI.new('0123456789').name_translation(params) + response = RosetteAPI.new('0123456789').get_name_translation(params) expect(response).instance_of? Hash end it 'badRequest: Expects NameTranslationParameters type as an argument' do params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊') - expect { RosetteAPI.new('0123456789').name_translation(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_name_translation(params) }.to raise_error(BadRequestError) end end @@ -288,23 +288,23 @@ end it 'test name similarity' do params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊') - response = RosetteAPI.new('0123456789').name_similarity(params) + response = RosetteAPI.new('0123456789').get_name_similarity(params) expect(response).instance_of? Hash end it 'badRequestFormat: name1 option can only be an instance of a String or NameParameter' do params = NameSimilarityParameters.new(123, 'Michael Jackson') - expect { RosetteAPI.new('0123456789').name_similarity(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError) end it 'badRequestFormat: name2 option can only be an instance of a String or NameParameter' do params = NameSimilarityParameters.new('Michael Jackson', 123) - expect { RosetteAPI.new('0123456789').name_similarity(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError) end it 'badRequest: Expects NameSimilarityParameters type as an argument' do params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng') - expect { RosetteAPI.new('0123456789').name_similarity(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError) end end @@ -326,29 +326,29 @@ end it 'test name deduplication' do params = NameDeduplicationParameters.new(names, 0.75) - response = RosetteAPI.new('0123456789').name_deduplication(params) + response = RosetteAPI.new('0123456789').get_name_deduplication(params) expect(response).instance_of? Hash end it 'badRequestFormat: names must be an array of name_parameter' do params = NameDeduplicationParameters.new('Michael Jackson', 0.75) - expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError) end it 'badRequestFormat: threshold must be a float' do params = NameDeduplicationParameters.new(names, 123) - expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError) end it 'badRequest: threshold must be in the range of 0 to 1' do params = NameDeduplicationParameters.new(names, 1.5) - expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError) end it 'badRequest: rosette_options can only be an instance of a Hash' do params = NameDeduplicationParameters.new(names, 0.5) params.rosette_options = 1 - expect { RosetteAPI.new('0123456789').name_deduplication(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError) end end @@ -360,10 +360,10 @@ source_script = 'Latn' before do transliteration_json = { content: content, - target_language: target_language, - target_script: target_script, - source_language: source_language, - source_script: source_script }.to_json + targetLanguage: target_language, + targetScript: target_script, + sourceLanguage: source_language, + sourceScript: source_script }.to_json stub_request(:post, 'https://api.rosette.com/rest/v1/transliteration') .with(body: transliteration_json, @@ -378,39 +378,39 @@ end it 'test transliteration' do params = TransliterationParameters.new(content, target_language, target_script, source_language, source_script) - response = RosetteAPI.new('0123456789').name_deduplication(params) + response = RosetteAPI.new('0123456789').get_transliteration(params) expect(response).instance_of? Hash end it 'badRequest: content must be provided' do params = TransliterationParameters.new(nil, target_language, target_script, source_language, source_script) - expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end it 'badRequest: source_language must be provided' do params = TransliterationParameters.new(content, nil, target_script, source_language, source_script) - expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end it 'badRequest: source_script must be provided' do params = TransliterationParameters.new(content, target_language, nil, source_language, source_script) - expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end it 'badRequest: target_language must be provided' do params = TransliterationParameters.new(content, target_language, target_script, nil, source_script) - expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end it 'badRequest: source_language must be provided' do params = TransliterationParameters.new(content, target_language, target_script, source_language, nil) - expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end it 'badRequest: rosette_options can only be an instance of a Hash' do params = TransliterationParameters.new(content, target_language, target_script, source_language, source_script) params.rosette_options = 1 - expect { RosetteAPI.new('0123456789').transliteration(params) }.to raise_error(BadRequestError) + expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end end From 8d43af270cac9c1ea4789cd5a2d6beeafd8898be Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 2 May 2017 09:25:11 -0400 Subject: [PATCH 07/17] Transliteration revision - Removed TransliterationParameters - Updated transliteration unit tests - Updated transliteration example to use DocumentParameters --- examples/transliteration.rb | 11 +---- lib/document_parameters.rb | 17 ++++---- lib/transliteration_parameters.rb | 67 ------------------------------- tests/tests_spec.rb | 37 +++-------------- 4 files changed, 16 insertions(+), 116 deletions(-) delete mode 100644 lib/transliteration_parameters.rb diff --git a/examples/transliteration.rb b/examples/transliteration.rb index e2c4d3b..3fe7c69 100644 --- a/examples/transliteration.rb +++ b/examples/transliteration.rb @@ -9,16 +9,9 @@ end transliteration_content_data = 'Kareem Abdul Jabbar holds the records for most points in the NBA' -transliteration_target_language = 'eng' -transliteration_target_script = 'Latn' -transliteration_source_language = 'ara' -transliteration_source_script = 'Latn' + begin - params = TransliterationParameters.new(transliteration_content_data, - transliteration_target_language, - transliteration_target_script, - transliteration_source_language, - transliteration_source_script) + params = DocumentParameters.new(transliteration_content_data) response = rosette_api.get_transliteration(params) puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error diff --git a/lib/document_parameters.rb b/lib/document_parameters.rb index edbfd68..8279a18 100644 --- a/lib/document_parameters.rb +++ b/lib/document_parameters.rb @@ -40,14 +40,15 @@ def initialize(options = {}) #:notnew: # Validates the parameters by checking if there are multiple content sources # set or no content provided at all. def validate_params - if [@content, @content_uri, @file_path].compact.length > 1 - raise BadRequestFormatError.new 'The format of the request is invalid: multiple content sources;' \ - ' must be one of an attachment, an inline "content" field, or an external' \ - '"contentUri"' - elsif [@content, @content_uri, @file_path].all?(&:nil?) - raise BadRequestFormatError.new 'The format of the request is invalid: no content provided; must' \ - ' be one of an attachment, an inline "content" field, or an external "contentUri"' - elsif @rosette_options + + raise BadRequestFormatError.new 'The format of the request is invalid: multiple content sources;' \ + ' must be one of an attachment, an inline "content" field, or an external' \ + '"contentUri"' + unless [@content, @content_uri, @file_path].compact.length > 1 + raise BadRequestFormatError.new 'The format of the request is invalid: no content provided; must' \ + ' be one of an attachment, an inline "content" field, or an external "contentUri"' + unless [@content, @content_uri, @file_path].all?(&:nil?) + if @rosette_options raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash end end diff --git a/lib/transliteration_parameters.rb b/lib/transliteration_parameters.rb deleted file mode 100644 index d7c6661..0000000 --- a/lib/transliteration_parameters.rb +++ /dev/null @@ -1,67 +0,0 @@ -require_relative 'bad_request_error' - -# This class encapsulates parameters that are needed for transliteration in -# Rosette API. -class TransliterationParameters - # Rosette API options (optional, should be a hash) - attr_accessor :rosette_options - # Content to be transliterated - attr_accessor :content - # Target Language - attr_accessor :target_language - # Target Script - attr_accessor :target_script - # Source Language - attr_accessor :source_language - # Source Script - attr_accessor :source_script - - def initialize(content, target_language, target_script, source_language, source_script, options = {}) #:notnew: - options = { - rosette_options: nil - }.update options - @content = content - @target_language = target_language - @target_script = target_script - @source_language = source_language - @source_script = source_script - @rosette_options = options[:rosette_options] - end - - # Validates the parameters by checking if name1 and name2 are instances of - # a String or NameParameter. - def validate_params - raise BadRequestError.new('content must be provided') unless @content - raise BadRequestError.new('target_language must be provided') unless @target_language - raise BadRequestError.new('target_script must be provided') unless @target_script - raise BadRequestError.new('source_language must be provided') unless @source_language - raise BadRequestError.new('source_script must be provided') unless @source_script - if @rosette_options - raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash - end - end - - # Converts this class to Hash with its keys in lower CamelCase. - # - # Returns the new Hash. - def load_params - validate_params - to_hash.select { |_key, value| value } - .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } - .to_h - end - - # Converts this class to Hash. - # - # Returns the new Hash. - def to_hash - { - content: @content, - target_language: @target_language, - target_script: @target_script, - source_language: @source_language, - source_script: @source_script, - options: @rosette_options - } - end -end diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index 81af70c..bc2ec36 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -354,16 +354,9 @@ describe '.transliteration' do content = 'Kareem Abdul Jabbar holds the record for most points in the NBA' - target_language = 'eng' - target_script = 'Latn' - source_language = 'ara' - source_script = 'Latn' + before do - transliteration_json = { content: content, - targetLanguage: target_language, - targetScript: target_script, - sourceLanguage: source_language, - sourceScript: source_script }.to_json + transliteration_json = { content: content }.to_json stub_request(:post, 'https://api.rosette.com/rest/v1/transliteration') .with(body: transliteration_json, @@ -377,38 +370,18 @@ .to_return(status: 200, body: '{"test": "transliteration"}', headers: {}) end it 'test transliteration' do - params = TransliterationParameters.new(content, target_language, target_script, source_language, source_script) + params = DocumentParameters.new(content) response = RosetteAPI.new('0123456789').get_transliteration(params) expect(response).instance_of? Hash end it 'badRequest: content must be provided' do - params = TransliterationParameters.new(nil, target_language, target_script, source_language, source_script) - expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) - end - - it 'badRequest: source_language must be provided' do - params = TransliterationParameters.new(content, nil, target_script, source_language, source_script) - expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) - end - - it 'badRequest: source_script must be provided' do - params = TransliterationParameters.new(content, target_language, nil, source_language, source_script) - expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) - end - - it 'badRequest: target_language must be provided' do - params = TransliterationParameters.new(content, target_language, target_script, nil, source_script) - expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) - end - - it 'badRequest: source_language must be provided' do - params = TransliterationParameters.new(content, target_language, target_script, source_language, nil) + params = DocumentParameters.new(nil) expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end it 'badRequest: rosette_options can only be an instance of a Hash' do - params = TransliterationParameters.new(content, target_language, target_script, source_language, source_script) + params = DocumentParameters.new(content) params.rosette_options = 1 expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end From 013797224f19dabcc0df70ab3c5b737a7c2b2f11 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 2 May 2017 09:36:42 -0400 Subject: [PATCH 08/17] Fixed parameter check --- lib/document_parameters.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/document_parameters.rb b/lib/document_parameters.rb index 8279a18..0e6ed93 100644 --- a/lib/document_parameters.rb +++ b/lib/document_parameters.rb @@ -40,15 +40,14 @@ def initialize(options = {}) #:notnew: # Validates the parameters by checking if there are multiple content sources # set or no content provided at all. def validate_params - - raise BadRequestFormatError.new 'The format of the request is invalid: multiple content sources;' \ - ' must be one of an attachment, an inline "content" field, or an external' \ - '"contentUri"' - unless [@content, @content_uri, @file_path].compact.length > 1 - raise BadRequestFormatError.new 'The format of the request is invalid: no content provided; must' \ - ' be one of an attachment, an inline "content" field, or an external "contentUri"' - unless [@content, @content_uri, @file_path].all?(&:nil?) - if @rosette_options + if [@content, @content_uri, @file_path].compact.length > 1 + raise BadRequestFormatError.new 'The format of the request is invalid: multiple content sources;' \ + ' must be one of an attachment, an inline "content" field, or an external' \ + '"contentUri"' unless [@content, @content_uri, @file_path].compact.length > 1 + elsif [@content, @content_uri, @file_path].all?(&:nil?) + raise BadRequestFormatError.new 'The format of the request is invalid: no content provided; must' \ + ' be one of an attachment, an inline "content" field, or an external "contentUri"' + elsif @rosette_options raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash end end From f78f066c8715459aa582c4f27ce30b1c71188fff Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 2 May 2017 09:39:03 -0400 Subject: [PATCH 09/17] Bug fix from previous change --- lib/document_parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/document_parameters.rb b/lib/document_parameters.rb index 0e6ed93..edbfd68 100644 --- a/lib/document_parameters.rb +++ b/lib/document_parameters.rb @@ -43,7 +43,7 @@ def validate_params if [@content, @content_uri, @file_path].compact.length > 1 raise BadRequestFormatError.new 'The format of the request is invalid: multiple content sources;' \ ' must be one of an attachment, an inline "content" field, or an external' \ - '"contentUri"' unless [@content, @content_uri, @file_path].compact.length > 1 + '"contentUri"' elsif [@content, @content_uri, @file_path].all?(&:nil?) raise BadRequestFormatError.new 'The format of the request is invalid: no content provided; must' \ ' be one of an attachment, an inline "content" field, or an external "contentUri"' From 91f49813cbe6a892028ba89c2c2779ab33ed8b19 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 2 May 2017 09:44:05 -0400 Subject: [PATCH 10/17] Missed a transliteration_parameters reference --- lib/rosette_api.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/rosette_api.rb b/lib/rosette_api.rb index e279e4e..511eadb 100644 --- a/lib/rosette_api.rb +++ b/lib/rosette_api.rb @@ -3,7 +3,6 @@ require_relative 'name_deduplication_parameters' require_relative 'name_translation_parameters' require_relative 'name_similarity_parameters' -require_relative 'transliteration_parameters' require_relative 'rosette_api_error' require_relative 'bad_request_error' require_relative 'bad_request_format_error' From d665f55308cf24320d15812b94537ec1e91a65c0 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 2 May 2017 10:01:02 -0400 Subject: [PATCH 11/17] Bug squash - fixed assignment in transliteration example - fixed unit test (looking for wrong exception) - fixed api, checking for wrong parameter type --- examples/transliteration.rb | 3 ++- lib/rosette_api.rb | 4 ++-- tests/tests_spec.rb | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/transliteration.rb b/examples/transliteration.rb index 3fe7c69..8a4b2f1 100644 --- a/examples/transliteration.rb +++ b/examples/transliteration.rb @@ -11,7 +11,8 @@ transliteration_content_data = 'Kareem Abdul Jabbar holds the records for most points in the NBA' begin - params = DocumentParameters.new(transliteration_content_data) + params = DocumentParameters.new + params.content = transliteration_content_data response = rosette_api.get_transliteration(params) puts JSON.pretty_generate(response) rescue RosetteAPIError => rosette_api_error diff --git a/lib/rosette_api.rb b/lib/rosette_api.rb index 511eadb..2c716e7 100644 --- a/lib/rosette_api.rb +++ b/lib/rosette_api.rb @@ -353,11 +353,11 @@ def get_syntax_dependencies(params) # # ==== Attributes # - # * +params+ - TransliterationParameters helps to build the request body in RequestBuilder. + # * +params+ - DocumentParameters helps to build the request body in RequestBuilder. # # Returns the transliteration of the input. def get_transliteration(params) - check_params params, 'Expects a TransliterationParameters type as an argument', TransliterationParameters + check_params params, 'Expects a DocumentParameters type as an argument', DocumentParameters params = params.load_params diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index bc2ec36..ec92eab 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -370,18 +370,20 @@ .to_return(status: 200, body: '{"test": "transliteration"}', headers: {}) end it 'test transliteration' do - params = DocumentParameters.new(content) + params = DocumentParameters.new + params.content = content response = RosetteAPI.new('0123456789').get_transliteration(params) expect(response).instance_of? Hash end it 'badRequest: content must be provided' do - params = DocumentParameters.new(nil) - expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) + params = DocumentParameters.new + expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestFormatError) end it 'badRequest: rosette_options can only be an instance of a Hash' do - params = DocumentParameters.new(content) + params = DocumentParameters.new + params.content = content params.rosette_options = 1 expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError) end From 27fbeb693090f8e578386492975602220486c1bb Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 4 May 2017 08:19:27 -0400 Subject: [PATCH 12/17] Name deduplication fix - Added name expansion to to_hash --- lib/name_deduplication_parameters.rb | 2 +- lib/request_builder.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/name_deduplication_parameters.rb b/lib/name_deduplication_parameters.rb index ea1b22f..57d8262 100644 --- a/lib/name_deduplication_parameters.rb +++ b/lib/name_deduplication_parameters.rb @@ -46,7 +46,7 @@ def load_params # Returns the new Hash. def to_hash { - names: @names, + names: @names.map(&:load_param), threshold: @threshold, options: @rosette_options } diff --git a/lib/request_builder.rb b/lib/request_builder.rb index 799ad48..e9f3deb 100644 --- a/lib/request_builder.rb +++ b/lib/request_builder.rb @@ -62,6 +62,7 @@ def prepare_plain_request(params) request['X-RosetteAPI-Binding'] = 'ruby' request['X-RosetteAPI-Binding-Version'] = @binding_version request.body = params.to_json + print(request.body) [@http_client, request] end From 5877d9f17dff2354919909af03b75fd12a6e3ecb Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 4 May 2017 08:31:58 -0400 Subject: [PATCH 13/17] Unit test fix - name deduplication needed the same map fix for the name elements --- lib/request_builder.rb | 13 +++++++------ tests/tests_spec.rb | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/request_builder.rb b/lib/request_builder.rb index e9f3deb..12c8bd8 100644 --- a/lib/request_builder.rb +++ b/lib/request_builder.rb @@ -44,11 +44,13 @@ def prepare_plain_request(params) raise RosetteAPIError.new 'connectionError', 'Failed to establish connection with Rosette API server.' end - if params['customHeaders'] - keys_array = params['customHeaders'].keys - for k in keys_array - if k.to_s =~ /^X-RosetteAPI-/ - request[k] = params['customHeaders'][k] + custom_headers = params['customHeaders'] + + if custom_headers + keys_array = custom_headers.keys + for key in keys_array + if key.to_s =~ /^X-RosetteAPI-/ + request[key] = custom_headers[key] else raise RosetteAPIError.new 'invalidHeader', 'Custom header must begin with "X-RosetteAPI-"' end @@ -62,7 +64,6 @@ def prepare_plain_request(params) request['X-RosetteAPI-Binding'] = 'ruby' request['X-RosetteAPI-Binding-Version'] = @binding_version request.body = params.to_json - print(request.body) [@http_client, request] end diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index ec92eab..2536bbc 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -311,7 +311,7 @@ describe '.name_deduplication' do names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| NameParameter.new(n) } before do - names_json = { names: names, threshold: 0.75 }.to_json + names_json = { names: names.map(&:load_param), threshold: 0.75 }.to_json stub_request(:post, 'https://api.rosette.com/rest/v1/name-deduplication') .with(body: names_json, From e3d8fe03e6ff3175c051589d2dada3a5c5002505 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 15 May 2017 08:56:32 -0400 Subject: [PATCH 14/17] Updated name deduplication example - Added data identifier with string of names - Updated code to split string and map to Name objects --- examples/name_deduplication.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/name_deduplication.rb b/examples/name_deduplication.rb index d1e06a8..4e91178 100644 --- a/examples/name_deduplication.rb +++ b/examples/name_deduplication.rb @@ -8,9 +8,10 @@ rosette_api = RosetteAPI.new(api_key, url) end -dedup_list = ['John Smith', 'Johnathon Smith', 'Fred Jones'] +name_dedupe_data = 'John Smith,Johnathon Smith,Fred Jones' + threshold = 0.75 -names = dedup_list.map { |n| NameParameter.new(n) } +names = name_dedupe_data.Split(',').map { |n| NameParameter.new(n) } begin params = NameDeduplicationParameters.new(names, threshold) response = rosette_api.get_name_deduplication(params) From 98e5a5648672f2d7bb5b63f7cc3c0d1688072d53 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 15 May 2017 08:59:01 -0400 Subject: [PATCH 15/17] Syntax error --- examples/name_deduplication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/name_deduplication.rb b/examples/name_deduplication.rb index 4e91178..d022949 100644 --- a/examples/name_deduplication.rb +++ b/examples/name_deduplication.rb @@ -11,7 +11,7 @@ name_dedupe_data = 'John Smith,Johnathon Smith,Fred Jones' threshold = 0.75 -names = name_dedupe_data.Split(',').map { |n| NameParameter.new(n) } +names = name_dedupe_data.split(',').map { |n| NameParameter.new(n) } begin params = NameDeduplicationParameters.new(names, threshold) response = rosette_api.get_name_deduplication(params) From 8f5217efdb787e4682d6872707651fc21d98b394 Mon Sep 17 00:00:00 2001 From: Brian Sawyer Date: Fri, 26 May 2017 10:43:46 -0400 Subject: [PATCH 16/17] WS-1138 Allow name deduplication threshold to be null as default --- lib/name_deduplication_parameters.rb | 6 ++++-- tests/tests_spec.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/name_deduplication_parameters.rb b/lib/name_deduplication_parameters.rb index 57d8262..c9e47e3 100644 --- a/lib/name_deduplication_parameters.rb +++ b/lib/name_deduplication_parameters.rb @@ -24,8 +24,10 @@ def initialize(names, threshold, options = {}) #:notnew: # a String or NameParameter. def validate_params raise BadRequestError.new('names must be an array of name_parameter') unless @names.instance_of? Array - raise BadRequestError.new('threshold must be a float') unless @threshold.is_a?(Float) - raise BadRequestError.new('threshold must be in the range of 0 to 1') if @threshold.negative? || @threshold > 1 + if @threshold + raise BadRequestError.new('threshold must be a float') unless @threshold.is_a?(Float) + raise BadRequestError.new('threshold must be in the range of 0 to 1') if @threshold.negative? || @threshold > 1 + end if @rosette_options raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash end diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index 2536bbc..ff919b1 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -323,12 +323,31 @@ 'X-Rosetteapi-Binding' => 'ruby', 'X-Rosetteapi-Binding-Version' => '1.5.0' }) .to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {}) + + nothresh_json = { names: names.map(&:load_param) }.to_json + + stub_request(:post, 'https://api.rosette.com/rest/v1/name-deduplication') + .with(body: nothresh_json, + headers: {'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby', + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + .to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {}) end it 'test name deduplication' do params = NameDeduplicationParameters.new(names, 0.75) response = RosetteAPI.new('0123456789').get_name_deduplication(params) expect(response).instance_of? Hash end + + it 'test null threshold' do + params = NameDeduplicationParameters.new(names, nil) + response = RosetteAPI.new('0123456789').get_name_deduplication(params) + expect(response).instance_of? Hash + end it 'badRequestFormat: names must be an array of name_parameter' do params = NameDeduplicationParameters.new('Michael Jackson', 0.75) From eba2382356094dc3d7b0d96cd148b4cd4aa13753 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 14 Jun 2017 12:40:14 +0000 Subject: [PATCH 17/17] Version 1.7.0 --- lib/rosette_api.rb | 2 +- rosette_api.gemspec | 4 ++-- tests/tests_spec.rb | 40 ++++++++++++++++++++-------------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/rosette_api.rb b/lib/rosette_api.rb index 2c716e7..2384354 100644 --- a/lib/rosette_api.rb +++ b/lib/rosette_api.rb @@ -10,7 +10,7 @@ # This class allows you to access all Rosette API endpoints. class RosetteAPI # Version of Ruby binding - BINDING_VERSION = '1.5.0' + BINDING_VERSION = '1.7.0' # Rosette API language endpoint LANGUAGE_ENDPOINT = '/language'.freeze # Rosette API morphology endpoint diff --git a/rosette_api.gemspec b/rosette_api.gemspec index 202c2c0..5f39c71 100644 --- a/rosette_api.gemspec +++ b/rosette_api.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.0.0' s.name = 'rosette_api' - s.version = '1.5.0' + s.version = '1.7.0' s.license = 'MIT' s.summary = 'Rosette API gem that supports multilingual text-analytics.' @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.authors = ['Basis Technology Corp'] s.email = %q{support@rosette.com} s.homepage = %q{https://developer.rosette.com/} - s.date = %q{2016-12-19} + s.date = %q{2017-06-14} all_files = `git ls-files -z`.split("\x0") s.files = all_files.grep(%r{^(bin|lib)/|^.rubocop.yml$}) diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index ff919b1..336870c 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -21,7 +21,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test language' do @@ -55,7 +55,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "morphology/complete"}', headers: {}) end it 'test morphology complete' do @@ -76,7 +76,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "morphology/compound-components"}', headers: {}) end it 'test morphology compound components' do @@ -97,7 +97,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "morphology/han-readings"}', headers: {}) end it 'test morphology han readings' do @@ -118,7 +118,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "morphology/parts-of-speech"}', headers: {}) end it 'test morphology parts of speech' do @@ -139,7 +139,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "morphology/lemmas"}', headers: {}) end it 'test morphology lemmas' do @@ -160,7 +160,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "entities"}', headers: {}) end it 'test entities' do @@ -182,7 +182,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "entities"}', headers: {}) end it 'test entities without qids' do @@ -213,7 +213,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "categories"}', headers: {}) end it 'test categories' do @@ -234,7 +234,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "relationships"}', headers: {}) end it 'test relationships' do @@ -256,7 +256,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "name-translation"}', headers: {}) end it 'test name translation' do @@ -283,7 +283,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "name-similarity"}', headers: {}) end it 'test name similarity' do @@ -321,7 +321,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {}) nothresh_json = { names: names.map(&:load_param) }.to_json @@ -334,7 +334,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {}) end it 'test name deduplication' do @@ -385,7 +385,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "transliteration"}', headers: {}) end it 'test transliteration' do @@ -418,7 +418,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "tokens"}', headers: {}) end it 'test tokens' do @@ -439,7 +439,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "sentences"}', headers: {}) end it 'test sentences' do @@ -490,7 +490,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0', + 'X-Rosetteapi-Binding-Version' => '1.7.0', 'X-RosetteApi-App' => 'ruby-app' }) .to_return(status: 200, body: '{"test": "language"}', headers: {}) end @@ -527,7 +527,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test text_embedding' do @@ -548,7 +548,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.5.0' }) + 'X-Rosetteapi-Binding-Version' => '1.7.0' }) .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test syntax_dependencies' do