Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Park committed Oct 24, 2017
2 parents a2a55b4 + 1db4e61 commit 1726213
Show file tree
Hide file tree
Showing 25 changed files with 272 additions and 41 deletions.
28 changes: 28 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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-nodejs"
}
}
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)
}
36 changes: 36 additions & 0 deletions Jenkinsfile.examples
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
node {
def SOURCEDIR = pwd()
def TEST_CONTAINER = 'examples/nodejs-test'
def DOCKERFILE_DIR = './examples'
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}"]) {
def examplesDir = "${SOURCEDIR}" + '/examples'
sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${examplesDir}:/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)
}
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ This is the Rosette API client binding for node.js.
## Getting Started
Install the module with: `npm install rosette-api`

If the version you are using is not [the latest from npm](https://www.npmjs.com/package/rosette-api) (or `npm show rosette-api@* version`),
please check for its [**compatibilty with api.rosette.com**](https://developer.rosette.com/features-and-functions?javascript).
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:

- `npm list rosette-api` for local installation
- `npm list -g rosette-api` for global installation

https://www.npmjs.com/package/rosette-api

## Docker ##
A Docker image for running the examples against the compiled source library is available on Docker Hub.

Expand Down Expand Up @@ -37,10 +49,10 @@ api.rosette(endpoint, function(err, res){
## API Parameters
| Parameter | Endpoint | 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 |
| content | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, topics, transliteration | Either content or contentUri required, transliteration requires content only |
| contentUri | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, topics | Either content or contentUri required |
| language | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, topics, name similarity | No |
| documentFile | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, topics | No |
| name1 | name similarity | Yes |
| name2 | name similarity| Yes |
| name | name translation | Yes |
Expand All @@ -61,5 +73,11 @@ api.rosette(endpoint, function(err, res){
## Additional Examples
See [examples](examples).

## API Documentation
See [documentation](http://rosette-api.github.io/nodejs)

## Release Notes
See [wiki](https://github.com/rosette-api/nodejs/wiki/Release-Notes)

## Additional Information
See [Rosette API site](https://developer.rosette.com/)
4 changes: 2 additions & 2 deletions examples/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ RUN apt-get -y update && apt-get install -y git && apt-get install -y vim && apt
ENV API_KEY api_key

#set the working directory
RUN mkdir /nodejs-dev
WORKDIR /nodejs-dev
RUN mkdir -p /nodejs-dev/examples
WORKDIR /nodejs-dev/examples
COPY runAll.sh runAll.sh
RUN chmod 0755 runAll.sh

Expand Down
14 changes: 8 additions & 6 deletions examples/runAll.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function checkAPI() {
if [ ! -z $match ]; then
echo -e "\nInvalid Rosette API Key"
exit 1
fi
fi
}

# add the trailing slash of the alt_url if necessary
Expand All @@ -41,7 +41,7 @@ function validateURL() {
if [ "${match}" = "" ]; then
echo -e "\n${ping_url} server not responding\n"
exit 1
fi
fi
}

function runExample() {
Expand Down Expand Up @@ -93,19 +93,21 @@ cp -r -n /source/. .
#Run the examples
if [ ! -z ${API_KEY} ]; then
checkAPI
#Prerequisite
cd ./examples
npm install rosette-api
cp -r node_modules/rosette-api/lib ../lib
pushd ../lib
npm install multipart-stream
popd
npm install argparse
npm install temporary
npm install multipart-stream
if [ ! -z ${FILENAME} ]; then
runExample ${FILENAME}
else
for file in *.js; do
runExample ${file}
done
fi
else
else
HELP
fi

Expand Down
26 changes: 26 additions & 0 deletions examples/topics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

var Api = require("../lib/Api");
var ArgumentParser = require("argparse").ArgumentParser;

var parser = new ArgumentParser({
addHelp: true,
description: "Get the key phrases and concepts in 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 = "topics";

var 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."
var content = topics_data;
api.parameters.content = content;

api.rosette(endpoint, function(err, res){
if(err){
console.log(err);
} else {
console.log(JSON.stringify(res, null, 2));
}
});
1 change: 1 addition & 0 deletions lib/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var translatedName = require("./nameTranslation");
var tokens = require("./tokens");
var syntax_dependencies = require("./syntax_dependencies");
var transliteration = require("./transliteration");
var topics = require("./topics");

/**
* @class
Expand Down
2 changes: 1 addition & 1 deletion lib/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ categories.prototype.getResults = function(parameters, userKey, protocol, servic
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of content or contentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
return callback(new RosetteException("badArgument", "Cannot supply content and contentUri", "bad arguments"));
Expand Down
4 changes: 2 additions & 2 deletions lib/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ entities.prototype.getResults = function(parameters, userKey, protocol, serviceU
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else {
// configure URL
Expand Down
4 changes: 2 additions & 2 deletions lib/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ language.prototype.getResults = function(parameters, userKey, protocol, serviceU
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else {
// configure URL
Expand Down
6 changes: 3 additions & 3 deletions lib/morphology.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ morphology.prototype.getResults = function(parameters, userKey, protocol, servic
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else if (parameters.morphology == null) {
} else if (!parameters.morphology) {
return callback(new RosetteException("badArgument", "Must supply type of morphology", "bad arguments"));
} else {
// configure URL
Expand Down
2 changes: 1 addition & 1 deletion lib/nameDeduplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nameDeduplication.prototype.getResults = function(parameters, userKey, protocol,
return callback(new RosetteException("badArgument", "nameDeduplication does not support documentFile"));
} else {
// validate parameters
if (parameters.loadParams().names == null) {
if (!parameters.loadParams().names) {
return callback(new RosetteException("badArgument", "Must supply a list of names for deduplication"));
} else {
// configure URL
Expand Down
2 changes: 1 addition & 1 deletion lib/nameSimilarity.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ nameSimilarity.prototype.getResults = function(parameters, userKey, protocol, se
} else {

// validate parameters
if (parameters.loadParams().name1 == null || parameters.loadParams().name2 == null) {
if (!parameters.loadParams().name1 || !parameters.loadParams().name2) {
return callback(new RosetteException("badArgument", "Must supply both name1 and name2 parameters to be matched."));
} else {
// configure URL
Expand Down
4 changes: 2 additions & 2 deletions lib/nameTranslation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ nameTranslation.prototype.getResults = function(parameters, userKey, protocol, s
} else {

// validate parameters
if (parameters.loadParams().name == null) {
if (!parameters.loadParams().name) {
return callback(new RosetteException("badArgument", "Must supply name parameter", "bad arguments"));
} else if (parameters.loadParams().targetLanguage == null) {
} else if (!parameters.loadParams().targetLanguage) {
return callback(new RosetteException("badArgument", "Must supply target language parameter", "bad arguments"));
} else {
// configure URL
Expand Down
4 changes: 2 additions & 2 deletions lib/relationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ relationships.prototype.getResults = function(parameters, userKey, protocol, ser
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rosetteRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var querystring = require('querystring');
*
* @type string
*/
var BINDING_VERSION = "1.7.0";
var BINDING_VERSION = "1.8.0";

/**
* @class
Expand Down
4 changes: 2 additions & 2 deletions lib/sentences.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ sentences.prototype.getResults = function(parameters, userKey, protocol, service
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else {
// configure URL
Expand Down
4 changes: 2 additions & 2 deletions lib/sentiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ sentiment.prototype.getResults = function(parameters, userKey, protocol, service
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else {

Expand Down
4 changes: 2 additions & 2 deletions lib/syntax_dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ syntax_dependencies.prototype.getResults = function(parameters, userKey, protoco
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else {
// configure URL
Expand Down
4 changes: 2 additions & 2 deletions lib/textEmbedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ textEmbedding.prototype.getResults = function(parameters, userKey, protocol, ser
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else {
// configure URL
Expand Down
4 changes: 2 additions & 2 deletions lib/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ tokens.prototype.getResults = function(parameters, userKey, protocol, serviceURL
} else {

// validate parameters
if (parameters.loadParams().content == null && parameters.loadParams().contentUri == null) {
if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", "bad arguments"));
} else if (parameters.loadParams().content != null && parameters.loadParams().contentUri != null) {
} else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
} else {
// configure URL
Expand Down
Loading

0 comments on commit 1726213

Please sign in to comment.