1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

bump senitment node to include links to multi lang version

This commit is contained in:
Dave Conway-Jones 2019-03-15 10:03:05 +00:00
parent c1ac48d6a6
commit a2269bb863
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
5 changed files with 205 additions and 4 deletions

View File

@ -26,7 +26,8 @@
<h3>Details</h3> <h3>Details</h3>
<p>A score greater than zero is positive and less than zero is negative.</p> <p>A score greater than zero is positive and less than zero is negative.</p>
<p>The score typically ranges from -5 to +5, but can go higher and lower.</p> <p>The score typically ranges from -5 to +5, but can go higher and lower.</p>
<p>See <a href="https://github.com/thisandagain/sentiment/blob/master/README.md" target="_blank">the Sentiment docs here</a>.</p> <p>See <a href="https://github.com/thisandagain/sentiment/blob/master/README.md" target="_blank">the Sentiment docs here.</a>.</p>
<p><b>Note</b>: There is also a multi-language version available - <b>node-red-node-multilang-sentiment</b></p>
</script> </script>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -1,4 +1,4 @@
Copyright 2016, 2018 JS Foundation and other contributors, https://js.foundation/ Copyright 2016, 2019 JS Foundation and other contributors, https://js.foundation/
Copyright 2013-2016 IBM Corp. Copyright 2013-2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -4,7 +4,7 @@ node-red-node-sentiment
A <a href="http://nodered.org" target="new">Node-RED</a> node that scores incoming words A <a href="http://nodered.org" target="new">Node-RED</a> node that scores incoming words
using the AFINN-165 wordlist and attaches a sentiment.score property to the msg. using the AFINN-165 wordlist and attaches a sentiment.score property to the msg.
NOTE: We also have a multi-language version available as <b>node-red-node-multilang-sentiment</b>. NOTE: There is also a multi-language version available - **node-red-node-multilang-sentiment**.
Install Install
------- -------

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-sentiment", "name" : "node-red-node-sentiment",
"version" : "0.1.2", "version" : "0.1.3",
"description" : "A Node-RED node that uses the AFINN-165 wordlists for sentiment analysis of words.", "description" : "A Node-RED node that uses the AFINN-165 wordlists for sentiment analysis of words.",
"dependencies" : { "dependencies" : {
"sentiment" : "2.1.0" "sentiment" : "2.1.0"

View File

@ -0,0 +1,200 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var sentimentNode = require("../../../analysis/mlsentiment/mlsentiment.js");
var helper = require("node-red-node-test-helper");
describe('mlsentiment Node', function() {
before(function(done) {
helper.startServer(done);
});
after(function(done) {
helper.stopServer(done);
});
afterEach(function() {
helper.unload();
});
it('should be loaded', function(done) {
var flow = [{id:"sentimentNode1", type:"mlsentiment", name: "sentimentNode" }];
helper.load(sentimentNode, flow, function() {
var sentimentNode1 = helper.getNode("sentimentNode1");
sentimentNode1.should.have.property('name', 'sentimentNode');
done();
});
});
it('should pass on msg if no payload', function(done) {
var flow = [{id:"jn1",type:"mlsentiment",wires:[["jn2"]]},
{id:"jn2", type:"helper"}];
helper.load(sentimentNode, flow, function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
msg.should.not.have.property('sentiment');
msg.topic.should.equal("pass on");
done();
});
var testString = 'good, great, best, brilliant';
jn1.receive({topic:"pass on"});
});
});
it('should add a positive score for good words', function(done) {
var flow = [{id:"jn1",type:"mlsentiment",wires:[["jn2"]]},
{id:"jn2", type:"helper"}];
helper.load(sentimentNode, flow, function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
try {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.be.above(10);
done();
} catch(err) {
done(err);
}
});
var testString = 'good, great, best, brilliant';
jn1.receive({payload:testString});
});
});
it('should add a positive score for good words (in French)', function(done) {
var flow = [{id:"jn1",type:"mlsentiment",wires:[["jn2"]],lang:"fr"},
{id:"jn2", type:"helper"}];
helper.load(sentimentNode, flow, function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
try {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.be.above(5);
done();
} catch(err) {
done(err);
}
});
var testString = 'bon, belle, don du ciel, brillant';
jn1.receive({payload:testString});
});
});
it('should add a positive score for good words - alternative property', function(done) {
var flow = [{id:"jn1",type:"mlsentiment",property:"foo",wires:[["jn2"]]},
{id:"jn2", type:"helper"}];
helper.load(sentimentNode, flow, function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
try {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.be.above(10);
done();
} catch(err) {
done(err);
}
});
var testString = 'good, great, best, brilliant';
jn1.receive({foo:testString});
});
});
it('should add a negative score for bad words', function(done) {
var flow = [{id:"jn1",type:"mlsentiment",wires:[["jn2"]]},
{id:"jn2", type:"helper"}];
helper.load(sentimentNode, flow, function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.be.below(-10);
done();
});
var testString = 'bad, horrible, negative, awful';
jn1.receive({payload:testString});
});
});
it('should add a negative score for bad words - alternative property', function(done) {
var flow = [{id:"jn1",type:"mlsentiment",property:"foo",wires:[["jn2"]]},
{id:"jn2", type:"helper"}];
helper.load(sentimentNode, flow, function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.be.below(-10);
done();
});
var testString = 'bad, horrible, negative, awful';
jn1.receive({foo:testString});
});
});
it('should allow you to override word scoring', function(done) {
var flow = [{id:"jn1",type:"mlsentiment",wires:[["jn2"]]},
{id:"jn2", type:"helper"}];
helper.load(sentimentNode, flow, function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.equal(20);
done();
});
var testString = 'sick, wicked';
var overrides = {'sick': 10, 'wicked': 10 };
jn1.receive({payload:testString,overrides:overrides});
});
});
it('should allow you to override word scoring - alternative property', function(done) {
var flow = [{id:"jn1",type:"mlsentiment",property:"foo",wires:[["jn2"]]},
{id:"jn2", type:"helper"}];
helper.load(sentimentNode, flow, function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.equal(20);
done();
});
var testString = 'sick, wicked';
var overrides = {'sick': 10, 'wicked': 10 };
jn1.receive({foo:testString,overrides:overrides});
});
});
});