MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / analyzeSyntaxOfText

Function analyzeSyntaxOfText

cloud-language/analyze.v1.js:164–195  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

162}
163
164async function analyzeSyntaxOfText(text) {
165 // [START language_syntax_text]
166 // Imports the Google Cloud client library
167 const language = require('@google-cloud/language');
168
169 // Creates a client
170 const client = new language.LanguageServiceClient();
171
172 /**
173 * TODO(developer): Uncomment the following line to run this code.
174 */
175 // const text = 'Your text to analyze, e.g. Hello, world!';
176
177 // Prepares a document, representing the provided text
178 const document = {
179 content: text,
180 type: 'PLAIN_TEXT',
181 };
182
183 // Need to specify an encodingType to receive word offsets
184 const encodingType = 'UTF8';
185
186 // Detects the sentiment of the document
187 const [syntax] = await client.analyzeSyntax({document, encodingType});
188
189 console.log('Tokens:');
190 syntax.tokens.forEach(part => {
191 console.log(`${part.partOfSpeech.tag}: ${part.text.content}`);
192 console.log('Morphology:', part.partOfSpeech);
193 });
194 // [END language_syntax_text]
195}
196
197async function analyzeSyntaxInFile(bucketName, fileName) {
198 // [START language_syntax_gcs]

Callers 1

analyze.v1.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected