Skip to content

Commit dea2b0a

Browse files
author
Chris Park
committed
Updated all examples to accept an alternate URL. Corrected the README and added some copy explaining how to run all of the examples.
1 parent b419065 commit dea2b0a

19 files changed

+59
-37
lines changed

examples/README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ You can run your desired `_endpoint_.js` file to see it in action.
77
For example, run `node categories.js --key <your_key>` if you want to see the categories
88
functionality demonstrated.
99

10+
If you would like to run against an alternate url, you can use the optional --url <alt_url> argument.
11+
12+
To run all of the examples, use the command line:
13+
`find -maxdepth 1 -name "*.js" -exec node {} --key api_key --url alt_url \;`
14+
1015
All files require you to input your Rosette API User Key after `--key` to run.
1116
For example: `node ping.js --key 1234567890`
1217

1318
Each example, when run, prints its output to the console.
1419

1520
| File Name | What it does |
1621
| ------------- |------------- |
17-
| categories.php | Gets the category of a document at a URL |
18-
| entities.php | Gets the entities from a piece of text |
19-
| entities_linked.php | Gets the linked (to Wikipedia) entities from a piece of text |
20-
| info.php | Gets information about Rosette API |
21-
| language.php | Gets the language of a piece of text |
22-
| matched-name.php | Gets the similarity score of two names |
23-
| morphology_complete.php | Gets the complete morphological analysis of a piece of text|
24-
| morphology_compound-components.php | Gets the de-compounded words from a piece of text |
25-
| morphology_han-readings.php | Gets the Chinese words from a piece of text |
26-
| morphology_lemmas.php | Gets the lemmas of words from a piece of text |
27-
| morphology_parts-of-speech.php | Gets the part-of-speech tags for words in a piece of text |
28-
| ping.php | Pings the Rosette API to check for reachability |
29-
| sentences.php | Gets the sentences from a piece of text |
30-
| sentiment.php | Gets the sentiment of a local file |
31-
| tokens.php | Gets the tokens (words) from a piece of text |
32-
| translated-name.php | Translates a name from one language to another |
22+
| base64_input.js | Gets the entities from a piece of base64 encoded text |
23+
| categories.js | Gets the category of a document at a URL |
24+
| entities.js | Gets the entities from a piece of text |
25+
| entities_linked.js | Gets the linked (to Wikipedia) entities from a piece of text |
26+
| info.js | Gets information about Rosette API |
27+
| language.js | Gets the language of a piece of text |
28+
| matched-name.js | Gets the similarity score of two names |
29+
| morphology_complete.js | Gets the complete morphological analysis of a piece of text|
30+
| morphology_compound-components.js | Gets the de-compounded words from a piece of text |
31+
| morphology_han-readings.js | Gets the Chinese words from a piece of text |
32+
| morphology_lemmas.js | Gets the lemmas of words from a piece of text |
33+
| morphology_parts-of-speech.js | Gets the part-of-speech tags for words in a piece of text |
34+
| ping.js | Pings the Rosette API to check for reachability |
35+
| sentences.js | Gets the sentences from a piece of text |
36+
| sentiment.js | Gets the sentiment of a local file |
37+
| tokens.js | Gets the tokens (words) from a piece of text |
38+
| translated-name.js | Translates a name from one language to another |

examples/base64_input.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var parser = new ArgumentParser({
1414
description: "Get the entities from a piece of text"
1515
});
1616
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
17+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1718
var args = parser.parseArgs();
1819

1920
var docParams = new DocumentParameters();
@@ -23,7 +24,7 @@ var content = new Buffer(entities_text_data).toString('base64');
2324
docParams.setItem("content", content);
2425
docParams.setItem("contentType", rosetteConstants.dataFormat.UNSPECIFIED);
2526

