Skip to content

Commit bc558af

Browse files
committed
Address comments.
1 parent 2b76870 commit bc558af

File tree

4 files changed

+78
-94
lines changed

4 files changed

+78
-94
lines changed

language/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,24 @@ __Usage:__ `node analyze --help`
3535

3636
```
3737
Commands:
38-
sentiment <text> Detect the sentiment of a block of text.
38+
sentimentFromString <text> Detect the sentiment of a block of text.
3939
sentimentFromFile <bucket> <filename> Detect the sentiment of text in a GCS file.
40-
entities <text> Detect the entities of a block of text.
40+
entitiesFromString <text> Detect the entities of a block of text.
4141
entitiesFromFile <bucket> <filename> Detect the entities of text in a GCS file.
42-
syntax <text> Detect the syntax of a block of text.
43-
syntaxFromFile <bucket> <filename> Detect the syntax of a block of text.
42+
syntaxFromString <text> Detect the syntax of a block of text.
43+
syntaxFromFile <bucket> <filename> Detect the syntax of text in a GCS file.
4444
4545
Options:
4646
--language, -l The language of the text. [string]
47-
--type, -t Type of text. [string] [choices: "text", "html"] [default: "text"]
47+
--type, -t Type of text [string] [choices: "text", "html"] [default: "text"]
4848
--help Show help [boolean]
4949
5050
Examples:
51-
node analyze sentiment "President Obama is speaking at the White House."
51+
node analyze sentimentFromString "President Obama is speaking at the White House."
5252
node analyze sentimentFromFile my-bucket file.txt
53-
node analyze entities "<p>President Obama is speaking at the White House.</p> -t html"
53+
node analyze entitiesFromString "<p>President Obama is speaking at the White House.</p>" -t html
5454
node analyze entitiesFromFile my-bucket file.txt
55-
node analyze syntax "President Obama is speaking at the White House."
55+
node analyze syntaxFromString "President Obama is speaking at the White House."
5656
node analyze syntaxFromFile my-bucket es_file.txt -l es
5757
5858
For more information, see https://cloud.google.com/natural-language/docs

language/analyze.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ var language = Language();
2929
var storage = Storage();
3030
// [END setup]
3131

32-
// [START analyze_sentiment]
32+
// [START analyze_sentiment_from_string]
3333
/**
3434
* Detect the sentiment of a block of text.
3535
*
3636
* @param {string} text The text to analyze.
3737
* @param {object} [options] Configuration options.
38-
* @param {string} [options.type] "text" or "html".
38+
* @param {string} [options.type] The type of the text, either "text" or "html".
3939
* @param {string} [options.language] The language of the text, e.g. "en".
4040
* @param {function} callback The callback function.
4141
*/
42-
function analyzeSentiment (text, options, callback) {
42+
function analyzeSentimentFromString (text, options, callback) {
4343
var document = language.document({
4444
content: text,
4545
type: options.type,
@@ -61,7 +61,7 @@ function analyzeSentiment (text, options, callback) {
6161
return callback(null, sentiment);
6262
});
6363
}
64-
// [END analyze_sentiment]
64+
// [END analyze_sentiment_from_string]
6565

6666
// [START analyze_sentiment_from_file]
6767
/**
@@ -71,7 +71,7 @@ function analyzeSentiment (text, options, callback) {
7171
* @param {string} filename The name of the file to be analyzed.
7272
* @param {object} [options] Optional configuration.
7373
* @param {string} [options.language] The language of the text, e.g. "en".
74-
* @param {string} [options.type] "text" or "html".
74+
* @param {string} [options.type] The type of the text, either "text" or "html".
7575
* @param {function} callback The callback function.
7676
*/
7777
function analyzeSentimentFromFile (bucket, filename, options, callback) {
@@ -98,17 +98,17 @@ function analyzeSentimentFromFile (bucket, filename, options, callback) {
9898
}
9999
// [END analyze_sentiment_from_file]
100100

101-
// [START analyze_entities]
101+
// [START analyze_entities_from_string]
102102
/**
103103
* Detect the entities from a block of text.
104104
*
105105
* @param {string} text The text to analyze.
106106
* @param {object} [options] Optional configuration.
107107
* @param {string} [options.language] The language of the text, e.g. "en".
108-
* @param {string} [options.type] "text" or "html".
108+
* @param {string} [options.type] The type of the text, either "text" or "html".
109109
* @param {function} callback The callback function.
110110
*/
111-
function analyzeEntities (text, options, callback) {
111+
function analyzeEntitiesFromString (text, options, callback) {
112112
var document = language.document({
113113
content: text,
114114
type: options.type,
@@ -130,7 +130,7 @@ function analyzeEntities (text, options, callback) {
130130
return callback(null, entities);
131131
});
132132
}
133-
// [END analyze_entities]
133+
// [END analyze_entities_from_string]
134134

135135
// [START analyze_entities_from_file]
136136
/**
@@ -140,7 +140,7 @@ function analyzeEntities (text, options, callback) {
140140
* @param {string} filename The name of the file to be analyzed.
141141
* @param {object} [options] Optional configuration.
142142
* @param {string} [options.language] The language of the text, e.g. "en".
143-
* @param {string} [options.type] "text" or "html".
143+
* @param {string} [options.type] The type of the text, either "text" or "html".
144144
* @param {function} callback The callback function.
145145
*/
146146
function analyzeEntitiesFromFile (bucket, filename, options, callback) {
@@ -167,17 +167,17 @@ function analyzeEntitiesFromFile (bucket, filename, options, callback) {
167167
}
168168
// [END analyze_entities_from_file]
169169

170-
// [START analyze_syntax]
170+
// [START analyze_syntax_from_string]
171171
/**
172172
* Detect the syntax in a block of text.
173173
*
174174
* @param {string} text The text to analyze.
175175
* @param {object} [options] Optional configuration.
176176
* @param {string} [options.language] The language of the text, e.g. "en".
177-
* @param {string} [options.type] "text" or "html".
177+
* @param {string} [options.type] The type of the text, either "text" or "html".
178178
* @param {function} callback The callback function.
179179
*/
180-
function analyzeSyntax (text, options, callback) {
180+
function analyzeSyntaxFromString (text, options, callback) {
181181
var document = language.document({
182182
content: text,
183183
type: options.type,
@@ -198,7 +198,7 @@ function analyzeSyntax (text, options, callback) {
198198
return callback(null, apiResponse);
199199
});
200200
}
201-
// [END analyze_syntax]
201+
// [END analyze_syntax_from_string]
202202

203203
// [START analyze_syntax_from_file]
204204
/**
@@ -208,7 +208,7 @@ function analyzeSyntax (text, options, callback) {
208208
* @param {string} filename The name of the file to be analyzed.
209209
* @param {object} [options] Optional configuration.
210210
* @param {string} [options.language] The language of the text, e.g. "en".
211-
* @param {string} [options.type] "text" or "html".
211+
* @param {string} [options.type] The type of the text, either "text" or "html".
212212
* @param {function} callback The callback function.
213213
*/
214214
function analyzeSyntaxFromFile (bucket, filename, options, callback) {
@@ -240,11 +240,11 @@ var cli = require('yargs');
240240
var utils = require('../utils');
241241

242242
var program = module.exports = {
243-
analyzeSentiment: analyzeSentiment,
243+
analyzeSentimentFromString: analyzeSentimentFromString,
244244
analyzeSentimentFromFile: analyzeSentimentFromFile,
245-
analyzeEntities: analyzeEntities,
245+
analyzeEntitiesFromString: analyzeEntitiesFromString,
246246
analyzeEntitiesFromFile: analyzeEntitiesFromFile,
247-
analyzeSyntax: analyzeSyntax,
247+
analyzeSyntaxFromString: analyzeSyntaxFromString,
248248
analyzeSyntaxFromFile: analyzeSyntaxFromFile,
249249
main: function (args) {
250250
// Run the command-line program
@@ -254,22 +254,22 @@ var program = module.exports = {
254254

255255
cli
256256
.demand(1)
257-
.command('sentiment <text>', 'Detect the sentiment of a block of text.', {}, function (options) {
258-
program.analyzeSentiment(options.text, utils.pick(options, ['language', 'type']), utils.makeHandler());
257+
.command('sentimentFromString <text>', 'Detect the sentiment of a block of text.', {}, function (options) {
258+
program.analyzeSentimentFromString(options.text, utils.pick(options, ['language', 'type']), utils.makeHandler());
259259
})
260260
.command('sentimentFromFile <bucket> <filename>', 'Detect the sentiment of text in a GCS file.', {}, function (options) {
261261
program.analyzeSentimentFromFile(options.bucket, options.filename, utils.pick(options, ['language', 'type']), utils.makeHandler());
262262
})
263-
.command('entities <text>', 'Detect the entities of a block of text.', {}, function (options) {
264-
program.analyzeEntities(options.text, utils.pick(options, ['language', 'type']), utils.makeHandler());
263+
.command('entitiesFromString <text>', 'Detect the entities of a block of text.', {}, function (options) {
264+
program.analyzeEntitiesFromString(options.text, utils.pick(options, ['language', 'type']), utils.makeHandler());
265265
})
266266
.command('entitiesFromFile <bucket> <filename>', 'Detect the entities of text in a GCS file.', {}, function (options) {
267267
program.analyzeEntitiesFromFile(options.bucket, options.filename, utils.pick(options, ['language', 'type']), utils.makeHandler());
268268
})
269-
.command('syntax <text>', 'Detect the syntax of a block of text.', {}, function (options) {
270-
program.analyzeSyntax(options.text, utils.pick(options, ['language', 'type']), utils.makeHandler());
269+
.command('syntaxFromString <text>', 'Detect the syntax of a block of text.', {}, function (options) {
270+
program.analyzeSyntaxFromString(options.text, utils.pick(options, ['language', 'type']), utils.makeHandler());
271271
})
272-
.command('syntaxFromFile <bucket> <filename>', 'Detect the syntax of a block of text.', {}, function (options) {
272+
.command('syntaxFromFile <bucket> <filename>', 'Detect the syntax of text in a GCS file.', {}, function (options) {
273273
program.analyzeSyntaxFromFile(options.bucket, options.filename, utils.pick(options, ['language', 'type']), utils.makeHandler());
274274
})
275275
.options({
@@ -290,13 +290,13 @@ cli
290290
global: true
291291
}
292292
})
293-
.example('node $0 sentiment "President Obama is speaking at the White House."', '')
293+
.example('node $0 sentimentFromString "President Obama is speaking at the White House."', '')
294294
.example('node $0 sentimentFromFile my-bucket file.txt', '')
295-
.example('node $0 entities "<p>President Obama is speaking at the White House.</p> -t html"', '')
295+
.example('node $0 entitiesFromString "<p>President Obama is speaking at the White House.</p>" -t html', '')
296296
.example('node $0 entitiesFromFile my-bucket file.txt', '')
297-
.example('node $0 syntax "President Obama is speaking at the White House."', '')
297+
.example('node $0 syntaxFromString "President Obama is speaking at the White House."', '')
298298
.example('node $0 syntaxFromFile my-bucket es_file.txt -l es', '')
299-
.wrap(200)
299+
.wrap(100)
300300
.recommendCommands()
301301
.epilogue('For more information, see https://cloud.google.com/natural-language/docs');
302302

language/system-test/analyze.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ describe('language:analyze', function () {
4141
});
4242
});
4343

44-
describe('analyzeSentiment', function () {
44+
describe('analyzeSentimentFromString', function () {
4545
it('should analyze sentiment in text', function (done) {
46-
program.analyzeSentiment(text, options, function (err, sentiment) {
47-
assert.equal(null, err);
46+
program.analyzeSentimentFromString(text, options, function (err, sentiment) {
47+
assert.equal(err, null);
4848
assert.equal(typeof sentiment, 'object');
4949
assert.equal(typeof sentiment.polarity, 'number');
5050
assert.equal(typeof sentiment.magnitude, 'number');
@@ -56,7 +56,7 @@ describe('language:analyze', function () {
5656
describe('analyzeSentimentFromFile', function () {
5757
it('should analyze sentiment in a file', function (done) {
5858
program.analyzeSentimentFromFile(bucketName, fileName, options, function (err, sentiment) {
59-
assert.equal(null, err);
59+
assert.equal(err, null);
6060
assert.equal(typeof sentiment, 'object');
6161
assert.equal(typeof sentiment.polarity, 'number');
6262
assert.equal(typeof sentiment.magnitude, 'number');
@@ -65,10 +65,10 @@ describe('language:analyze', function () {
6565
});
6666
});
6767

68-
describe('analyzeEntities', function () {
68+
describe('analyzeEntitiesFromString', function () {
6969
it('should analyze entities in text', function (done) {
70-
program.analyzeEntities(text, options, function (err, entities) {
71-
assert.equal(null, err);
70+
program.analyzeEntitiesFromString(text, options, function (err, entities) {
71+
assert.equal(err, null);
7272
assert.equal(typeof entities, 'object');
7373
assert.equal(Array.isArray(entities.people), true);
7474
assert.equal(Array.isArray(entities.places), true);
@@ -80,7 +80,7 @@ describe('language:analyze', function () {
8080
describe('analyzeEntitiesFromFile', function () {
8181
it('should analyze entities in a file', function (done) {
8282
program.analyzeEntitiesFromFile(bucketName, fileName, options, function (err, entities) {
83-
assert.equal(null, err);
83+
assert.equal(err, null);
8484
assert.equal(typeof entities, 'object');
8585
assert.equal(Array.isArray(entities.people), true);
8686
assert.equal(Array.isArray(entities.places), true);
@@ -89,10 +89,10 @@ describe('language:analyze', function () {
8989
});
9090
});
9191

92-
describe('analyzeSyntax', function () {
92+
describe('analyzeSyntaxFromString', function () {
9393
it('should analyze syntax in text', function (done) {
94-
program.analyzeSyntax(text, options, function (err, syntax) {
95-
assert.equal(null, err);
94+
program.analyzeSyntaxFromString(text, options, function (err, syntax) {
95+
assert.equal(err, null);
9696
assert.equal(typeof syntax, 'object');
9797
assert.equal(Array.isArray(syntax.sentences), true);
9898
assert.equal(Array.isArray(syntax.tokens), true);
@@ -104,7 +104,7 @@ describe('language:analyze', function () {
104104
describe('analyzeSyntaxFromFile', function () {
105105
it('should analyze syntax in a file', function (done) {
106106
program.analyzeSyntaxFromFile(bucketName, fileName, options, function (err, syntax) {
107-
assert.equal(null, err);
107+
assert.equal(err, null);
108108
assert.equal(typeof syntax, 'object');
109109
assert.equal(Array.isArray(syntax.sentences), true);
110110
assert.equal(Array.isArray(syntax.tokens), true);

0 commit comments

Comments
 (0)