mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
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
This commit is contained in:
parent
8a29f9e379
commit
46ace77cf4
@ -4,14 +4,16 @@
|
||||
<h3>Outputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>sentiment <span class="property-type">object</span></dt>
|
||||
<dd>contains the resulting AFINN-111 sentiment.</dd>
|
||||
<dd>contains the resulting AFINN-165 sentiment.</dd>
|
||||
<dt>sentiment.score <span class="property-type">number</span></dt>
|
||||
<dd>the sentiment score.</dd>
|
||||
</dl>
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>words <span class="property-type">object</span></dt>
|
||||
<dd>an object of words and scores to override or add words can be supplied - <code>{ word:score,... }</code>.</dd>
|
||||
<dd>besides sending a raw string in msg.payload, an object of words and scores to override or add words can be supplied - <code>{ word:score,... }</code>.</dd>
|
||||
<dt>tokens <span class="property-type">object</span></dt>
|
||||
<dd>a `tokens` object allows custom tokenizers which may be required by some languages - <code>{ ['世界',...] }</code>.</dd>
|
||||
</dl>
|
||||
<dl class="message-properties">
|
||||
<dt>lang <span class="property-type">string</span></dt>
|
||||
|
@ -4,14 +4,16 @@
|
||||
<h3>出力</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>sentiment <span class="property-type">オブジェクト</span></dt>
|
||||
<dd>AFINN-111による感情分析の結果</dd>
|
||||
<dd>AFINN-165による感情分析の結果</dd>
|
||||
<dt>sentiment.score <span class="property-type">数値</span></dt>
|
||||
<dd>感情分析スコア</dd>
|
||||
</dl>
|
||||
<h3>入力</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>overrides <span class="property-type">オブジェクト</span></dt>
|
||||
<dt>words <span class="property-type">オブジェクト</span></dt>
|
||||
<dd>単語スコアの上書きをするためのオブジェクト - <code>{ word:score,... }</code></dd>
|
||||
<dt>tokens <span class="property-type">object</span></dt>
|
||||
<dd>一部の言語で必要となるカスタム トークナイザーが可能になります - <code>{ ['世界',...] }</code>.</dd>
|
||||
</dl>
|
||||
<h3>詳細</h3>
|
||||
<p>ゼロ以上のスコアはポジティブ、ゼロ以下はネガティブを意味します。</p>
|
||||
|
@ -1,28 +1,29 @@
|
||||
|
||||
module.exports = function(RED) {
|
||||
module.exports = function (RED) {
|
||||
"use strict";
|
||||
var multilangsentiment = require('multilang-sentiment');
|
||||
|
||||
function MultiLangSentimentNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
RED.nodes.createNode(this, n);
|
||||
this.lang = n.lang;
|
||||
this.property = n.property||"payload";
|
||||
this.property = n.property || "payload";
|
||||
var node = this;
|
||||
|
||||
this.on("input", function(msg) {
|
||||
var value = RED.util.getMessageProperty(msg,node.property);
|
||||
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;
|
||||
}
|
||||
multilangsentiment(value, node.lang || msg.lang || 'en', {words: msg.extras || null}, function (err, result) {
|
||||
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);
|
||||
RED.nodes.registerType("mlsentiment", MultiLangSentimentNode);
|
||||
}
|
||||
|
@ -1,19 +1,25 @@
|
||||
{
|
||||
"name" : "node-red-node-multilang-sentiment",
|
||||
"version" : "0.1.0",
|
||||
"description" : "A Node-RED node that uses the AFINN-165 wordlists for sentiment analysis of words translated into multiple languages including emojis.",
|
||||
"dependencies" : {
|
||||
"multilang-sentiment" : "^1.2.0"
|
||||
"name": "node-red-node-multilang-sentiment",
|
||||
"version": "0.2.0",
|
||||
"description": "A Node-RED node that uses the AFINN-165 wordlists for sentiment analysis of words translated into multiple languages including emoji.",
|
||||
"dependencies": {
|
||||
"multilang-sentiment": "^2.0.0"
|
||||
},
|
||||
"repository" : {
|
||||
"type":"git",
|
||||
"url":"https://github.com/node-red/node-red-nodes.git",
|
||||
"directory" : "tree/master/analysis/mlsentiment"
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/node-red/node-red-nodes.git",
|
||||
"directory": "tree/master/analysis/mlsentiment"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [ "node-red", "sentiment", "anaylsis", "AFINN" ],
|
||||
"node-red" : {
|
||||
"nodes" : {
|
||||
"keywords": [
|
||||
"node-red",
|
||||
"sentiment",
|
||||
"anaylsis",
|
||||
"AFINN",
|
||||
"emoji"
|
||||
],
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
"mlsentiment": "mlsentiment.js"
|
||||
}
|
||||
},
|
||||
@ -21,5 +27,8 @@
|
||||
"name": "Dave Conway-Jones",
|
||||
"email": "ceejay@vnet.ibm.com",
|
||||
"url": "http://nodered.org"
|
||||
}
|
||||
},
|
||||
"contributors" : [
|
||||
"Chuan Khoo <khoo.chuan@gmail.com> (https://chuank.com)"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user