| 195 | } |
| 196 | |
| 197 | async function analyzeSyntaxInFile(bucketName, fileName) { |
| 198 | // [START language_syntax_gcs] |
| 199 | // Imports the Google Cloud client library |
| 200 | const language = require('@google-cloud/language'); |
| 201 | |
| 202 | // Creates a client |
| 203 | const client = new language.LanguageServiceClient(); |
| 204 | |
| 205 | /** |
| 206 | * TODO(developer): Uncomment the following lines to run this code |
| 207 | */ |
| 208 | // const bucketName = 'Your bucket name, e.g. my-bucket'; |
| 209 | // const fileName = 'Your file name, e.g. my-file.txt'; |
| 210 | |
| 211 | // Prepares a document, representing a text file in Cloud Storage |
| 212 | const document = { |
| 213 | gcsContentUri: `gs://${bucketName}/${fileName}`, |
| 214 | type: 'PLAIN_TEXT', |
| 215 | }; |
| 216 | |
| 217 | // Need to specify an encodingType to receive word offsets |
| 218 | const encodingType = 'UTF8'; |
| 219 | |
| 220 | // Detects the sentiment of the document |
| 221 | const [syntax] = await client.analyzeSyntax({document, encodingType}); |
| 222 | |
| 223 | console.log('Parts of speech:'); |
| 224 | syntax.tokens.forEach(part => { |
| 225 | console.log(`${part.partOfSpeech.tag}: ${part.text.content}`); |
| 226 | console.log('Morphology:', part.partOfSpeech); |
| 227 | }); |
| 228 | // [END language_syntax_gcs] |
| 229 | } |
| 230 | |
| 231 | async function analyzeEntitySentimentOfText(text) { |
| 232 | // [START language_entity_sentiment_text] |