Skip to content

Commit 2b81602

Browse files
committed
Merge branch 'develop'
2 parents 26700e7 + cd498c8 commit 2b81602

File tree

8 files changed

+111
-36
lines changed

8 files changed

+111
-36
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
node {
1+
node ("docker-light") {
22
def SOURCEDIR = pwd()
33
try {
44
stage("Clean up") {

examples/categories.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
rosette_api = RosetteAPI.new(api_key, url)
99
end
1010

11-
categories_url_data = "http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/"
11+
categories_url_data = "https://onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/"
1212
begin
1313
params = DocumentParameters.new(content_uri: categories_url_data)
1414
response = rosette_api.get_categories(params)

examples/relationships.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
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."
1212
begin
1313
params = DocumentParameters.new(content: relationships_text_data)
14-
params.rosette_options = { accuracyMode: 'PRECISION' }
1514
response = rosette_api.get_relationships(params)
1615
puts JSON.pretty_generate(response)
1716
rescue RosetteAPIError => rosette_api_error
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
rosette_api = RosetteAPI.new(api_key, url)
99
end
1010

11-
embeddings_data = "Cambridge, Massachusetts"
11+
semantic_vectors_data = "Cambridge, Massachusetts"
1212
begin
13-
params = DocumentParameters.new(content: embeddings_data)
14-
response = rosette_api.get_text_embedding(params)
13+
params = DocumentParameters.new(content: semantic_vectors_data)
14+
response = rosette_api.get_semantic_vectors(params)
1515
puts JSON.pretty_generate(response)
1616
rescue RosetteAPIError => rosette_api_error
1717
printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message)

examples/similar_terms.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'rosette_api'
2+
3+
api_key, url = ARGV
4+
5+
if !url
6+
rosette_api = RosetteAPI.new(api_key)
7+
else
8+
rosette_api = RosetteAPI.new(api_key, url)
9+
end
10+
11+
similar_terms_data = "spy"
12+
begin
13+
params = DocumentParameters.new(content: similar_terms_data)
14+
params.rosette_options = { "resultLanguages" => ["spa", "deu", "jpn"] }
15+
response = rosette_api.get_similar_terms(params)
16+
puts JSON.pretty_generate(response)
17+
rescue RosetteAPIError => rosette_api_error
18+
printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message)
19+
end

lib/rosette_api.rb

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# This class allows you to access all Rosette API endpoints.
1111
class RosetteAPI
1212
# Version of Ruby binding
13-
BINDING_VERSION = '1.9.2'
13+
BINDING_VERSION = '1.12.1'
1414
# Rosette API language endpoint
1515
LANGUAGE_ENDPOINT = '/language'.freeze
1616
# Rosette API morphology endpoint
@@ -37,8 +37,12 @@ class RosetteAPI
3737
INFO = '/info'.freeze
3838
# Rosette API ping endpoint
3939
PING = '/ping'.freeze
40-
# Text Embedding endpoint
40+
# Text Embedding endpoint (deprecated)
4141
TEXT_EMBEDDING = '/text-embedding'.freeze
42+
# Semantic Vectors endpoint (replaces /text-embedding)
43+
SEMANTIC_VECTORS = '/semantics/vector'.freeze
44+
# Similar Terms endpoint
45+
SIMILAR_TERMS_ENDPOINT = '/semantics/similar'.freeze
4246
# Syntactic Dependencies endpoint
4347
SYNTACTIC_DEPENDENCIES_ENDPOINT = '/syntax/dependencies'.freeze
4448
# Transliteration endpoint
@@ -320,11 +324,13 @@ def get_sentences(params)
320324
#
321325
# Returns the vectors associated with the text
322326
#
327+
# Deprecated. Please use `get_semantic_vectors` instead
328+
#
323329
# ==== Attributes
324330
#
325331
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
326332
#
327-
# Returns list of linguistic sentences of the input.
333+
# Returns the text embedding representation of the input.
328334
def get_text_embedding(params)
329335
check_params params
330336

@@ -341,6 +347,21 @@ def get_text_embedding(params)
341347
#
342348
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
343349
#
350+
# Returns the text embedding representation of the input.
351+
def get_semantic_vectors(params)
352+
check_params params
353+
params = params.load_params
354+
RequestBuilder.new(@user_key, @alternate_url + SEMANTIC_VECTORS, @http_client, params, @url_parameters, BINDING_VERSION)
355+
.send_post_request
356+
end
357+
358+
#
359+
# Returns the syntactic structure of the text
360+
#
361+
# ==== Attributes
362+
#
363+
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
364+
#
344365
# Returns list of linguistic sentences of the input.
345366
def get_syntax_dependencies(params)
346367
check_params params
@@ -384,6 +405,22 @@ def get_topics(params)
384405
.send_post_request
385406
end
386407

408+
# Returns the terms similar to the input
409+
#
410+
# ==== Attributes
411+
#
412+
# * +params+ - DocumentParameters helps to build the request body in RequestBuilder.
413+
#
414+
# Returns a mapping of languageCode to similar terms
415+
def get_similar_terms(params)
416+
check_params params
417+
418+
params = params.load_params
419+
420+
RequestBuilder.new(@user_key, @alternate_url + SIMILAR_TERMS_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION)
421+
.send_post_request
422+
end
423+
387424
# Gets information about the Rosette API, returns name, build number
388425
# and build time.
389426
def info

rosette_api.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
88
s.required_ruby_version = '>= 2.0.0'
99

1010
s.name = 'rosette_api'
11-
s.version = '1.9.2'
11+
s.version = '1.12.1'
1212
s.license = 'MIT'
1313

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

2424
all_files = `git ls-files -z`.split("\x0")
2525
s.files = all_files.grep(%r{^(bin|lib)/|^.rubocop.yml$})

tests/tests_spec.rb

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
'User-Agent' => @user_agent,
3030
'X-Rosetteapi-Key' => '0123456789',
3131
'X-Rosetteapi-Binding' => 'ruby',
32-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
32+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
3333
.to_return(status: 200, body: '{"test": "language"}', headers: {})
3434
end
3535
it 'test language' do
@@ -63,7 +63,7 @@
6363
'User-Agent' => @user_agent,
6464
'X-Rosetteapi-Key' => '0123456789',
6565
'X-Rosetteapi-Binding' => 'ruby',
66-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
66+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
6767
.to_return(status: 200, body: '{"test": "morphology/complete"}', headers: {})
6868
end
6969
it 'test morphology complete' do
@@ -84,7 +84,7 @@
8484
'User-Agent' => @user_agent,
8585
'X-Rosetteapi-Key' => '0123456789',
8686
'X-Rosetteapi-Binding' => 'ruby',
87-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
87+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
8888
.to_return(status: 200, body: '{"test": "morphology/compound-components"}', headers: {})
8989
end
9090
it 'test morphology compound components' do
@@ -105,7 +105,7 @@
105105
'User-Agent' => @user_agent,
106106
'X-Rosetteapi-Key' => '0123456789',
107107
'X-Rosetteapi-Binding' => 'ruby',
108-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
108+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
109109
.to_return(status: 200, body: '{"test": "morphology/han-readings"}', headers: {})
110110
end
111111
it 'test morphology han readings' do
@@ -126,7 +126,7 @@
126126
'User-Agent' => @user_agent,
127127
'X-Rosetteapi-Key' => '0123456789',
128128
'X-Rosetteapi-Binding' => 'ruby',
129-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
129+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
130130
.to_return(status: 200, body: '{"test": "morphology/parts-of-speech"}', headers: {})
131131
end
132132
it 'test morphology parts of speech' do
@@ -147,7 +147,7 @@
147147
'User-Agent' => @user_agent,
148148
'X-Rosetteapi-Key' => '0123456789',
149149
'X-Rosetteapi-Binding' => 'ruby',
150-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
150+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
151151
.to_return(status: 200, body: '{"test": "morphology/lemmas"}', headers: {})
152152
end
153153
it 'test morphology lemmas' do
@@ -168,7 +168,7 @@
168168
'User-Agent' => @user_agent,
169169
'X-Rosetteapi-Key' => '0123456789',
170170
'X-Rosetteapi-Binding' => 'ruby',
171-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
171+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
172172
.to_return(status: 200, body: '{"test": "entities"}', headers: {})
173173
end
174174
it 'test entities' do
@@ -190,7 +190,7 @@
190190
'User-Agent' => @user_agent,
191191
'X-Rosetteapi-Key' => '0123456789',
192192
'X-Rosetteapi-Binding' => 'ruby',
193-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
193+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
194194
.to_return(status: 200, body: '{"test": "entities"}', headers: {})
195195
end
196196
it 'test entities without qids' do
@@ -221,7 +221,7 @@
221221
'User-Agent' => @user_agent,
222222
'X-Rosetteapi-Key' => '0123456789',
223223
'X-Rosetteapi-Binding' => 'ruby',
224-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
224+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
225225
.to_return(status: 200, body: '{"test": "categories"}', headers: {})
226226
end
227227
it 'test categories' do
@@ -242,7 +242,7 @@
242242
'User-Agent' => @user_agent,
243243
'X-Rosetteapi-Key' => '0123456789',
244244
'X-Rosetteapi-Binding' => 'ruby',
245-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
245+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
246246
.to_return(status: 200, body: '{"test": "relationships"}', headers: {})
247247
end
248248
it 'test relationships' do
@@ -264,7 +264,7 @@
264264
'User-Agent' => @user_agent,
265265
'X-Rosetteapi-Key' => '0123456789',
266266
'X-Rosetteapi-Binding' => 'ruby',
267-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
267+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
268268
.to_return(status: 200, body: '{"test": "name-translation"}', headers: {})
269269
end
270270
it 'test name translation' do
@@ -291,7 +291,7 @@
291291
'User-Agent' => @user_agent,
292292
'X-Rosetteapi-Key' => '0123456789',
293293
'X-Rosetteapi-Binding' => 'ruby',
294-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
294+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
295295
.to_return(status: 200, body: '{"test": "name-similarity"}', headers: {})
296296
end
297297
it 'test name similarity' do
@@ -329,7 +329,7 @@
329329
'User-Agent' => @user_agent,
330330
'X-Rosetteapi-Key' => '0123456789',
331331
'X-Rosetteapi-Binding' => 'ruby',
332-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
332+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
333333
.to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {})
334334

335335
nothresh_json = { names: names.map(&:load_param) }.to_json
@@ -342,7 +342,7 @@
342342
'User-Agent' => @user_agent,
343343
'X-Rosetteapi-Key' => '0123456789',
344344
'X-Rosetteapi-Binding' => 'ruby',
345-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
345+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
346346
.to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {})
347347
end
348348
it 'test name deduplication' do
@@ -393,7 +393,7 @@
393393
'User-Agent' => @user_agent,
394394
'X-Rosetteapi-Key' => '0123456789',
395395
'X-Rosetteapi-Binding' => 'ruby',
396-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
396+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
397397
.to_return(status: 200, body: '{"test": "transliteration"}', headers: {})
398398
end
399399
it 'test transliteration' do
@@ -426,7 +426,7 @@
426426
'User-Agent' => @user_agent,
427427
'X-Rosetteapi-Key' => '0123456789',
428428
'X-Rosetteapi-Binding' => 'ruby',
429-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
429+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
430430
.to_return(status: 200, body: '{"test": "tokens"}', headers: {})
431431
end
432432
it 'test tokens' do
@@ -447,7 +447,7 @@
447447
'User-Agent' => @user_agent,
448448
'X-Rosetteapi-Key' => '0123456789',
449449
'X-Rosetteapi-Binding' => 'ruby',
450-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
450+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
451451
.to_return(status: 200, body: '{"test": "topics"}', headers: {})
452452
end
453453
it 'test topics' do
@@ -468,7 +468,7 @@
468468
'User-Agent' => @user_agent,
469469
'X-Rosetteapi-Key' => '0123456789',
470470
'X-Rosetteapi-Binding' => 'ruby',
471-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
471+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
472472
.to_return(status: 200, body: '{"test": "sentences"}', headers: {})
473473
end
474474
it 'test sentences' do
@@ -519,7 +519,7 @@
519519
'User-Agent' => @user_agent,
520520
'X-Rosetteapi-Key' => '0123456789',
521521
'X-Rosetteapi-Binding' => 'ruby',
522-
'X-Rosetteapi-Binding-Version' => '1.9.2',
522+
'X-Rosetteapi-Binding-Version' => '1.12.1',
523523
'X-RosetteApi-App' => 'ruby-app' })
524524
.to_return(status: 200, body: '{"test": "language"}', headers: {})
525525
end
@@ -546,23 +546,43 @@
546546
end
547547
end
548548

