Skip to content

Commit f5ec30d

Browse files
language: elaborate docs to show config options
1 parent d976349 commit f5ec30d

File tree

2 files changed

+75
-8
lines changed

2 files changed

+75
-8
lines changed

packages/language/src/document.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ var prop = require('propprop');
3030
/*! Developer Documentation
3131
*
3232
* @param {module:language} language - The parent Language object.
33-
* @param {object=} config - Configuration object.
3433
*/
3534
/*
3635
* Create a Natural Language Document object. From this object, you will be able
@@ -39,13 +38,32 @@ var prop = require('propprop');
3938
* @constructor
4039
* @alias module:language/document
4140
*
41+
* @param {object|string|module:storage/file} config - Configuration object, the
42+
* inline content of the document, or a Storage File object.
43+
* @param {string|module:storage/file} options.content - If using `config` as an
44+
* object to specify the encoding and/or language of the document, use this
45+
* property to pass the inline content of the document or a Storage File
46+
* object.
47+
* @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See
48+
* [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1beta1/EncodingType).
49+
* @param {string} options.language - The language of the text.
50+
* @return {module:language/document}
51+
*
4252
* @example
4353
* var textToAnalyze = [
4454
* 'Google is an American multinational technology company specializing in',
4555
* 'Internet-related services and products.'
4656
* ].join(' ');
4757
*
4858
* var document = language.document(textToAnalyze);
59+
*
60+
* //-
61+
* // Create a Document object with pre-defined configuration, such as its
62+
* // language.
63+
* //-
64+
* var spanishDocument = language.document('¿Dónde está la sede de Google?', {
65+
* language: 'es'
66+
* });
4967
*/
5068
function Document(language, config) {
5169
var content = config.content || config;
@@ -130,7 +148,8 @@ Document.PART_OF_SPEECH = {
130148
*
131149
* @resource [documents.annotateText API Documentation]{@link https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText}
132150
*
133-
* @param {object=} options - Configuration object.
151+
* @param {object=} options - Configuration object. See
152+
* [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#request-body).
134153
* @param {boolean} options.entities - Detect the entities from this document.
135154
* By default, all features (`entities`, `sentiment`, and `syntax`) are
136155
* enabled. By overriding any of these values, all defaults are switched to
@@ -419,7 +438,8 @@ Document.prototype.annotate = function(options, callback) {
419438
*
420439
* @resource [documents.analyzeEntities API Documentation]{@link https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeEntities}
421440
*
422-
* @param {object=} options - Configuration object.
441+
* @param {object=} options - Configuration object. See
442+
* [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeEntities#request-body).
423443
* @param {boolean} options.verbose - Enable verbose mode for more detailed
424444
* results. Default: `false`
425445
* @param {function} callback - The callback function.
@@ -545,7 +565,8 @@ Document.prototype.detectEntities = function(options, callback) {
545565
*
546566
* @resource [documents.analyzeSentiment API Documentation]{@link https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeSentiment}
547567
*
548-
* @param {object=} options - Configuration object.
568+
* @param {object=} options - Configuration object. See
569+
* [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeSentiment#request-body).
549570
* @param {boolean} options.verbose - Enable verbose mode for more detailed
550571
* results. Default: `false`
551572
* @param {function} callback - The callback function.

packages/language/src/index.js

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ util.inherits(Language, common.GrpcService);
9393
* detection, this may be more convenient. However, if you plan to run multiple
9494
* detections, it's easier to create a {module:language/document} object.
9595
*
96-
* @resource [documents.annotate API Documentation]{@link https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotate}
96+
* @resource [documents.annotate API Documentation]{@link https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText}
9797
*
9898
* @param {string|module:storage/file} content - Inline content or a Storage
9999
* File object.
100-
* @param {object=} options - Configuration object.
100+
* @param {object=} options - Configuration object. See
101+
* [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#request-body).
101102
* @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See
102103
* [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1beta1/EncodingType).
103104
* @param {string} options.language - The language of the text.
@@ -136,6 +137,16 @@ util.inherits(Language, common.GrpcService);
136137
* language.annotate('Hello!', options, callback);
137138
*
138139
* //-
140+
* // Specify the language the text is written in.
141+
* //-
142+
* var options = {
143+
* language: 'es',
144+
* entities: true
145+
* };
146+
*
147+
* language.annotate('¿Dónde está la sede de Google?', options, callback);
148+
*
149+
* //-
139150
* // Verbose mode may also be enabled for more detailed results.
140151
* //-
141152
* var options = {
@@ -170,7 +181,8 @@ Language.prototype.annotate = function(content, options, callback) {
170181
*
171182
* @param {string|module:storage/file} content - Inline content or a Storage
172183
* File object.
173-
* @param {object=} options - Configuration object.
184+
* @param {object=} options - Configuration object. See
185+
* [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeEntities#request-body).
174186
* @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See
175187
* [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1beta1/EncodingType).
176188
* @param {string} options.language - The language of the text.
@@ -209,6 +221,15 @@ Language.prototype.annotate = function(content, options, callback) {
209221
* language.detectEntities('Axel Foley is from Detroit', options, callback);
210222
*
211223
* //-
224+
* // Specify the language the text is written in.
225+
* //-
226+
* var options = {
227+
* language: 'es'
228+
* };
229+
*
230+
* language.detectEntities('Axel Foley es de Detroit', options, callback);
231+
*
232+
* //-
212233
* // Verbose mode may also be enabled for more detailed results.
213234
* //-
214235
* var options = {
@@ -243,7 +264,8 @@ Language.prototype.detectEntities = function(content, options, callback) {
243264
*
244265
* @param {string|module:storage/file} content - Inline content or a Storage
245266
* File object.
246-
* @param {object=} options - Configuration object.
267+
* @param {object=} options - Configuration object. See
268+
* [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/analyzeSentiment#request-body).
247269
* @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See
248270
* [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1beta1/EncodingType).
249271
* @param {string} options.language - The language of the text.
@@ -337,6 +359,14 @@ Language.prototype.detectSentiment = function(content, options, callback) {
337359
* var document = language.document(file);
338360
*
339361
* //-
362+
* // Create a Document object with pre-defined configuration, such as its
363+
* // language.
364+
* //-
365+
* var document = language.document('¿Dónde está la sede de Google?', {
366+
* language: 'es'
367+
* });
368+
*
369+
* //-
340370
* // You can now run detections on the document.
341371
* //
342372
* // See {module:language/document} for a complete list of methods available.
@@ -374,6 +404,14 @@ Language.prototype.document = function(config) {
374404
* var document = language.html(file);
375405
*
376406
* //-
407+
* // Create a Document object with pre-defined configuration, such as its
408+
* // language.
409+
* //-
410+
* var document = language.html('<h1>Titulo del documento</h1>', {
411+
* language: 'es'
412+
* });
413+
*
414+
* //-
377415
* // You can now run detections on the document.
378416
* //
379417
* // See {module:language/document} for a complete list of methods available.
@@ -416,6 +454,14 @@ Language.prototype.html = function(content, options) {
416454
* var document = language.text(file);
417455
*
418456
* //-
457+
* // Create a Document object with pre-defined configuration, such as its
458+
* // language.
459+
* //-
460+
* var document = language.text('¿Dónde está la sede de Google?', {
461+
* language: 'es'
462+
* });
463+
*
464+
* //-
419465
* // You can now run detections on the document.
420466
* //
421467
* // See {module:language/document} for a complete list of methods available.

0 commit comments

Comments
 (0)