Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
seth-mg committed Feb 8, 2019
2 parents 26700e7 + cd498c8 commit 2b81602
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node {
node ("docker-light") {
def SOURCEDIR = pwd()
try {
stage("Clean up") {
Expand Down
2 changes: 1 addition & 1 deletion examples/categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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 = "https://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)
Expand Down
1 change: 0 additions & 1 deletion examples/relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
relationships_text_data = "FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC’s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR’s security cameras to the same government officials. At the time, Timms was the head of FLIR’s Middle East office in Dubai."
begin
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
Expand Down
6 changes: 3 additions & 3 deletions examples/text_embedding.rb → examples/semantic_vectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
rosette_api = RosetteAPI.new(api_key, url)
end

embeddings_data = "Cambridge, Massachusetts"
semantic_vectors_data = "Cambridge, Massachusetts"
begin
params = DocumentParameters.new(content: embeddings_data)
response = rosette_api.get_text_embedding(params)
params = DocumentParameters.new(content: semantic_vectors_data)
response = rosette_api.get_semantic_vectors(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)
Expand Down
19 changes: 19 additions & 0 deletions examples/similar_terms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rosette_api'

api_key, url = ARGV

if !url
rosette_api = RosetteAPI.new(api_key)
else
rosette_api = RosetteAPI.new(api_key, url)
end

similar_terms_data = "spy"
begin
params = DocumentParameters.new(content: similar_terms_data)
params.rosette_options = { "resultLanguages" => ["spa", "deu", "jpn"] }
response = rosette_api.get_similar_terms(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
43 changes: 40 additions & 3 deletions lib/rosette_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# This class allows you to access all Rosette API endpoints.
class RosetteAPI
# Version of Ruby binding
BINDING_VERSION = '1.9.2'
BINDING_VERSION = '1.12.1'
# Rosette API language endpoint
LANGUAGE_ENDPOINT = '/language'.freeze
# Rosette API morphology endpoint
Expand All @@ -37,8 +37,12 @@ class RosetteAPI
INFO = '/info'.freeze
# Rosette API ping endpoint
PING = '/ping'.freeze
# Text Embedding endpoint
# Text Embedding endpoint (deprecated)
TEXT_EMBEDDING = '/text-embedding'.freeze
# Semantic Vectors endpoint (replaces /text-embedding)
SEMANTIC_VECTORS = '/semantics/vector'.freeze
# Similar Terms endpoint
SIMILAR_TERMS_ENDPOINT = '/semantics/similar'.freeze
# Syntactic Dependencies endpoint
SYNTACTIC_DEPENDENCIES_ENDPOINT = '/syntax/dependencies'.freeze
# Transliteration endpoint
Expand Down Expand Up @@ -320,11 +324,13 @@ def get_sentences(params)
#
# Returns the vectors associated with the text
#
# Deprecated. Please use `get_semantic_vectors` instead
#
# ==== Attributes
#
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
#
# Returns list of linguistic sentences of the input.
# Returns the text embedding representation of the input.
def get_text_embedding(params)
check_params params

Expand All @@ -341,6 +347,21 @@ def get_text_embedding(params)
#
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
#
# Returns the text embedding representation of the input.
def get_semantic_vectors(params)
check_params params
params = params.load_params
RequestBuilder.new(@user_key, @alternate_url + SEMANTIC_VECTORS, @http_client, params, @url_parameters, BINDING_VERSION)
.send_post_request
end

#
# Returns the syntactic structure of the text
#
# ==== Attributes
#
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
#
# Returns list of linguistic sentences of the input.
def get_syntax_dependencies(params)
check_params params
Expand Down Expand Up @@ -384,6 +405,22 @@ def get_topics(params)
.send_post_request
end

# Returns the terms similar to the input
#
# ==== Attributes
#
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
#
# Returns a mapping of languageCode to similar terms
def get_similar_terms(params)
check_params params

params = params.load_params

RequestBuilder.new(@user_key, @alternate_url + SIMILAR_TERMS_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
Expand Down
4 changes: 2 additions & 2 deletions rosette_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.0.0'

s.name = 'rosette_api'
s.version = '1.9.2'
s.version = '1.12.1'
s.license = 'MIT'

s.summary = 'Rosette API gem that supports multilingual text-analytics.'
Expand All @@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.authors = ['Basis Technology Corp']
s.email = %q{[email protected]}
s.homepage = %q{https://developer.rosette.com/}
s.date = %q{2018-02-14}
s.date = %q{2019-02-08}

all_files = `git ls-files -z`.split("\x0")
s.files = all_files.grep(%r{^(bin|lib)/|^.rubocop.yml$})
Expand Down
70 changes: 45 additions & 25 deletions tests/tests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "language"}', headers: {})
end
it 'test language' do
Expand Down Expand Up @@ -63,7 +63,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "morphology/complete"}', headers: {})
end
it 'test morphology complete' do
Expand All @@ -84,7 +84,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "morphology/compound-components"}', headers: {})
end
it 'test morphology compound components' do
Expand All @@ -105,7 +105,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "morphology/han-readings"}', headers: {})
end
it 'test morphology han readings' do
Expand All @@ -126,7 +126,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "morphology/parts-of-speech"}', headers: {})
end
it 'test morphology parts of speech' do
Expand All @@ -147,7 +147,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "morphology/lemmas"}', headers: {})
end
it 'test morphology lemmas' do
Expand All @@ -168,7 +168,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "entities"}', headers: {})
end
it 'test entities' do
Expand All @@ -190,7 +190,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "entities"}', headers: {})
end
it 'test entities without qids' do
Expand Down Expand Up @@ -221,7 +221,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "categories"}', headers: {})
end
it 'test categories' do
Expand All @@ -242,7 +242,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "relationships"}', headers: {})
end
it 'test relationships' do
Expand All @@ -264,7 +264,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "name-translation"}', headers: {})
end
it 'test name translation' do
Expand All @@ -291,7 +291,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "name-similarity"}', headers: {})
end
it 'test name similarity' do
Expand Down Expand Up @@ -329,7 +329,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {})

