1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/analysis/sentiment/72-sentiment.js
Dave Conway-Jones 50fc196c6f
Add multilingual sentiment node
(but not publish - yet)
2018-07-19 12:39:07 +01:00

29 lines
981 B
JavaScript

module.exports = function(RED) {
"use strict";
var sentiment = require('multilang-sentiment');
function SentimentNode(n) {
RED.nodes.createNode(this,n);
this.lang = n.lang;
this.property = n.property||"payload";
var node = this;
this.on("input", function(msg) {
var value = RED.util.getMessageProperty(msg,node.property);
if (value !== undefined) {
if (msg.hasOwnProperty("overrides")) {
msg.extras = msg.overrides;
delete msg.overrides;
}
sentiment(value, node.lang || msg.lang || 'en', {words: msg.extras || null}, function (err, result) {
msg.sentiment = result;
node.send(msg);
});
}
else { node.send(msg); } // If no matching property - just pass it on.
});
}
RED.nodes.registerType("sentiment",SentimentNode);
}