Skip to content

Commit d0e0177

Browse files
author
Chris Park
committed
Merge branch 'develop' of github.com:rosette-api/nodejs into develop
2 parents d7086aa + 994a817 commit d0e0177

File tree

13 files changed

+49
-140
lines changed

13 files changed

+49
-140
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ api.rosette(endpoint, function(err, res){
4444
| targetScheme | name translation | No |
4545
| options | relationships | No |
4646
| accuracyMode | relationships | Yes |
47-
| linked | entities | No |
47+
| linkEntities | entities | No |
4848
| explain | sentiment | No |
4949
| morphology | morphology | Yes |
5050

docker/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ MAINTAINER Sam Hausmann
44
#install necessary packages
55
RUN apt-get -y update && apt-get install -y git && apt-get install -y vim && apt-get install -y curl
66

7+
RUN npm install -g grunt-cli && npm install -g eslint
8+
79
ENV API_KEY api_key
810

911
RUN mkdir /nodejs-dev
@@ -13,5 +15,5 @@ RUN chmod 0755 /nodejs-dev/runAll.sh
1315
#set the working directory
1416
WORKDIR /nodejs-dev
1517

16-
CMD ./runAll.sh $API_KEY $FILENAME $ALT_URL $GIT_USERNAME $GIT_EMAIL $VERSION
18+
CMD ./runAll.sh
1719
VOLUME ["/source"]

docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Build the docker image, e.g. `docker build -t basistech/nodejs:1.1 .`
99

1010
Run an example as `docker run -e API_KEY=api-key -v "path-to-local-nodejs-dir:/source" basistech/nodejs:1.1`
1111

12-
To test against a specific source file, add `-e FILENAME=filename` before the `-v`, to test against an alternate url, add `-e ALT_URL=alternate_url`, and optionally if you would like to regenerate gh-pages from the changes made to the development source you can add `-e GIT_USERNAME=git-username -e VERSION=version` before the `-v`. In order to push the gh-pages to git remember to mount .ssh and .gitconfig to the root dir `-v path-to-.ssh-dir:/root/.ssh -v path-to-.gitconfig:/root/.gitconfig`.
12+
To test against a specific source file, add `-e FILENAME=filename` before the `-v`, to test against an alternate url, add `-e ALT_URL=alternate_url`.

docker/runAll.sh

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
ping_url="https://api.rosette.com/rest/v1/"
44
retcode=0
5+
errors=( "Exception" "processingFailure" "badRequest" "ParseError" "ValueError" "SyntaxError" "AttributeError" "ImportError" )
56

67
#------------------- Functions -------------------------------------
78

@@ -11,12 +12,14 @@ function HELP {
1112
echo " API_KEY - Rosette API key (required)"
1213
echo " FILENAME - Python source file (optional)"
1314
echo " ALT_URL - Alternate service URL (optional)"
14-
echo " GIT_USERNAME - Git username where you would like to push regenerated gh-pages (optional)"
15-
echo " VERSION - Build version (optional)"
1615
echo "Compiles and runs the source file(s) using the local development source."
1716
exit 1
1817
}
1918

19+
if [ ! -z ${ALT_URL} ]; then
20+
ping_url=${ALT_URL}
21+
fi
22+
2023
#Checks if Rosette API key is valid
2124
function checkAPI() {
2225
match=$(curl "${ping_url}ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
@@ -56,38 +59,27 @@ function runExample() {
5659
fi
5760
echo "${result}"
5861
echo -e "\n---------- ${1} end -------------"
59-
if [[ $result == *"Exception"* ]]; then
60-
retcode=1
61-
elif [[ $result == *"processingFailure"* ]]; then
62-
retcode=1
63-
fi
62+
for err in "${errors[@]}"; do
63+
if [[ ${result} == *"${err}"* ]]; then
64+
retcode=1
65+
fi
66+
done
6467
}
6568

6669

6770
#------------------- Functions End ----------------------------------
6871

6972
#Gets API_KEY, FILENAME and ALT_URL if present
70-
while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
73+
while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
7174
case "${arg}" in
7275
API_KEY)
7376
API_KEY=${OPTARG}
74-
usage
7577
;;
7678
ALT_URL)
7779
ALT_URL=${OPTARG}
78-
usage
7980
;;
8081
FILENAME)
8182
FILENAME=${OPTARG}
82-
usage
83-
;;
84-
GIT_USERNAME)
85-
GIT_USERNAME=${OPTARG}
86-
usage
87-
;;
88-
VERSION)
89-
VERSION={OPTARG}
90-
usage
9183
;;
9284
esac
9385
done
@@ -100,15 +92,11 @@ validateURL
10092
cp -r -n /source/. .
10193

