1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00
node-red/nodes/core/analysis/72-sentiment.js

24 lines
743 B
JavaScript
Raw Normal View History

2013-09-05 16:02:48 +02:00
2014-05-04 00:32:04 +02:00
module.exports = function(RED) {
"use strict";
2014-05-04 00:32:04 +02:00
var sentiment = require('sentiment');
2014-05-04 00:32:04 +02:00
function SentimentNode(n) {
RED.nodes.createNode(this,n);
this.property = n.property||"payload";
2014-05-04 00:32:04 +02:00
var node = this;
2014-05-04 00:32:04 +02:00
this.on("input", function(msg) {
var value = RED.util.getMessageProperty(msg,node.property);
if (value !== undefined) {
sentiment(value, msg.overrides || null, function (err, result) {
msg.sentiment = result;
node.send(msg);
});
}
else { node.send(msg); } // If no matching property - just pass it on.
});
2014-05-04 00:32:04 +02:00
}
RED.nodes.registerType("sentiment",SentimentNode);
2013-09-05 16:02:48 +02:00
}