diff --git a/.travis.yml b/.travis.yml index a01758e..93764f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,8 @@ language: node_js node_js: - - "0.11.16" - - "0.12.7" - - "1.0.4" - - "4.2.4" - - "4.4.7" - "6.3.0" + - "7.2.0" + - "8.0.0" before_install: - npm install -g npm before_script: diff --git a/README.md b/README.md index 77c4bab..7bbe406 100644 --- a/README.md +++ b/README.md @@ -37,23 +37,24 @@ api.rosette(endpoint, function(err, res){ ## API Parameters | Parameter | Endpoint | Required | ------------- |------------- |------------- -| content | categories, entities, language, morphology, relationships, sentences, sentiment, tokens | Either content or contentUri required | +| content | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, transliteration | Either content or contentUri required, transliteration requires content only | | contentUri | categories, entities, language, morphology, relationships, sentences, sentiment, tokens | Either content or contentUri required | | language | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, name similarity | No | | documentFile | categories, entities, language, morphology, relationships, sentences, sentiment, tokens | No | | name1 | name similarity | Yes | | name2 | name similarity| Yes | | name | name translation | Yes | -| targetLanguage | name translation | Yes | +| names | name deduplication | Yes | +| targetLanguage | name translation, transliteration (No) | Yes | | entityType | name translation | No | | sourceLanguageOfOrigin | name translation | No | | sourceLanguageOfUse | name translation | No | -| sourceScript | name translation | No | -| targetScript | name translation | No | +| sourceLanguage | transliteration | No | +| sourceScript | name translation, transliteration | No | +| targetScript | name translation, transliteration | No | | targetScheme | name translation | No | | options | relationships | No | | accuracyMode | relationships | Yes | -| linkEntities | entities | No | | explain | sentiment | No | | morphology | morphology | Yes | diff --git a/examples/name_deduplication.js b/examples/name_deduplication.js new file mode 100644 index 0000000..db98f5b --- /dev/null +++ b/examples/name_deduplication.js @@ -0,0 +1,29 @@ +"use strict"; + +var Api = require("../lib/Api"); +var ArgumentParser = require("argparse").ArgumentParser; + +var parser = new ArgumentParser({ + addHelp: true, + description: "Deduplicate a list of names" +}); +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 = "nameDeduplication"; + +var name_dedupe_data = "John Smith,Johnathon Smith,Fred Jones"; + +api.parameters.names = name_dedupe_data.split(",").map(function(name) { + return {"text": name, "language": "eng", "entityType": "PERSON"} +}); +api.parameters.threshold = 0.75; + +api.rosette(endpoint, function(err, res){ + if(err){ + console.log(err); + } else { + console.log(JSON.stringify(res, null, 2)); + } +}); diff --git a/examples/syntax_dependencies.js b/examples/syntax_dependencies.js index 58600bd..146407a 100644 --- a/examples/syntax_dependencies.js +++ b/examples/syntax_dependencies.js @@ -16,7 +16,6 @@ var endpoint = "syntax_dependencies"; var syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday."; api.parameters.content = syntax_dependencies_data; -api.parameters.genre = "social-media"; api.rosette(endpoint, function(err, res){ if(err){ console.log(err); diff --git a/examples/transliteration.js b/examples/transliteration.js new file mode 100644 index 0000000..e9ca696 --- /dev/null +++ b/examples/transliteration.js @@ -0,0 +1,27 @@ +"use strict"; + +var Api = require("../lib/Api"); +var ArgumentParser = require("argparse").ArgumentParser; + +var parser = new ArgumentParser({ + addHelp: true, + description: "Get the transliteration from 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 = "transliteration"; + +var transliteration_data = "Bill Gates, Microsoft's former CEO, is a philanthropist."; + +api.parameters.content = transliteration_data; + +api.rosette(endpoint, function(err, res) { + if (err) { + console.log(err); + } else { + console.log(JSON.stringify(res, null, 2)); + } +}); diff --git a/lib/Api.js b/lib/Api.js index c3b95cf..4358efd 100644 --- a/lib/Api.js +++ b/lib/Api.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -26,6 +26,7 @@ var entities = require("./entities"); var info = require("./info"); var language = require("./language"); var matchedName = require("./nameSimilarity"); +var nameDeduplication = require("./nameDeduplication"); var morphology = require("./morphology"); var ping = require("./ping"); var relationships = require("./relationships"); @@ -35,6 +36,7 @@ var textEmbedding = require("./textEmbedding"); var translatedName = require("./nameTranslation"); var tokens = require("./tokens"); var syntax_dependencies = require("./syntax_dependencies"); +var transliteration = require("./transliteration"); /** * @class @@ -44,7 +46,7 @@ var syntax_dependencies = require("./syntax_dependencies"); * Api server endpoints. * * @example var api = new API(userKey, serviceUrl); - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function Api(userKey, serviceURL) { diff --git a/lib/categories.js b/lib/categories.js index 08e7ab3..6071ede 100644 --- a/lib/categories.js +++ b/lib/categories.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function categories() { diff --git a/lib/entities.js b/lib/entities.js index cbd7391..64668aa 100644 --- a/lib/entities.js +++ b/lib/entities.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function entities() { @@ -50,10 +50,10 @@ entities.prototype.getResults = function(parameters, userKey, protocol, serviceU } else { // configure URL var urlParts = URL.parse(serviceURL + "entities"); - + var req = new rosetteRequest(); req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback); - + } } diff --git a/lib/info.js b/lib/info.js index cd9baf3..879b328 100644 --- a/lib/info.js +++ b/lib/info.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function info() { diff --git a/lib/language.js b/lib/language.js index dcfe637..64cbf02 100644 --- a/lib/language.js +++ b/lib/language.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function language() { diff --git a/lib/morphology.js b/lib/morphology.js index de885eb..4983f1b 100644 --- a/lib/morphology.js +++ b/lib/morphology.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function morphology() { diff --git a/lib/nameDeduplication.js b/lib/nameDeduplication.js new file mode 100644 index 0000000..707a651 --- /dev/null +++ b/lib/nameDeduplication.js @@ -0,0 +1,57 @@ +/** + * Rosette API. + * + * @copyright 2016-2017 Basis Technology Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * @license http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + **/ +"use strict"; + +var URL = require("url"); + +var rosetteConstants = require("./rosetteConstants"); +var RosetteException = require("./rosetteExceptions"); +var rosetteRequest = require("./rosetteRequest"); + +/** + * @class + * + * @copyright 2016-2017 Basis Technology Corporation. + * @license http://www.apache.org/licenses/LICENSE-2.0 + */ +function nameDeduplication() { + +}; + +/** + * Makes an HTTP request to the specified Rosette API endpoint and returns the result + * @param {string} parameters - The Rosette API endpoint parameters + * @param {string} userKey - The Rosette API user access key + * @param {string} serviceURL - The base service URL to be used to access the Rosette API + * @param {function} callback - Callback function to be exectuted after the function to which it is passed is complete + */ +nameDeduplication.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) { + + if (parameters.documentFile != null) { + return callback(new RosetteException("badArgument", "nameDeduplication does not support documentFile")); + } else { + // validate parameters + if (parameters.loadParams().names == null) { + return callback(new RosetteException("badArgument", "Must supply a list of names for deduplication")); + } else { + // configure URL + var urlParts = URL.parse(serviceURL + "name-deduplication"); + var req = new rosetteRequest(); + req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback); + } + } + +}; + +module.exports = nameDeduplication; diff --git a/lib/nameSimilarity.js b/lib/nameSimilarity.js index 64a7a21..9e535f5 100644 --- a/lib/nameSimilarity.js +++ b/lib/nameSimilarity.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function nameSimilarity() { @@ -39,7 +39,7 @@ function nameSimilarity() { nameSimilarity.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) { if (parameters.documentFile != null) { - parameters.loadFile(parameters.documentFile, parameters, userKey, protocol, serviceURL, "name-similarity", callback); + return callback(new RosetteException("badArgument", "Name similarity does not support documentFile", "bad arguments")); } else { // validate parameters diff --git a/lib/nameTranslation.js b/lib/nameTranslation.js index ba2b864..8a89a90 100644 --- a/lib/nameTranslation.js +++ b/lib/nameTranslation.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function nameTranslation() { @@ -39,12 +39,12 @@ function nameTranslation() { nameTranslation.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) { if (parameters.documentFile != null) { - parameters.loadFile(parameters.documentFile, parameters, userKey, protocol, serviceURL, "name-translation", callback); + return callback(new RosetteException("badArgument", "Name translation does not support documentFile", "bad arguments")); } else { // validate parameters if (parameters.loadParams().name == null) { - return callback(new RosetteException("badArgument", "Must name parameter", "bad arguments")); + return callback(new RosetteException("badArgument", "Must supply name parameter", "bad arguments")); } else if (parameters.loadParams().targetLanguage == null) { return callback(new RosetteException("badArgument", "Must supply target language parameter", "bad arguments")); } else { diff --git a/lib/parameters.js b/lib/parameters.js index 8c1d737..5d120dd 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -35,7 +35,7 @@ var BINDING_VERSION = "1.1"; /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function parameters() { @@ -51,6 +51,10 @@ function parameters() { this.name1 = null; this.name2 = null; + // name deduplication parameters + this.names = null; + this.threshold = null; + // name translation parameters this.name = null; this.targetLanguage = null; @@ -61,6 +65,9 @@ function parameters() { this.targetScript = null; this.targetScheme = null; + // transliteration parameters + this.sourceLanguage = null; + //relationships parameters this.options = null; this.accuracyMode = null; @@ -94,10 +101,13 @@ parameters.prototype.loadParams = function() { "name1": this.name1, "name2": this.name2, "name": this.name, + "names": this.names, + "threshold": this.threshold, "targetLanguage": this.targetLanguage, "entityType": this.entityType, "sourceLanguageOfOrigin": this.sourceLanguageOfOrigin, "sourceLanguageOfUse": this.sourceLanguageOfUse, + "sourceLanguage": this.sourceLanguage, "sourceScript": this.sourceScript, "targetScript": this.targetScript, "targetScheme": this.targetScheme, @@ -152,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, "X-RosetteAPI-Binding": "nodejs", "X-RosetteAPI-Binding-Version": BINDING_VERSION } diff --git a/lib/ping.js b/lib/ping.js index 5e74484..6730053 100644 --- a/lib/ping.js +++ b/lib/ping.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function ping() { diff --git a/lib/relationships.js b/lib/relationships.js index 3d660f5..7deba4b 100644 --- a/lib/relationships.js +++ b/lib/relationships.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function relationships() { diff --git a/lib/rosetteConstants.js b/lib/rosetteConstants.js index fd06ccb..c3c3fcc 100644 --- a/lib/rosetteConstants.js +++ b/lib/rosetteConstants.js @@ -1,7 +1,7 @@ /** * Container for the Rosette Constants. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at diff --git a/lib/rosetteExceptions.js b/lib/rosetteExceptions.js index 893128c..e407a88 100644 --- a/lib/rosetteExceptions.js +++ b/lib/rosetteExceptions.js @@ -1,7 +1,7 @@ /** * RosetteException. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at diff --git a/lib/rosetteRequest.js b/lib/rosetteRequest.js index 309d1ef..e2969ab 100644 --- a/lib/rosetteRequest.js +++ b/lib/rosetteRequest.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -28,12 +28,12 @@ var querystring = require('querystring'); * * @type string */ -var BINDING_VERSION = "1.5.0"; +var BINDING_VERSION = "1.7.0"; /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function rosetteRequest() { @@ -82,7 +82,7 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol, path: path, method: requestType, headers: headers, - agent: false + agent: false }; if (urlParts.port) { diff --git a/lib/sentences.js b/lib/sentences.js index f3d347b..c26d488 100644 --- a/lib/sentences.js +++ b/lib/sentences.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function sentences() { diff --git a/lib/sentiment.js b/lib/sentiment.js index d95ab77..e3935a3 100644 --- a/lib/sentiment.js +++ b/lib/sentiment.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function sentiment() { diff --git a/lib/syntax_dependencies.js b/lib/syntax_dependencies.js index d12feac..b6817f8 100644 --- a/lib/syntax_dependencies.js +++ b/lib/syntax_dependencies.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function syntax_dependencies() { @@ -40,7 +40,7 @@ syntax_dependencies.prototype.getResults = function(parameters, userKey, protoco if (parameters.documentFile != null) { parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, protocol, serviceURL, "syntax/dependencies", callback); - + } else { // validate parameters @@ -53,10 +53,10 @@ syntax_dependencies.prototype.getResults = function(parameters, userKey, protoco var urlParts = URL.parse(serviceURL + "syntax/dependencies"); } - + var req = new rosetteRequest(); req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback); - + } }; diff --git a/lib/textEmbedding.js b/lib/textEmbedding.js index 7e44af6..505be14 100644 --- a/lib/textEmbedding.js +++ b/lib/textEmbedding.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function textEmbedding() { diff --git a/lib/tokens.js b/lib/tokens.js index 6fd0540..af40ff7 100644 --- a/lib/tokens.js +++ b/lib/tokens.js @@ -1,7 +1,7 @@ /** * Rosette API. * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -22,7 +22,7 @@ var rosetteRequest = require("./rosetteRequest"); /** * @class * - * @copyright 2014-2015 Basis Technology Corporation. + * @copyright 2016-2017 Basis Technology Corporation. * @license http://www.apache.org/licenses/LICENSE-2.0 */ function tokens() { diff --git a/lib/transliteration.js b/lib/transliteration.js new file mode 100644 index 0000000..f9e9a84 --- /dev/null +++ b/lib/transliteration.js @@ -0,0 +1,58 @@ +/** + * Rosette API. + * + * @copyright 2016-2017 Basis Technology Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * @license http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + **/ +"use strict"; + +var URL = require("url"); + +var rosetteConstants = require("./rosetteConstants"); +var RosetteException = require("./rosetteExceptions"); +var rosetteRequest = require("./rosetteRequest"); + +/** + * @class + * + * @copyright 2016-2017 Basis Technology Corporation. + * @license http://www.apache.org/licenses/LICENSE-2.0 + */ +function transliteration() { + +}; + +/** + * Makes an HTTP request to the specified Rosette API endpoint and returns the result + * @param {string} parameters - The Rosette API endpoint parameters + * @param {string} userKey - The Rosette API user access key + * @param {string} serviceURL - The base service URL to be used to access the Rosette API + * @param {function} callback - Callback function to be exectuted after the function to which it is passed is complete + */ +transliteration.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) { + + if (parameters.documentFile != null) { + parameters.loadFile(parameters.documentFile, parameters, userKey, protocol, serviceURL, "transliteration", callback); + } else { + + // validate parameters + if (parameters.loadParams().content == null) { + return callback(new RosetteException("badArgument", "Must supply Content", "bad arguments")); + } + + // configure URL + var urlParts = URL.parse(serviceURL + "transliteration"); + var req = new rosetteRequest(); + req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback); + } + +}; + +module.exports = transliteration; diff --git a/package.json b/package.json index 289286f..4b9595a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rosette-api", - "version": "1.5.0", + "version": "1.7.0", "description": "Rosette API Node.js client SDK", "main": "index", "directories": { diff --git a/tests/unittests.js b/tests/unittests.js index 998a6ae..78b8760 100644 --- a/tests/unittests.js +++ b/tests/unittests.js @@ -8,6 +8,7 @@ var fs = require('fs'); var Api = require("../lib/Api"); var language = require("../lib/language"); var relationships = require("../lib/relationships"); +var nameDeduplication = require("../lib/nameDeduplication"); var nameSimilarity = require("../lib/nameSimilarity"); var nameTranslation = require("../lib/nameTranslation"); var sentiment = require("../lib/sentiment"); @@ -42,7 +43,7 @@ describe("Language Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the language endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Sample Content"; @@ -78,7 +79,6 @@ describe("Language Endpoint", function() { done(); }); }); - }); describe("Relationships Endpoint", function() { @@ -101,7 +101,7 @@ describe("Relationships Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the relationships endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Sample Content"; @@ -126,7 +126,72 @@ describe("Relationships Endpoint", function() { done(); }); }); +}); + +describe("Name Deduplication Endpoint", function() { + beforeEach(function(done) { + var mockResponse = JSON.stringify({'name': 'Rosette API', 'versionChecked': true}); + + nock('https://api.rosette.com', {"encodedQueryParams": true }) + .post('/rest/v1/info') + .query({"clientVersion": "1.1"}) + .reply(200, JSON.parse(mockResponse)); + + nock('https://api.rosette.com', {"encodedQueryParams": true }) + .post('/rest/v1/name-deduplication') + .query({"clientVersion": "1.1"}) + .reply(200, JSON.parse(mockResponse)); + done(); + }); + + afterEach(function(done) { + nock.cleanAll(); + done(); + }); + + it("successfully calls the name deduplication endpoint", function(done) { + var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); + + api.parameters.names = [ + {"text": "John Smith", "language": "eng", "entityType": "PERSON"}, + {"text": "Johnathon Smith", "language": "eng", "entityType": "PERSON"}, + {"text": "Fred Jones Smith", "language": "eng", "entityType": "PERSON"} + ]; + api.parameters.threshold = 0.75; + + api.rosette("nameDeduplication", function(err, res) { + chai.expect(err).to.be.null; + chai.expect(res.name).to.equal('Rosette API'); + done(); + }); + }); + + it("successfully calls the name deduplication endpoint without threshold", function(done) { + var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); + + api.parameters.names = [ + {"text": "John Smith", "language": "eng", "entityType": "PERSON"}, + {"text": "Johnathon Smith", "language": "eng", "entityType": "PERSON"}, + {"text": "Fred Jones Smith", "language": "eng", "entityType": "PERSON"} + ]; + + api.rosette("nameDeduplication", function(err, res) { + chai.expect(err).to.be.null; + chai.expect(res.name).to.equal('Rosette API'); + done(); + }); + }); + + it("detects missing names parameter", function(done) { + var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); + api.rosette("nameSimilarity", function(err, res) { + chai.expect(err).to.not.be.null; + chai.expect(err.name).to.equal('RosetteException'); + chai.expect(err.message).to.contain('badArgument'); + done(); + }); + }); }); describe("Name Similarity Endpoint", function() { @@ -149,7 +214,7 @@ describe("Name Similarity Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the name similarity endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); var name_similarity_data1 = "Michael Jackson"; @@ -179,7 +244,6 @@ describe("Name Similarity Endpoint", function() { done(); }); }); - }); describe("Name Translation Endpoint", function() { @@ -202,7 +266,7 @@ describe("Name Translation Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the name translation endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.name = "Some Name"; @@ -242,7 +306,6 @@ describe("Name Translation Endpoint", function() { done(); }); }); - }); describe("Sentiment Endpoint", function() { @@ -265,7 +328,7 @@ describe("Sentiment Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the sentiment endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Some Content"; @@ -301,7 +364,6 @@ describe("Sentiment Endpoint", function() { done(); }); }); - }); describe("Categories Endpoint", function() { @@ -324,7 +386,7 @@ describe("Categories Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the categories endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Some Content"; @@ -383,7 +445,7 @@ describe("Entities Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the entities endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Some Content"; @@ -419,7 +481,6 @@ describe("Entities Endpoint", function() { done(); }); }); - }); describe("Morphology Endpoint (suite covers all features)", function() { @@ -442,7 +503,7 @@ describe("Morphology Endpoint (suite covers all features)", function() { nock.cleanAll(); done(); }); - + it("successfully calls the morphology endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Some Content"; @@ -494,8 +555,6 @@ describe("Morphology Endpoint (suite covers all features)", function() { done(); }); }); - - }); describe("Tokens Endpoint", function() { @@ -518,7 +577,7 @@ describe("Tokens Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the tokens endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Some Content"; @@ -554,7 +613,6 @@ describe("Tokens Endpoint", function() { done(); }); }); - }); describe("Sentences Endpoint", function() { @@ -577,7 +635,7 @@ describe("Sentences Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the sentences endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Some Content"; @@ -613,7 +671,6 @@ describe("Sentences Endpoint", function() { done(); }); }); - }); describe("Text Embedding Endpoint", function() { @@ -631,7 +688,7 @@ describe("Text Embedding Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the textEmbedding endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Some Content"; @@ -667,7 +724,6 @@ describe("Text Embedding Endpoint", function() { done(); }); }); - }); describe("Syntactic Dependencies Endpoint", function() { @@ -690,7 +746,7 @@ describe("Syntactic Dependencies Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the syntactic dependencies endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.parameters.content = "Some Content"; @@ -726,7 +782,51 @@ describe("Syntactic Dependencies Endpoint", function() { done(); }); }); +}); + +describe("Transliteration Endpoint", function() { + beforeEach(function(done) { + var mockResponse = JSON.stringify({'name': 'Rosette API', 'versionChecked': true}); + + nock('https://api.rosette.com', {"encodedQueryParams": true }) + .post('/rest/v1/info') + .query({"clientVersion": "1.1"}) + .reply(200, JSON.parse(mockResponse)); + + nock('https://api.rosette.com', {"encodedQueryParams": true }) + .post('/rest/v1/transliteration') + .query({"clientVersion": "1.1"}) + .reply(200, JSON.parse(mockResponse)); + done(); + }); + + afterEach(function(done) { + nock.cleanAll(); + done(); + }); + + it("successfully calls the transliteration endpoint", function(done) { + var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); + api.parameters.content = "Some Content"; + + api.rosette("transliteration", function(err, res) { + chai.expect(err).to.be.null; + chai.expect(res.name).to.equal('Rosette API'); + done(); + }); + + }); + + it("detects content parameter is not defined", function(done) { + var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); + api.rosette("transliteration", function(err, res) { + chai.expect(err).to.not.be.null; + chai.expect(err.name).to.equal('RosetteException'); + chai.expect(err.message).to.contain('badArgument'); + done(); + }); + }); }); describe("Info Endpoint", function() { @@ -748,7 +848,7 @@ describe("Info Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the info endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); @@ -757,9 +857,7 @@ describe("Info Endpoint", function() { chai.expect(res.name).to.equal('Rosette API'); done(); }); - }); - }); describe("Ping Endpoint", function() { @@ -781,7 +879,7 @@ describe("Ping Endpoint", function() { nock.cleanAll(); done(); }); - + it("successfully calls the ping endpoint", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); @@ -790,7 +888,6 @@ describe("Ping Endpoint", function() { chai.expect(res.name).to.equal('Rosette API'); done(); }); - }); }); @@ -813,7 +910,7 @@ describe("Error 409 Incompatible Binding Check", function() { nock.cleanAll(); done(); }); - + it("successfully handles the error", function(done) { var api = new Api('123456789', 'https://api.rosette.com/rest/v1'); api.rosette("info", function(err, res) { @@ -823,5 +920,4 @@ describe("Error 409 Incompatible Binding Check", function() { done(); }); }); - });