diff --git a/Jenkinsfile b/Jenkinsfile index fd9203c..28b186e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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-nodejs" } } diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples index dcd9d95..ad76198 100644 --- a/Jenkinsfile.examples +++ b/Jenkinsfile.examples @@ -11,11 +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}"]) { + 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}"]) { def examplesDir = "${SOURCEDIR}" + '/examples' sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${examplesDir}:/source ${TEST_CONTAINER}" } diff --git a/examples/entities.js b/examples/entities.js index 146904b..f86682d 100644 --- a/examples/entities.js +++ b/examples/entities.js @@ -13,7 +13,7 @@ var args = parser.parseArgs(); var api = new Api(args.key, args.url); var endpoint = "entities"; -var 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"; +var 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."; api.parameters.content = entities_text_data; api.parameters.genre = "social-media"; diff --git a/examples/language_multilingual.js b/examples/language_multilingual.js new file mode 100644 index 0000000..2c5864a --- /dev/null +++ b/examples/language_multilingual.js @@ -0,0 +1,35 @@ +"use strict"; + +var Api = require("../lib/Api"); +var ArgumentParser = require("argparse").ArgumentParser; + +var parser = new ArgumentParser({ + addHelp: true, + description: "Determine the language of a piece of text" +}); +parser.addArgument(["--key"], {help: "Rosette API key", required: true}); +parser.addArgument(["--url"], {help: "Rosette API alt-url", required: false}); +var args = parser.parseArgs(); +var api = new Api(args.key, args.url); +var endpoint = "language"; +var appHeader = []; +appHeader[0] = "X-RosetteAPI-App" +appHeader[1] = "app"; +api.parameters.customHeaders = [appHeader]; + +var 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 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان."; + +api.parameters.content = language_multilingual_data; +var appHeader = []; +appHeader[0] = "X-RosetteAPI-App" +appHeader[1] = "app"; +api.parameters.customHeaders = [appHeader]; +api.parameters.options = { "multilingual": "true" }; + +api.rosette(endpoint, function(err, res){ + if(err){ + console.log(err); + } else { + console.log(JSON.stringify(res, null, 2)); + } +}); diff --git a/examples/morphology_complete.js b/examples/morphology_complete.js index 62f5d5e..f3152bb 100644 --- a/examples/morphology_complete.js +++ b/examples/morphology_complete.js @@ -13,7 +13,7 @@ var args = parser.parseArgs(); var api = new Api(args.key, args.url); var endpoint = "morphology"; -var morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did."; +var morphology_complete_data = "The quick brown fox jumped over the lazy dog. 👍🏾 Yes he did. B)"; var content = morphology_complete_data; api.parameters.content = content; diff --git a/examples/name_deduplication.js b/examples/name_deduplication.js index db98f5b..b03897d 100644 --- a/examples/name_deduplication.js +++ b/examples/name_deduplication.js @@ -13,7 +13,7 @@ var args = parser.parseArgs(); var api = new Api(args.key, args.url); var endpoint = "nameDeduplication"; -var name_dedupe_data = "John Smith,Johnathon Smith,Fred Jones"; +var name_dedupe_data = "Alice Terry,Alice Thierry,Betty Grable,Betty Gable,Norma Shearer,Norm Shearer,Brigitte Helm,Bridget Helem,Judy Holliday,Julie Halliday"; api.parameters.names = name_dedupe_data.split(",").map(function(name) { return {"text": name, "language": "eng", "entityType": "PERSON"} diff --git a/examples/relationships.js b/examples/relationships.js index ef0badf..2f44201 100644 --- a/examples/relationships.js +++ b/examples/relationships.js @@ -14,7 +14,7 @@ var args = parser.parseArgs(); var api = new Api(args.key, args.url); var endpoint = "relationships"; -var relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist."; +var 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."; var content = relationships_text_data; api.parameters.content = content; diff --git a/examples/sentences.js b/examples/sentences.js index b8a9e07..636e4e6 100644 --- a/examples/sentences.js +++ b/examples/sentences.js @@ -14,7 +14,7 @@ var args = parser.parseArgs(); var api = new Api(args.key, args.url); var endpoint = "sentences"; -var 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."; +var 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."; var content = sentences_data; api.parameters.content = content; diff --git a/examples/text_embedding.js b/examples/text_embedding.js index 232db98..c042a5f 100644 --- a/examples/text_embedding.js +++ b/examples/text_embedding.js @@ -13,7 +13,7 @@ var args = parser.parseArgs(); var api = new Api(args.key, args.url); var endpoint = "textEmbedding"; -var embeddings_data = 'Cambridge, Massachusetts' +var embeddings_data = "Cambridge, Massachusetts" api.parameters.content = embeddings_data; api.rosette(endpoint, function(err, res){ diff --git a/examples/transliteration.js b/examples/transliteration.js index e9ca696..6aab67b 100644 --- a/examples/transliteration.js +++ b/examples/transliteration.js @@ -14,7 +14,7 @@ var args = parser.parseArgs(); var api = new Api(args.key, args.url); var endpoint = "transliteration"; -var transliteration_data = "Bill Gates, Microsoft's former CEO, is a philanthropist."; +var transliteration_data = "ana r2ye7 el gam3a el sa3a 3 el 3asr"; api.parameters.content = transliteration_data; diff --git a/lib/parameters.js b/lib/parameters.js index 5d120dd..65dd743 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -46,6 +46,7 @@ function parameters() { this.language = null; this.documentFile = null; this.genre = null; + this.options = null; // name matching parameters this.name1 = null; @@ -69,7 +70,6 @@ function parameters() { this.sourceLanguage = null; //relationships parameters - this.options = null; this.accuracyMode = null; //sentiment parameters @@ -162,7 +162,7 @@ parameters.prototype.loadFile = function(filePath, loadedParameters, userKey, pr "accept": 'application/json', "accept-encoding": "gzip", "content-type": 'multipart/mixed', - "user-agent": "rosetteapinode/" + BINDING_VERSION, + "user-agent": "rosetteapinode/" + BINDING_VERSION + "/" + process.version, "X-RosetteAPI-Binding": "nodejs", "X-RosetteAPI-Binding-Version": BINDING_VERSION } diff --git a/lib/rosetteRequest.js b/lib/rosetteRequest.js index 41e1f1e..e0ac9a8 100644 --- a/lib/rosetteRequest.js +++ b/lib/rosetteRequest.js @@ -28,7 +28,8 @@ var querystring = require('querystring'); * * @type string */ -var BINDING_VERSION = "1.8.0"; +var BINDING_VERSION = "1.8.1"; +var USER_AGENT = "rosetteapinode/" + BINDING_VERSION + "/" + process.version; /** * @class @@ -41,6 +42,7 @@ function rosetteRequest() { }; rosetteRequest.prototype.bindingVersion = function() { return BINDING_VERSION; } +rosetteRequest.prototype.userAgent = function() { return USER_AGENT; } /** * Makes an HTTP request to the specified Rosette API endpoint and returns the result @@ -55,7 +57,7 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol, "accept": "application/json", "accept-encoding": "gzip", "content-type": "application/json", - "user-agent": "rosetteapinode/" + BINDING_VERSION, + "user-agent": USER_AGENT, "X-RosetteAPI-Binding": "nodejs", "X-RosetteAPI-Binding-Version": BINDING_VERSION } diff --git a/package.json b/package.json index 639d858..a214d79 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rosette-api", - "version": "1.8.0", + "version": "1.8.1", "description": "Rosette API Node.js client SDK", "main": "index", "directories": { diff --git a/tests/unittests.js b/tests/unittests.js index 72c6978..c46f339 100644 --- a/tests/unittests.js +++ b/tests/unittests.js @@ -23,6 +23,18 @@ var ping = require("../lib/ping"); var syntax_dependencies = require("../lib/syntax_dependencies"); var paramObj = require("../lib/parameters"); var rosetteException = require("../lib/rosetteExceptions"); +var rosetteRequest = require("../lib/rosetteRequest.js"); + +describe("User Agent", function() { + it("correctly constructs the User-Agent", function() { + var req = new rosetteRequest(); + var testUserAgent = "rosetteapinode/" + req.bindingVersion() + "/" + process.version; + + req.userAgent(function(err, res) { + chai.expect(res.name).to.equal(testUserAgent); + }); + }); +}); describe("Language Endpoint", function() { beforeEach(function(done) {