10294
#Run unit tests
103-
npm install -g grunt-cli
104-
npm install -g eslint
10595
npm install
10696
grunt test
10797
#run eslint
10898
eslint lib/*.js
10999

110-
111-
112100
#Run the examples
113101
if [ ! -z ${API_KEY} ]; then
114102
checkAPI
@@ -117,8 +105,10 @@ if [ ! -z ${API_KEY} ]; then
117105
npm install argparse
118106
npm install temporary
119107
if [ ! -z ${FILENAME} ]; then
108+
echo -e "\nRunning example against: ${ping_url}\n"
120109
runExample ${FILENAME}
121110
else
111+
echo -e "\nRunning examples against: ${ping_url}\n"
122112
for file in *.js; do
123113
runExample $file
124114
done
@@ -128,11 +118,5 @@ else
128118
retcode=1
129119
fi
130120

131-
#Generate gh-pages and push them to git account (if git username is provided)
132-
if [ ! -z ${GIT_USERNAME} ]; then
133-
134-
grunt doc
135-
fi
136-
137121
exit ${retcode}
138122

examples/entities.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ var api = new Api(args.key, args.url);
1515
var endpoint = "entities";
1616

1717
api.parameters.content = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS";
18-
18+
api.parameters.genre = "social-media";
19+
// to improve performance, and if you don't need the QID, set this option
20+
// api.parameters.options = { "linkEntities": false };
1921
api.rosette(endpoint, function(err, res){
2022
if(err){
2123
console.log(err);

examples/entities_linked.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/language.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ parser.addArgument(["--url"], {help: "Rosette API alt-url", required: false});
1212
var args = parser.parseArgs();
1313
var api = new Api(args.key, args.url);
1414
var endpoint = "language";
15+
var appHeader = [];
16+
appHeader[0] = "X-RosetteAPI-App"
17+
appHeader[1] = "app";
18+
api.parameters.customHeaders = [appHeader];
1519

1620
var content = "Por favor Señorita, says the man.";
1721

1822
api.parameters.content = content;
23+
var appHeader = [];
24+
appHeader[0] = "X-RosetteAPI-App"
25+
appHeader[1] = "app";
26+
api.parameters.customHeaders = [appHeader];
1927

2028
api.rosette(endpoint, function(err, res){
2129
if(err){

lib/.Rhistory

Whitespace-only changes.

lib/entities.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ function entities() {
3939
entities.prototype.getResults = function(parameters, userKey, serviceURL, callback) {
4040

4141
if (parameters.loadParams().documentFile != null) {
42-
if (parameters.loadParams().linked == true) {
43-
parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, serviceURL, "entities/linked", callback);
44-
} else {
45-
parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, serviceURL, "entities", callback);
46-
}
47-
42+
parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, serviceURL, "entities", callback);
43+
4844
} else {
4945

5046
// validate parameters
@@ -54,11 +50,8 @@ entities.prototype.getResults = function(parameters, userKey, serviceURL, callba
5450
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
5551
} else {
5652
// configure URL
57-
if (parameters.loadParams().linked == true) {
58-
var urlParts = URL.parse(serviceURL + "entities/linked");
59-
} else {
60-
urlParts = URL.parse(serviceURL + "entities");
61-
}
53+
var urlParts = URL.parse(serviceURL + "entities");
54+
6255
var req = new rosetteRequest();
6356
req.makeRequest('POST', userKey, urlParts, parameters, callback);
6457
}

lib/parameters.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ function parameters() {
6363
this.options = null;
6464
this.accuracyMode = null;
6565

66-
//entities parameters
67-
this.linked = null;
68-
6966
//sentiment parameters
7067
this.explain = null;
7168
this.shortString = null;
7269

7370
//morphology
7471
this.morphology = null;
7572

73+
//headers
74+
this.customHeaders = null;
75+
7676
}
7777

7878
/**
@@ -98,16 +98,16 @@ parameters.prototype.loadParams = function() {
9898
"targetScript": this.targetScript,
9999
"targetScheme": this.targetScheme,
100100
"options": this.options,
101-
"linked": this.linked,
102101
"explain": this.explain,
103102
"short-string": this.shortString,
104103
"morphology": this.morphology,
105104
"_maxRetries": this.maxRetries,
106-
"_msInterval": this.msInterval
105+
"_msInterval": this.msInterval,
106+
"_customHeaders": this.customHeaders
107107
};
108108

109109
for (var key in paramJSON) {
110-
if (key.substring(0, 1) !== '_' && paramJSON[key] != null) {
110+
if (key.substring(0, 1) !== '_' && paramJSON[key] != null && key != "customHeaders") {
111111
tempJSON[key] = paramJSON[key];
112112
}
113113
}

0 commit comments

Comments
 (0)