26-
var api = new Api(args.key);
27+
var api = new Api(args.key, args.url);
2728
api.entities(docParams, false, function(err, res) {
2829
if (err) {
2930
throw err;

examples/categories.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ var parser = new ArgumentParser({
1414
});
1515
var categories_url_data = "http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/";
1616
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
17-
parser.addArgument(["--url"], {help: "Optional URL for data",
18-
defaultValue: categories_url_data});
17+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1918
var args = parser.parseArgs();
2019

2120
var docParams = new DocumentParameters();
22-
docParams.setItem("contentUri", args.url);
21+
docParams.setItem("contentUri", categories_url_data);
2322

24-
var api = new Api(args.key);
23+
var api = new Api(args.key, args.url);
2524
api.categories(docParams, function(err, res) {
2625
if (err) {
2726
throw err;

examples/entities.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var parser = new ArgumentParser({
1313
description: "Get the entities from a piece of text"
1414
});
1515
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
16+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1617
var args = parser.parseArgs();
1718

1819
var docParams = new DocumentParameters();
@@ -21,7 +22,7 @@ var content = entities_text_data;
2122

2223
docParams.setItem("content", content);
2324

24-
var api = new Api(args.key);
25+
var api = new Api(args.key, args.url);
2526
api.entities(docParams, false, function(err, res) {
2627
if (err) {
2728
throw err;

examples/entities_linked.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ var parser = new ArgumentParser({
1313
description: "Get linked entities from a piece of text"
1414
});
1515
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
16+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1617
var args = parser.parseArgs();
1718

1819
var docParams = new DocumentParameters();
1920
var entities_linked_text_data = "Last month director Paul Feig announced the movie will have an all-star female cast including Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon.";
2021
var content = entities_linked_text_data;
2122
docParams.setItem("content", content);
2223

23-
var api = new Api(args.key);
24+
var api = new Api(args.key, args.url);
2425
api.entities(docParams, true, function(err, res) {
2526
if (err) {
2627
throw err;

examples/info.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ var parser = new ArgumentParser({
1212
description: "Get information about Rosette API"
1313
});
1414
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
15+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1516
var args = parser.parseArgs();
1617

17-
var api = new Api(args.key);
18+
var api = new Api(args.key, args.url);
1819
api.info(function(err, res) {
1920
if (err) {
2021
throw err;

examples/language.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ var parser = new ArgumentParser({
1313
description: "Determine the language of a piece of text"
1414
});
1515
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
16+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1617
var args = parser.parseArgs();
1718

1819
var docParams = new DocumentParameters();
1920
var language_data = "Por favor Señorita, says the man.";
2021
var content = language_data;
2122
docParams.setItem("content", content);
2223

23-
var api = new Api(args.key);
24+
var api = new Api(args.key, args.url);
2425
api.language(docParams, function(err, res) {
2526
if (err) {
2627
throw err;

examples/matched-name.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var parser = new ArgumentParser({
1313
description: "Get the similarity score of two names"
1414
});
1515
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
16+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1617
var args = parser.parseArgs();
1718

1819
var matched_name_data1 = "Michael Jackson";
@@ -21,7 +22,7 @@ var name1 = {"text": matched_name_data1, "language": "eng", "entityType": "PERSO
2122
var name2 = {"text": matched_name_data2, "entityType": "PERSON"};
2223
var matchParams = new NameMatchingParameters(name1, name2);
2324

24-
var api = new Api(args.key);
25+
var api = new Api(args.key, args.url);
2526
api.matchedName(matchParams, function(err, res) {
2627
if (err) {
2728
throw err;

examples/morphology_complete.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ var parser = new ArgumentParser({
1414
description: "Get the complete morphological analysis of a piece of text"
1515
});
1616
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
17+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1718
var args = parser.parseArgs();
1819

1920
var docParams = new DocumentParameters();
2021
var morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did.";
2122
var content = morphology_complete_data;
2223
docParams.setItem("content", content);
2324

24-
var api = new Api(args.key);
25+
var api = new Api(args.key, args.url);
2526
api.morphology(docParams, null, function(err, res) {
2627
if (err) {
2728
throw err;

examples/morphology_compound-components.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ var parser = new ArgumentParser({
1414
description: "Get de-compounded words from a piece of text"
1515
});
1616
parser.addArgument(["--key"], {help: "Rosette API key", required: true});
17+
parser.addArgument(["--url"], {help: "Alternate URL (optional)", defaultValue: "https://api.rosette.com/rest/v1"});
1718
var args = parser.parseArgs();
1819

1920
var docParams = new DocumentParameters();
2021
var morphology_compound_components_data = "Rechtsschutzversicherungsgesellschaften";
2122
var content = morphology_compound_components_data;
2223
docParams.setItem("content", content);
2324

24-
var api = new Api(args.key);
25+
var api = new Api(args.key, args.url);
2526
api.morphology(docParams, rosetteConstants.morpholoyOutput.COMPOUND_COMPONENTS, function(err, res) {
2627
if (err) {
2728
throw err;

0 commit comments

Comments
 (0)