-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
72 lines (56 loc) · 1.39 KB
/
example.js
File metadata and controls
72 lines (56 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Import this module
const NLP = require('google-nlp')
// Google Cloud API key
const apiKey = 'ABCDEFGHHIJKLMNOPQRSTUVWXYZ'
// Text to send to Google NLP
let text = 'The quick brown fox jumps over the lazy dog'
// Instantiate he NLP class with your Google Cloud API key
let nlp = new NLP( apiKey )
/**
* Analyze entities from the text string
*/
nlp.analyzeEntities( text )
.then(function( entities ) {
// Output returned entities
console.log( 'Entities:', entities );
})
.catch(function( error ) {
// Error received, output the error
console.log( 'Error:', error.message );
})
/**
* Analyze sentiment from the text string
*/
nlp.analyzeSentiment( text )
.then(function( sentiment ) {
console.log( 'Sentiment:', sentiment );
})
.catch(function( error ) {
console.log( 'Error:', error.message );
})
/**
* Analyze syntax from the text string
*/
nlp.analyzeSyntax( text )
.then(function( syntax ) {
console.log( 'Syntax:', syntax );
})
.catch(function( error ) {
console.log( 'Error:', error.message );
})
/**
* Analyze syntax from the text string
*/
// Default features if `features` param is omitted
const features = {
syntax: true,
entities: true,
sentiment: true
}
nlp.annotateText( text, features )
.then(function( annotations ) {
console.log( 'Annotations:', annotations );
})
.catch(function( error ) {
console.log( 'Error:', error.message );
})