UNPKG

@google-cloud/language

Version:
858 lines (784 loc) 2.43 MB
// Copyright 2025 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ (function(global, factory) { /* global define, require, module */ /* AMD */ if (typeof define === 'function' && define.amd) define(["protobufjs/minimal"], factory); /* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports) module.exports = factory(require("google-gax/build/src/protobuf").protobufMinimal); })(this, function($protobuf) { "use strict"; // Common aliases var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; // Exported root namespace var $root = $protobuf.roots._google_cloud_language_protos || ($protobuf.roots._google_cloud_language_protos = {}); $root.google = (function() { /** * Namespace google. * @exports google * @namespace */ var google = {}; google.cloud = (function() { /** * Namespace cloud. * @memberof google * @namespace */ var cloud = {}; cloud.language = (function() { /** * Namespace language. * @memberof google.cloud * @namespace */ var language = {}; language.v1 = (function() { /** * Namespace v1. * @memberof google.cloud.language * @namespace */ var v1 = {}; v1.LanguageService = (function() { /** * Constructs a new LanguageService service. * @memberof google.cloud.language.v1 * @classdesc Represents a LanguageService * @extends $protobuf.rpc.Service * @constructor * @param {$protobuf.RPCImpl} rpcImpl RPC implementation * @param {boolean} [requestDelimited=false] Whether requests are length-delimited * @param {boolean} [responseDelimited=false] Whether responses are length-delimited */ function LanguageService(rpcImpl, requestDelimited, responseDelimited) { $protobuf.rpc.Service.call(this, rpcImpl, requestDelimited, responseDelimited); } (LanguageService.prototype = Object.create($protobuf.rpc.Service.prototype)).constructor = LanguageService; /** * Creates new LanguageService service using the specified rpc implementation. * @function create * @memberof google.cloud.language.v1.LanguageService * @static * @param {$protobuf.RPCImpl} rpcImpl RPC implementation * @param {boolean} [requestDelimited=false] Whether requests are length-delimited * @param {boolean} [responseDelimited=false] Whether responses are length-delimited * @returns {LanguageService} RPC service. Useful where requests and/or responses are streamed. */ LanguageService.create = function create(rpcImpl, requestDelimited, responseDelimited) { return new this(rpcImpl, requestDelimited, responseDelimited); }; /** * Callback as used by {@link google.cloud.language.v1.LanguageService|analyzeSentiment}. * @memberof google.cloud.language.v1.LanguageService * @typedef AnalyzeSentimentCallback * @type {function} * @param {Error|null} error Error, if any * @param {google.cloud.language.v1.AnalyzeSentimentResponse} [response] AnalyzeSentimentResponse */ /** * Calls AnalyzeSentiment. * @function analyzeSentiment * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnalyzeSentimentRequest} request AnalyzeSentimentRequest message or plain object * @param {google.cloud.language.v1.LanguageService.AnalyzeSentimentCallback} callback Node-style callback called with the error, if any, and AnalyzeSentimentResponse * @returns {undefined} * @variation 1 */ Object.defineProperty(LanguageService.prototype.analyzeSentiment = function analyzeSentiment(request, callback) { return this.rpcCall(analyzeSentiment, $root.google.cloud.language.v1.AnalyzeSentimentRequest, $root.google.cloud.language.v1.AnalyzeSentimentResponse, request, callback); }, "name", { value: "AnalyzeSentiment" }); /** * Calls AnalyzeSentiment. * @function analyzeSentiment * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnalyzeSentimentRequest} request AnalyzeSentimentRequest message or plain object * @returns {Promise<google.cloud.language.v1.AnalyzeSentimentResponse>} Promise * @variation 2 */ /** * Callback as used by {@link google.cloud.language.v1.LanguageService|analyzeEntities}. * @memberof google.cloud.language.v1.LanguageService * @typedef AnalyzeEntitiesCallback * @type {function} * @param {Error|null} error Error, if any * @param {google.cloud.language.v1.AnalyzeEntitiesResponse} [response] AnalyzeEntitiesResponse */ /** * Calls AnalyzeEntities. * @function analyzeEntities * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnalyzeEntitiesRequest} request AnalyzeEntitiesRequest message or plain object * @param {google.cloud.language.v1.LanguageService.AnalyzeEntitiesCallback} callback Node-style callback called with the error, if any, and AnalyzeEntitiesResponse * @returns {undefined} * @variation 1 */ Object.defineProperty(LanguageService.prototype.analyzeEntities = function analyzeEntities(request, callback) { return this.rpcCall(analyzeEntities, $root.google.cloud.language.v1.AnalyzeEntitiesRequest, $root.google.cloud.language.v1.AnalyzeEntitiesResponse, request, callback); }, "name", { value: "AnalyzeEntities" }); /** * Calls AnalyzeEntities. * @function analyzeEntities * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnalyzeEntitiesRequest} request AnalyzeEntitiesRequest message or plain object * @returns {Promise<google.cloud.language.v1.AnalyzeEntitiesResponse>} Promise * @variation 2 */ /** * Callback as used by {@link google.cloud.language.v1.LanguageService|analyzeEntitySentiment}. * @memberof google.cloud.language.v1.LanguageService * @typedef AnalyzeEntitySentimentCallback * @type {function} * @param {Error|null} error Error, if any * @param {google.cloud.language.v1.AnalyzeEntitySentimentResponse} [response] AnalyzeEntitySentimentResponse */ /** * Calls AnalyzeEntitySentiment. * @function analyzeEntitySentiment * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnalyzeEntitySentimentRequest} request AnalyzeEntitySentimentRequest message or plain object * @param {google.cloud.language.v1.LanguageService.AnalyzeEntitySentimentCallback} callback Node-style callback called with the error, if any, and AnalyzeEntitySentimentResponse * @returns {undefined} * @variation 1 */ Object.defineProperty(LanguageService.prototype.analyzeEntitySentiment = function analyzeEntitySentiment(request, callback) { return this.rpcCall(analyzeEntitySentiment, $root.google.cloud.language.v1.AnalyzeEntitySentimentRequest, $root.google.cloud.language.v1.AnalyzeEntitySentimentResponse, request, callback); }, "name", { value: "AnalyzeEntitySentiment" }); /** * Calls AnalyzeEntitySentiment. * @function analyzeEntitySentiment * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnalyzeEntitySentimentRequest} request AnalyzeEntitySentimentRequest message or plain object * @returns {Promise<google.cloud.language.v1.AnalyzeEntitySentimentResponse>} Promise * @variation 2 */ /** * Callback as used by {@link google.cloud.language.v1.LanguageService|analyzeSyntax}. * @memberof google.cloud.language.v1.LanguageService * @typedef AnalyzeSyntaxCallback * @type {function} * @param {Error|null} error Error, if any * @param {google.cloud.language.v1.AnalyzeSyntaxResponse} [response] AnalyzeSyntaxResponse */ /** * Calls AnalyzeSyntax. * @function analyzeSyntax * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnalyzeSyntaxRequest} request AnalyzeSyntaxRequest message or plain object * @param {google.cloud.language.v1.LanguageService.AnalyzeSyntaxCallback} callback Node-style callback called with the error, if any, and AnalyzeSyntaxResponse * @returns {undefined} * @variation 1 */ Object.defineProperty(LanguageService.prototype.analyzeSyntax = function analyzeSyntax(request, callback) { return this.rpcCall(analyzeSyntax, $root.google.cloud.language.v1.AnalyzeSyntaxRequest, $root.google.cloud.language.v1.AnalyzeSyntaxResponse, request, callback); }, "name", { value: "AnalyzeSyntax" }); /** * Calls AnalyzeSyntax. * @function analyzeSyntax * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnalyzeSyntaxRequest} request AnalyzeSyntaxRequest message or plain object * @returns {Promise<google.cloud.language.v1.AnalyzeSyntaxResponse>} Promise * @variation 2 */ /** * Callback as used by {@link google.cloud.language.v1.LanguageService|classifyText}. * @memberof google.cloud.language.v1.LanguageService * @typedef ClassifyTextCallback * @type {function} * @param {Error|null} error Error, if any * @param {google.cloud.language.v1.ClassifyTextResponse} [response] ClassifyTextResponse */ /** * Calls ClassifyText. * @function classifyText * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IClassifyTextRequest} request ClassifyTextRequest message or plain object * @param {google.cloud.language.v1.LanguageService.ClassifyTextCallback} callback Node-style callback called with the error, if any, and ClassifyTextResponse * @returns {undefined} * @variation 1 */ Object.defineProperty(LanguageService.prototype.classifyText = function classifyText(request, callback) { return this.rpcCall(classifyText, $root.google.cloud.language.v1.ClassifyTextRequest, $root.google.cloud.language.v1.ClassifyTextResponse, request, callback); }, "name", { value: "ClassifyText" }); /** * Calls ClassifyText. * @function classifyText * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IClassifyTextRequest} request ClassifyTextRequest message or plain object * @returns {Promise<google.cloud.language.v1.ClassifyTextResponse>} Promise * @variation 2 */ /** * Callback as used by {@link google.cloud.language.v1.LanguageService|moderateText}. * @memberof google.cloud.language.v1.LanguageService * @typedef ModerateTextCallback * @type {function} * @param {Error|null} error Error, if any * @param {google.cloud.language.v1.ModerateTextResponse} [response] ModerateTextResponse */ /** * Calls ModerateText. * @function moderateText * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IModerateTextRequest} request ModerateTextRequest message or plain object * @param {google.cloud.language.v1.LanguageService.ModerateTextCallback} callback Node-style callback called with the error, if any, and ModerateTextResponse * @returns {undefined} * @variation 1 */ Object.defineProperty(LanguageService.prototype.moderateText = function moderateText(request, callback) { return this.rpcCall(moderateText, $root.google.cloud.language.v1.ModerateTextRequest, $root.google.cloud.language.v1.ModerateTextResponse, request, callback); }, "name", { value: "ModerateText" }); /** * Calls ModerateText. * @function moderateText * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IModerateTextRequest} request ModerateTextRequest message or plain object * @returns {Promise<google.cloud.language.v1.ModerateTextResponse>} Promise * @variation 2 */ /** * Callback as used by {@link google.cloud.language.v1.LanguageService|annotateText}. * @memberof google.cloud.language.v1.LanguageService * @typedef AnnotateTextCallback * @type {function} * @param {Error|null} error Error, if any * @param {google.cloud.language.v1.AnnotateTextResponse} [response] AnnotateTextResponse */ /** * Calls AnnotateText. * @function annotateText * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnnotateTextRequest} request AnnotateTextRequest message or plain object * @param {google.cloud.language.v1.LanguageService.AnnotateTextCallback} callback Node-style callback called with the error, if any, and AnnotateTextResponse * @returns {undefined} * @variation 1 */ Object.defineProperty(LanguageService.prototype.annotateText = function annotateText(request, callback) { return this.rpcCall(annotateText, $root.google.cloud.language.v1.AnnotateTextRequest, $root.google.cloud.language.v1.AnnotateTextResponse, request, callback); }, "name", { value: "AnnotateText" }); /** * Calls AnnotateText. * @function annotateText * @memberof google.cloud.language.v1.LanguageService * @instance * @param {google.cloud.language.v1.IAnnotateTextRequest} request AnnotateTextRequest message or plain object * @returns {Promise<google.cloud.language.v1.AnnotateTextResponse>} Promise * @variation 2 */ return LanguageService; })(); v1.Document = (function() { /** * Properties of a Document. * @memberof google.cloud.language.v1 * @interface IDocument * @property {google.cloud.language.v1.Document.Type|null} [type] Document type * @property {string|null} [content] Document content * @property {string|null} [gcsContentUri] Document gcsContentUri * @property {string|null} [language] Document language */ /** * Constructs a new Document. * @memberof google.cloud.language.v1 * @classdesc Represents a Document. * @implements IDocument * @constructor * @param {google.cloud.language.v1.IDocument=} [properties] Properties to set */ function Document(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * Document type. * @member {google.cloud.language.v1.Document.Type} type * @memberof google.cloud.language.v1.Document * @instance */ Document.prototype.type = 0; /** * Document content. * @member {string|null|undefined} content * @memberof google.cloud.language.v1.Document * @instance */ Document.prototype.content = null; /** * Document gcsContentUri. * @member {string|null|undefined} gcsContentUri * @memberof google.cloud.language.v1.Document * @instance */ Document.prototype.gcsContentUri = null; /** * Document language. * @member {string} language * @memberof google.cloud.language.v1.Document * @instance */ Document.prototype.language = ""; // OneOf field names bound to virtual getters and setters var $oneOfFields; /** * Document source. * @member {"content"|"gcsContentUri"|undefined} source * @memberof google.cloud.language.v1.Document * @instance */ Object.defineProperty(Document.prototype, "source", { get: $util.oneOfGetter($oneOfFields = ["content", "gcsContentUri"]), set: $util.oneOfSetter($oneOfFields) }); /** * Creates a new Document instance using the specified properties. * @function create * @memberof google.cloud.language.v1.Document * @static * @param {google.cloud.language.v1.IDocument=} [properties] Properties to set * @returns {google.cloud.language.v1.Document} Document instance */ Document.create = function create(properties) { return new Document(properties); }; /** * Encodes the specified Document message. Does not implicitly {@link google.cloud.language.v1.Document.verify|verify} messages. * @function encode * @memberof google.cloud.language.v1.Document * @static * @param {google.cloud.language.v1.IDocument} message Document message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ Document.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.type != null && Object.hasOwnProperty.call(message, "type")) writer.uint32(/* id 1, wireType 0 =*/8).int32(message.type); if (message.content != null && Object.hasOwnProperty.call(message, "content")) writer.uint32(/* id 2, wireType 2 =*/18).string(message.content); if (message.gcsContentUri != null && Object.hasOwnProperty.call(message, "gcsContentUri")) writer.uint32(/* id 3, wireType 2 =*/26).string(message.gcsContentUri); if (message.language != null && Object.hasOwnProperty.call(message, "language")) writer.uint32(/* id 4, wireType 2 =*/34).string(message.language); return writer; }; /** * Encodes the specified Document message, length delimited. Does not implicitly {@link google.cloud.language.v1.Document.verify|verify} messages. * @function encodeDelimited * @memberof google.cloud.language.v1.Document * @static * @param {google.cloud.language.v1.IDocument} message Document message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ Document.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a Document message from the specified reader or buffer. * @function decode * @memberof google.cloud.language.v1.Document * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {google.cloud.language.v1.Document} Document * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Document.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.language.v1.Document(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: { message.type = reader.int32(); break; } case 2: { message.content = reader.string(); break; } case 3: { message.gcsContentUri = reader.string(); break; } case 4: { message.language = reader.string(); break; } default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a Document message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof google.cloud.language.v1.Document * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {google.cloud.language.v1.Document} Document * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Document.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a Document message. * @function verify * @memberof google.cloud.language.v1.Document * @static * @param {Object.<string,*>} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ Document.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; var properties = {}; if (message.type != null && message.hasOwnProperty("type")) switch (message.type) { default: return "type: enum value expected"; case 0: case 1: case 2: break; } if (message.content != null && message.hasOwnProperty("content")) { properties.source = 1; if (!$util.isString(message.content)) return "content: string expected"; } if (message.gcsContentUri != null && message.hasOwnProperty("gcsContentUri")) { if (properties.source === 1) return "source: multiple values"; properties.source = 1; if (!$util.isString(message.gcsContentUri)) return "gcsContentUri: string expected"; } if (message.language != null && message.hasOwnProperty("language")) if (!$util.isString(message.language)) return "language: string expected"; return null; }; /** * Creates a Document message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof google.cloud.language.v1.Document * @static * @param {Object.<string,*>} object Plain object * @returns {google.cloud.language.v1.Document} Document */ Document.fromObject = function fromObject(object) { if (object instanceof $root.google.cloud.language.v1.Document) return object; var message = new $root.google.cloud.language.v1.Document(); switch (object.type) { default: if (typeof object.type === "number") { message.type = object.type; break; } break; case "TYPE_UNSPECIFIED": case 0: message.type = 0; break; case "PLAIN_TEXT": case 1: message.type = 1; break; case "HTML": case 2: message.type = 2; break; } if (object.content != null) message.content = String(object.content); if (object.gcsContentUri != null) message.gcsContentUri = String(object.gcsContentUri); if (object.language != null) message.language = String(object.language); return message; }; /** * Creates a plain object from a Document message. Also converts values to other types if specified. * @function toObject * @memberof google.cloud.language.v1.Document * @static * @param {google.cloud.language.v1.Document} message Document * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.<string,*>} Plain object */ Document.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.defaults) { object.type = options.enums === String ? "TYPE_UNSPECIFIED" : 0; object.language = ""; } if (message.type != null && message.hasOwnProperty("type")) object.type = options.enums === String ? $root.google.cloud.language.v1.Document.Type[message.type] === undefined ? message.type : $root.google.cloud.language.v1.Document.Type[message.type] : message.type; if (message.content != null && message.hasOwnProperty("content")) { object.content = message.content; if (options.oneofs) object.source = "content"; } if (message.gcsContentUri != null && message.hasOwnProperty("gcsContentUri")) { object.gcsContentUri = message.gcsContentUri; if (options.oneofs) object.source = "gcsContentUri"; } if (message.language != null && message.hasOwnProperty("language")) object.language = message.language; return object; }; /** * Converts this Document to JSON. * @function toJSON * @memberof google.cloud.language.v1.Document * @instance * @returns {Object.<string,*>} JSON object */ Document.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; /** * Gets the default type url for Document * @function getTypeUrl * @memberof google.cloud.language.v1.Document * @static * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") * @returns {string} The default type url */ Document.getTypeUrl = function getTypeUrl(typeUrlPrefix) { if (typeUrlPrefix === undefined) { typeUrlPrefix = "type.googleapis.com"; } return typeUrlPrefix + "/google.cloud.language.v1.Document"; }; /** * Type enum. * @name google.cloud.language.v1.Document.Type * @enum {number} * @property {number} TYPE_UNSPECIFIED=0 TYPE_UNSPECIFIED value * @property {number} PLAIN_TEXT=1 PLAIN_TEXT value * @property {number} HTML=2 HTML value */ Document.Type = (function() { var valuesById = {}, values = Object.create(valuesById); values[valuesById[0] = "TYPE_UNSPECIFIED"] = 0; values[valuesById[1] = "PLAIN_TEXT"] = 1; values[valuesById[2] = "HTML"] = 2; return values; })(); return Document; })(); v1.Sentence = (function() { /** * Properties of a Sentence. * @memberof google.cloud.language.v1 * @interface ISentence * @property {google.cloud.language.v1.ITextSpan|null} [text] Sentence text * @property {google.cloud.language.v1.ISentiment|null} [sentiment] Sentence sentiment */ /** * Constructs a new Sentence. * @memberof google.cloud.language.v1 * @classdesc Represents a Sentence. * @implements ISentence * @constructor * @param {google.cloud.language.v1.ISentence=} [properties] Properties to set */ function Sentence(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * Sentence text. * @member {google.cloud.language.v1.ITextSpan|null|undefined} text * @memberof google.cloud.language.v1.Sentence * @instance */ Sentence.prototype.text = null; /** * Sentence sentiment. * @member {google.cloud.language.v1.ISentiment|null|undefined} sentiment * @memberof google.cloud.language.v1.Sentence * @instance */ Sentence.prototype.sentiment = null; /** * Creates a new Sentence instance using the specified properties. * @function create * @memberof google.cloud.language.v1.Sentence * @static * @param {google.cloud.language.v1.ISentence=} [properties] Properties to set * @returns {google.cloud.language.v1.Sentence} Sentence instance */ Sentence.create = function create(properties) { return new Sentence(properties); }; /** * Encodes the specified Sentence message. Does not implicitly {@link google.cloud.language.v1.Sentence.verify|verify} messages. * @function encode * @memberof google.cloud.language.v1.Sentence * @static * @param {google.cloud.language.v1.ISentence} message Sentence message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ Sentence.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.text != null && Object.hasOwnProperty.call(message, "text")) $root.google.cloud.language.v1.TextSpan.encode(message.text, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); if (message.sentiment != null && Object.hasOwnProperty.call(message, "sentiment")) $root.google.cloud.language.v1.Sentiment.encode(message.sentiment, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); return writer; }; /** * Encodes the specified Sentence message, length delimited. Does not implicitly {@link google.cloud.language.v1.Sentence.verify|verify} messages. * @function encodeDelimited * @memberof google.cloud.language.v1.Sentence * @static * @param {google.cloud.language.v1.ISentence} message Sentence message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ Sentence.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a Sentence message from the specified reader or buffer. * @function decode * @memberof google.cloud.language.v1.Sentence * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {google.cloud.language.v1.Sentence} Sentence * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Sentence.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.language.v1.Sentence(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: { message.text = $root.google.cloud.language.v1.TextSpan.decode(reader, reader.uint32()); break; } case 2: { message.sentiment = $root.google.cloud.language.v1.Sentiment.decode(reader, reader.uint32()); break; } default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a Sentence message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof google.cloud.language.v1.Sentence * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {google.cloud.language.v1.Sentence} Sentence * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Sentence.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a Sentence message. * @function verify * @memberof google.cloud.language.v1.Sentence * @static * @param {Object.<string,*>} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ Sentence.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; if (message.text != null && message.hasOwnProperty("text")) { var error = $root.google.cloud.language.v1.TextSpan.verify(message.text); if (error) return "text." + error; } if (message.sentiment != null && message.hasOwnProperty("sentiment")) { var error = $root.google.cloud.language.v1.Sentiment.verify(message.sentiment); if (error) return "sentiment." + error; } return null; }; /** * Creates a Sentence message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof google.cloud.language.v1.Sentence * @static * @param {Object.<string,*>} object Plain object * @returns {google.cloud.language.v1.Sentence} Sentence */ Sentence.fromObject = function fromObject(object) { if (object instanceof $root.google.cloud.language.v1.Sentence) return object; var message = new $root.google.cloud.language.v1.Sentence(); if (object.text != null) { if (typeof object.text !== "object") throw TypeError(".google.cloud.language.v1.Sentence.text: object expected"); message.text = $root.google.cloud.language.v1.TextSpan.fromObject(object.text); } if (object.sentiment != null) { if (typeof object.sentiment !== "object") throw TypeError(".google.cloud.language.v1.Sentence.sentiment: object expected"); message.sentiment = $root.google.cloud.language.v1.Sentiment.fromObject(object.sentiment); } return message; }; /** * C