mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
b67452d569
* allow custom tokenizers allows use of tokens object to specifiy custom tokenizers updated mlsentiment to v2.0.0 (with temporary fix for comparative score applied) updated documentation * update unit tests
26 lines
1.1 KiB
JavaScript
26 lines
1.1 KiB
JavaScript
|
|
module.exports = function (RED) {
|
|
"use strict";
|
|
var multilangsentiment = require('multilang-sentiment');
|
|
|
|
function MultiLangSentimentNode(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) {
|
|
multilangSentiment(value, node.lang || msg.lang || 'en', { 'words': msg.words || null, 'tokens': msg.tokens || null }, function (err, result) {
|
|
msg.sentiment = result;
|
|
msg.sentiment.comparative = msg.sentiment.score / msg.sentiment.tokens.length; // temporarily addresses an issue in v2.0.0: https://github.com/marcellobarile/multilang-sentiment/issues/10
|
|
node.send(msg);
|
|
});
|
|
}
|
|
else { node.send(msg); } // If no matching property - just pass it on.
|
|
});
|
|
}
|
|
RED.nodes.registerType("mlsentiment", MultiLangSentimentNode);
|
|
}
|