549-
describe '.get_text_embedding' do
549+
describe '.get_similar_terms' do
550550
before do
551-
stub_request(:post, 'https://api.rosette.com/rest/v1/text-embedding')
551+
stub_request(:post, 'https://api.rosette.com/rest/v1/semantics/similar')
552552
.with(body: @json,
553553
headers: { 'Accept' => 'application/json',
554554
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
555555
'Content-Type' => 'application/json',
556556
'User-Agent' => @user_agent,
557557
'X-Rosetteapi-Key' => '0123456789',
558558
'X-Rosetteapi-Binding' => 'ruby',
559-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
559+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
560560
.to_return(status: 200, body: '{"test": "language"}', headers: {})
561561
end
562-
it 'test text_embedding' do
562+
it 'test similar_terms' do
563+
params = DocumentParameters.new(content: @content, options: { "resultLanguages" => [ "spa", "deu", "jpn" ] })
564+
response = RosetteAPI.new('0123456789').get_similar_terms(params)
565+
expect(response).instance_of? Hash
566+
end
567+
end
568+
569+
describe '.get_semantic_vectors' do
570+
before do
571+
stub_request(:post, 'https://api.rosette.com/rest/v1/semantics/vector')
572+
.with(body: @json,
573+
headers: { 'Accept' => 'application/json',
574+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
575+
'Content-Type' => 'application/json',
576+
'User-Agent' => @user_agent,
577+
'X-Rosetteapi-Key' => '0123456789',
578+
'X-Rosetteapi-Binding' => 'ruby',
579+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
580+
.to_return(status: 200, body: '{"test": "language"}', headers: {})
581+
end
582+
it 'test semantic_vectors' do
563583
params = DocumentParameters.new
564584
params.content = @content
565-
response = RosetteAPI.new('0123456789').get_text_embedding(params)
585+
response = RosetteAPI.new('0123456789').get_semantic_vectors(params)
566586
expect(response).instance_of? Hash
567587
end
568588
end
@@ -577,7 +597,7 @@
577597
'User-Agent' => @user_agent,
578598
'X-Rosetteapi-Key' => '0123456789',
579599
'X-Rosetteapi-Binding' => 'ruby',
580-
'X-Rosetteapi-Binding-Version' => '1.9.2' })
600+
'X-Rosetteapi-Binding-Version' => '1.12.1' })
581601
.to_return(status: 200, body: '{"test": "language"}', headers: {})
582602
end
583603
it 'test syntax_dependencies' do

0 commit comments

Comments
 (0)