diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..4330a17 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,28 @@ +node { + def SOURCEDIR = pwd() + try { + stage("Clean up") { + step([$class: 'WsCleanup']) + } + stage("Checkout Code") { + checkout scm + } + stage("Test with Docker") { + 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 rosetteapi/docker-ruby" + } + } + slack(true) + } catch (e) { + currentBuild.result = "FAILED" + slack(false) + throw e + } +} + +def slack(boolean success) { + def color = success ? "#00FF00" : "#FF0000" + def status = success ? "SUCCESSFUL" : "FAILED" + def message = status + ": Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})" + slackSend(color: color, channel: "#rapid", message: message) +} \ No newline at end of file diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples new file mode 100644 index 0000000..00a6627 --- /dev/null +++ b/Jenkinsfile.examples @@ -0,0 +1,35 @@ +node { + def SOURCEDIR = pwd() + def TEST_CONTAINER = 'examples/ruby-test' + def DOCKERFILE_DIR = './examples/docker' + try { + stage("Clean up") { + step([$class: 'WsCleanup']) + } + stage("Checkout Code") { + checkout scm + } + stage("Build Dockerfile") { + dir ("${DOCKERFILE_DIR}") { + docker.build("${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}" + } + } + slack(true) + } catch (e) { + currentBuild.result = "FAILED" + slack(false) + throw e + } +} + +def slack(boolean success) { + def color = success ? "#00FF00" : "#FF0000" + def status = success ? "SUCCESSFUL" : "FAILED" + def message = status + ": Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})" + slackSend(color: color, channel: "#rapid", message: message) +} \ No newline at end of file diff --git a/README.md b/README.md index 6976bc5..ab146ee 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,15 @@ See the wiki for more information. `gem install rosette_api` +If the version you are using is not [the latest from RubyGems](https://rubygems.org/gems/rosette_api), +please check for its [**compatibilty with api.rosette.com**](https://developer.rosette.com/features-and-functions?ruby). +If you have an on-premise version of Rosette API server, please contact support for +binding compatibility with your installation. + +To check your installed version: + +`gem list rosette_api` + ## Docker ## A Docker image for running the examples against the compiled source library is available on Docker Hub. @@ -21,9 +30,10 @@ Additional environment settings: See [examples](examples) ## API Documentation ## - See [documentation](http://rosette-api.github.io/ruby) -## Additional Information ## +## Release Notes +See the [wiki](https://github.com/rosette-api/ruby/wiki/Release-Notes) +## Additional Information ## Visit [Rosette API site](https://developer.rosette.com) diff --git a/examples/README.md b/examples/README.md index 571a7e4..30d1335 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,27 +11,28 @@ For example, run `ruby categories.js ` if you want to see the categori functionality demonstrated. All files require you to input your Rosette API User Key after `--key` to run. -For example: `ruby ping.js 1234567890` +For example: `ruby ping.js 1234567890` To run all of the examples: `find -maxdepth 1 -name *.rb -exec ruby {} api_key alternate_url` Each example, when run, prints its output to the console. -| File Name | What it does | +| File Name | What it does | | ------------- |------------- | -| categories.rb | Gets the category of a document at a URL | -| entities.rb | Gets the entities from a piece of text | -| info.rb | Gets information about Rosette API | -| language.rb | Gets the language of a piece of text | +| categories.rb | Gets the category of a document at a URL | +| entities.rb | Gets the entities from a piece of text | +| info.rb | Gets information about Rosette API | +| language.rb | Gets the language of a piece of text | | name_similarity.rb | Gets the similarity score of two names | -| morphology_complete.rb | Gets the complete morphological analysis of a piece of text| +| morphology_complete.rb | Gets the complete morphological analysis of a piece of text| | morphology_compound_components.rb | Gets the de-compounded words from a piece of text | | morphology_han_readings.rb | Gets the Chinese words from a piece of text | -| morphology_lemmas.rb | Gets the lemmas of words from a piece of text | +| morphology_lemmas.rb | Gets the lemmas of words from a piece of text | | morphology_parts_of_speech.rb | Gets the part-of-speech tags for words in a piece of text | -| ping.rb | Pings the Rosette API to check for reachability | +| ping.rb | Pings the Rosette API to check for reachability | | sentences.rb | Gets the sentences from a piece of text | -| sentiment.rb | Gets the sentiment of a local file | -| tokens.rb | Gets the tokens (words) from a piece of text | +| sentiment.rb | Gets the sentiment of a local file | +| tokens.rb | Gets the tokens (words) from a piece of text | +| topics.rb | Gets the key phrases and concepts from a piece of text | | name_translation.rb | Translates a name from one language to another | diff --git a/examples/topics.rb b/examples/topics.rb new file mode 100644 index 0000000..9376efc --- /dev/null +++ b/examples/topics.rb @@ -0,0 +1,18 @@ +require 'rosette_api' + +api_key, url = ARGV + +if !url + rosette_api = RosetteAPI.new(api_key) +else + rosette_api = RosetteAPI.new(api_key, url) +end + +topics_data = "Lily Collins is in talks to join Nicholas Hoult in Chernin Entertainment and Fox Searchlight's J.R.R. Tolkien biopic Tolkien. Anthony Boyle, known for playing Scorpius Malfoy in the British play Harry Potter and the Cursed Child, also has signed on for the film centered on the famed author. In Tolkien, Hoult will play the author of the Hobbit and Lord of the Rings book series that were later adapted into two Hollywood trilogies from Peter Jackson. Dome Karukoski is directing the project." +begin + params = DocumentParameters.new(content: topics_data) + response = rosette_api.get_topics(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/rosette_api.rb b/lib/rosette_api.rb index 2384354..2b03ac4 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.7.0' + BINDING_VERSION = '1.8.0' # Rosette API language endpoint LANGUAGE_ENDPOINT = '/language'.freeze # Rosette API morphology endpoint @@ -43,6 +43,9 @@ class RosetteAPI SYNTACTIC_DEPENDENCIES_ENDPOINT = '/syntax/dependencies'.freeze # Transliteration endpoint TRANSLITERATION_ENDPOINT = '/transliteration'.freeze + # Topics endpoint + TOPICS_ENDPOINT = '/topics'.freeze + # Rosette API key attr_accessor :user_key @@ -365,6 +368,22 @@ def get_transliteration(params) .send_post_request end + # Divides the input into topics (key phrases and concepts). + # + # ==== Attributes + # + # * +params+ - DocumentParameters helps to build the request body in RequestBuilder. + # + # Returns list of topics of the input. + def get_topics(params) + check_params params + + params = params.load_params + + RequestBuilder.new(@user_key, @alternate_url + TOPICS_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/rosette_api.gemspec b/rosette_api.gemspec index 5f39c71..23eb2a9 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.7.0' + s.version = '1.8.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{2017-06-14} + s.date = %q{2017-10-24} 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 336870c..195de7a 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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.0' }) .to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {}) end it 'test name deduplication' do @@ -342,7 +342,7 @@ 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) @@ -385,7 +385,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.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.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.0' }) .to_return(status: 200, body: '{"test": "tokens"}', headers: {}) end it 'test tokens' do @@ -429,6 +429,27 @@ end end + describe '.get_topics' do + before do + stub_request(:post, 'https://api.rosette.com/rest/v1/topics') + .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.8.0' }) + .to_return(status: 200, body: '{"test": "topics"}', headers: {}) + end + it 'test topics' do + params = DocumentParameters.new + params.content = @content + response = RosetteAPI.new('0123456789').get_topics(params) + expect(response).instance_of? Hash + end + end + describe '.get_sentences' do before do stub_request(:post, 'https://api.rosette.com/rest/v1/sentences') @@ -439,7 +460,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.0' }) .to_return(status: 200, body: '{"test": "sentences"}', headers: {}) end it 'test sentences' do @@ -490,7 +511,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.7.0', + 'X-Rosetteapi-Binding-Version' => '1.8.0', 'X-RosetteApi-App' => 'ruby-app' }) .to_return(status: 200, body: '{"test": "language"}', headers: {}) end @@ -527,7 +548,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.0' }) .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test text_embedding' do @@ -548,7 +569,7 @@ 'User-Agent' => 'Ruby', 'X-Rosetteapi-Key' => '0123456789', 'X-Rosetteapi-Binding' => 'ruby', - 'X-Rosetteapi-Binding-Version' => '1.7.0' }) + 'X-Rosetteapi-Binding-Version' => '1.8.0' }) .to_return(status: 200, body: '{"test": "language"}', headers: {}) end it 'test syntax_dependencies' do