forked from HPE-Haven-OnDemand/coding-tutorial_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (37 loc) · 1.59 KB
/
index.js
File metadata and controls
42 lines (37 loc) · 1.59 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
'use strict';
var expressApp = require('express')()
var urlencoded = require('body-parser').urlencoded({extended: false})
var havenondemand = require('havenondemand')
var port = process.env.PORT || 5000
var client = new havenondemand.HODClient('API_KEY', 'v1', 'OPTIONAL_PROXY')
var outputResults = function(text, sentiment, score, concepts, entities) {
console.log("\n---------------------------------------------")
console.log("---------------------------------------------")
console.log("RECEIVED: ", text)
console.log("\nSENTIMENT: ", sentiment, " | ", score)
console.log("\nCONCEPTS:")
console.log(concepts)
console.log("\nENTITIES:")
console.log(entities)
console.log("---------------------------------------------")
console.log("---------------------------------------------\n")
}
expressApp.post('/text_processor', urlencoded, function(req, res){
var text = req.body["Body"]
var entityData = {text: text, entity_type: ['people_eng', 'places_eng', 'companies_eng', 'organizations']}
client.call('analyzesentiment', {text: text}, function(err1, resp1){
client.call('extractconcepts', {text: text}, function(err2, resp2){
client.call('extractentities', entityData, function(err3, resp3){
var sentiment = resp1.body.aggregate.sentiment
var score = resp1.body.aggregate.score
var concepts = resp2.body.concepts
var entities = resp3.body.entities
outputResults(text, sentiment, score, concepts, entities)
res.sendStatus(200)
})
})
})
})
expressApp.listen(port, function(){
console.log("Listening on port: ", port)
})