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 Jan 17, 2018
2 parents 4ffe5b3 + 62d8a97 commit 4184b5f
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 65 deletions.
4 changes: 3 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ node {
checkout scm
}
stage("Test with Docker") {
withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) {
echo "${env.ALT_URL}"
def useUrl = ("${env.ALT_URL}" == "null") ? "${env.BINDING_TEST_URL}" : "${env.ALT_URL}"
withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${useUrl}"]) {
sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-ruby"
}
}
Expand Down
7 changes: 4 additions & 3 deletions Jenkinsfile.examples
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ node {
}
stage("Build Dockerfile") {
dir ("${DOCKERFILE_DIR}") {
docker.build("${TEST_CONTAINER}")
sh "docker build --no-cache -t ${TEST_CONTAINER} ."
}
}
stage("Run Examples") {
withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) {
sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source ${TEST_CONTAINER}"
echo "${env.ALT_URL}"
def useUrl = ("${env.ALT_URL}" == "null") ? "${env.BINDING_TEST_URL}" : "${env.ALT_URL}"
withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${useUrl}"]) { sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source ${TEST_CONTAINER}"
}
}
slack(true)
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 = "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)
Expand Down
2 changes: 1 addition & 1 deletion examples/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
rosette_api = RosetteAPI.new(api_key, url)
end

entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS"
entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country."
begin
params = DocumentParameters.new(content: entities_text_data, genre: 'social-media')
response = rosette_api.get_entities(params)
Expand Down
20 changes: 20 additions & 0 deletions examples/language_multilingual.rb
Original file line number Diff line number Diff line change
@@ -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

language_multilingual_data = "On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times. Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان."
begin
params = DocumentParameters.new(content: language_multilingual_data)
params.rosette_options = { 'multilingual' => 'true' }
params.custom_headers = { 'X-RosetteAPI-App' => 'ruby-app' }
response = rosette_api.get_language(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
2 changes: 1 addition & 1 deletion examples/morphology_complete.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

morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did."
morphology_complete_data = "The quick brown fox jumped over the lazy dog. 👍🏾 Yes he did. B)"
begin
params = DocumentParameters.new(content: morphology_complete_data)
response = rosette_api.get_morphology_complete(params)
Expand Down
2 changes: 1 addition & 1 deletion examples/name_deduplication.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

name_dedupe_data = 'John Smith,Johnathon Smith,Fred Jones'
name_dedupe_data = "Alice Terry,Alice Thierry,Betty Grable,Betty Gable,Norma Shearer,Norm Shearer,Brigitte Helm,Bridget Helem,Judy Holliday,Julie Halliday"

threshold = 0.75
names = name_dedupe_data.split(',').map { |n| NameParameter.new(n) }
Expand Down
4 changes: 2 additions & 2 deletions examples/name_similarity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
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)
Expand Down
2 changes: 1 addition & 1 deletion examples/name_translation.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

translated_name_data = 'معمر محمد أبو منيار القذاف'
translated_name_data = "معمر محمد أبو منيار القذاف"
begin
params = NameTranslationParameters.new(translated_name_data, 'eng', target_script: 'Latn')
response = rosette_api.get_name_translation(params)
Expand Down
2 changes: 1 addition & 1 deletion examples/relationships.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

relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist."
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' }
Expand Down
2 changes: 1 addition & 1 deletion examples/sentences.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

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."
sentences_data = "This land is your land. This land is my land, from California to the New York island; from the red wood forest to the Gulf Stream waters. This land was made for you and Me. As I was walking that ribbon of highway, I saw above me that endless skyway: I saw below me that golden valley: This land was made for you and me."

begin
params = DocumentParameters.new
Expand Down
2 changes: 1 addition & 1 deletion examples/sentiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end

file = Tempfile.new(%w[foo .html])
sentiment_file_data = '<html><head><title>New Ghostbusters Film</title></head><body><p>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.”</p></body></html>'
sentiment_file_data = "<html><head><title>New Ghostbusters Film</title></head><body><p>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.”</p></body></html>"
file.write(sentiment_file_data)
file.close
begin
Expand Down
2 changes: 1 addition & 1 deletion examples/syntax_dependencies.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

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)
Expand Down
2 changes: 1 addition & 1 deletion examples/text_embedding.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

embeddings_data = 'Cambridge, Massachusetts'
embeddings_data = "Cambridge, Massachusetts"
begin
params = DocumentParameters.new(content: embeddings_data)
response = rosette_api.get_text_embedding(params)
Expand Down
2 changes: 1 addition & 1 deletion examples/tokens.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

tokens_data = '北京大学生物系主任办公室内部会议'
tokens_data = "北京大学生物系主任办公室内部会议"
begin
params = DocumentParameters.new(content: tokens_data)
response = rosette_api.get_tokens(params)
Expand Down
6 changes: 6 additions & 0 deletions lib/request_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ class RequestBuilder
attr_accessor :user_key
# Rosette API binding version
attr_accessor :binding_version
# User-Agent string
attr_reader :user_agent

def initialize(user_key, alternate_url, http_client, params = {}, url_parameters = nil, binding_version)
@user_key = user_key
@alternate_url = alternate_url
@http_client = http_client
@params = params
@binding_version = binding_version
@user_agent = 'Ruby/' + binding_version + '/' + RUBY_VERSION

return unless url_parameters
@alternate_url = @alternate_url + '?' + URI.encode_www_form(url_parameters)
Expand Down Expand Up @@ -61,6 +64,7 @@ def prepare_plain_request(params)
request['X-RosetteAPI-Key'] = @user_key
request['Content-Type'] = 'application/json'
request['Accept'] = 'application/json'
request['User-Agent'] = @user_agent
request['X-RosetteAPI-Binding'] = 'ruby'
request['X-RosetteAPI-Binding-Version'] = @binding_version
request.body = params.to_json
Expand Down Expand Up @@ -123,6 +127,7 @@ def prepare_multipart_request(params)
end

request.add_field 'Content-Type', "multipart/form-data; boundary=#{boundary}"
request.add_field 'User-Agent', @user_agent
request.add_field 'X-RosetteAPI-Key', @user_key
request.add_field 'X-RosetteAPI-Binding', 'ruby'
request.add_field 'X-RosetteAPI-Binding-Version', @binding_version
Expand All @@ -143,6 +148,7 @@ def send_get_request
raise RosetteAPIError.new 'connectionError', 'Failed to establish connection with Rosette API server.'
end
request['X-RosetteAPI-Key'] = @user_key
request['User-Agent'] = @user_agent

get_response @http_client, request
end
Expand Down
7 changes: 6 additions & 1 deletion 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.8.0'
BINDING_VERSION = '1.9.0'
# Rosette API language endpoint
LANGUAGE_ENDPOINT = '/language'.freeze
# Rosette API morphology endpoint
Expand Down Expand Up @@ -398,6 +398,11 @@ def ping
.send_get_request
end

# Gets the User-Agent string
def user_agent
RequestBuilder.new(@user_key, @alternate_url + PING, @http_client, @url_parameters, BINDING_VERSION).user_agent
end

private

# Checks that the right parameter type is being passed in.
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.8.0'
s.version = '1.9.0'
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{2017-10-24}
s.date = %q{2018-01-17}

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

0 comments on commit 4184b5f

Please sign in to comment.