nothresh_json = { names: names.map(&:load_param) }.to_json
Expand All @@ -342,7 +342,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {})
end
it 'test name deduplication' do
Expand Down Expand Up @@ -393,7 +393,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "transliteration"}', headers: {})
end
it 'test transliteration' do
Expand Down Expand Up @@ -426,7 +426,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "tokens"}', headers: {})
end
it 'test tokens' do
Expand All @@ -447,7 +447,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "topics"}', headers: {})
end
it 'test topics' do
Expand All @@ -468,7 +468,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "sentences"}', headers: {})
end
it 'test sentences' do
Expand Down Expand Up @@ -519,7 +519,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2',
'X-Rosetteapi-Binding-Version' => '1.12.1',
'X-RosetteApi-App' => 'ruby-app' })
.to_return(status: 200, body: '{"test": "language"}', headers: {})
end
Expand All @@ -546,23 +546,43 @@
end
end

describe '.get_text_embedding' do
describe '.get_similar_terms' do
before do
stub_request(:post, 'https://api.rosette.com/rest/v1/text-embedding')
stub_request(:post, 'https://api.rosette.com/rest/v1/semantics/similar')
.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' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "language"}', headers: {})
end
it 'test text_embedding' do
it 'test similar_terms' do
params = DocumentParameters.new(content: @content, options: { "resultLanguages" => [ "spa", "deu", "jpn" ] })
response = RosetteAPI.new('0123456789').get_similar_terms(params)
expect(response).instance_of? Hash
end
end

describe '.get_semantic_vectors' do
before do
stub_request(:post, 'https://api.rosette.com/rest/v1/semantics/vector')
.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' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "language"}', headers: {})
end
it 'test semantic_vectors' do
params = DocumentParameters.new
params.content = @content
response = RosetteAPI.new('0123456789').get_text_embedding(params)
response = RosetteAPI.new('0123456789').get_semantic_vectors(params)
expect(response).instance_of? Hash
end
end
Expand All @@ -577,7 +597,7 @@
'User-Agent' => @user_agent,
'X-Rosetteapi-Key' => '0123456789',
'X-Rosetteapi-Binding' => 'ruby',
'X-Rosetteapi-Binding-Version' => '1.9.2' })
'X-Rosetteapi-Binding-Version' => '1.12.1' })
.to_return(status: 200, body: '{"test": "language"}', headers: {})
end
it 'test syntax_dependencies' do
Expand Down

0 comments on commit 2b81602

Please sign in to comment.