-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang-process.js
43 lines (40 loc) · 1.17 KB
/
lang-process.js
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
let AlchemyLanguageV1 = require('watson-developer-cloud/alchemy-language/v1');
class NathanProcessor{
constructor(api_key){
this.watson = new AlchemyLanguageV1({
api_key: '836929e582b56ff138ef55896dc5efb959fdd50b'
});
}
queryProduct(string, callback){
this.watson.keywords({
text: string
}, function (err, res) {
let keywords = [];
if(res){
for(let i = 0; i < 3 && i < res.keywords.length; i++){
keywords.push(res.keywords[i].text);
}
}
callback(err, keywords);
});
}
queryLocation(string, callback){
this.watson.entities({
text: string
}, function (err, res) {
if (res.entities.length > 0 && res.entities[0].type == 'City'){
callback(err, res.entities[0].text)
} else {
callback(err, null);
}
});
}
}
module.exports = NathanProcessor;
/**
* Example Code
*
* new NathanProcessor().queryProduct('Where can I find nike shoes?', function (err, keywords) {
* console.log(keywords);
* };
*/