Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Even better handling of punctuation and hashtags

  • Loading branch information...
commit cf998b87d531c046eaeab0566593468270b068f7 1 parent 99656ed
@thinkroth authored
Showing with 8 additions and 3 deletions.
  1. +2 −2 lib/sentimental.js
  2. +6 −1 test/test.js
View
4 lib/sentimental.js
@@ -20,7 +20,7 @@ function negativity (phrase) {
words.push(t);
};
- var noPunctuation = phrase.replace(/[^\w\s]|_/g,"").replace(/\s+/g," "),
+ var noPunctuation = phrase.replace(/[^a-zA-Z ]+/g, '').replace('/ {2,}/',' '),
tokens = noPunctuation.toLowerCase().split(" "),
hits = 0,
words = [];
@@ -56,7 +56,7 @@ function positivity (phrase) {
words.push(t);
};
- var noPunctuation = phrase.replace(/[^\w\s]|_/g,"").replace(/\s+/g," "),
+ var noPunctuation = phrase.replace(/[^a-zA-Z ]+/g, '').replace('/ {2,}/',' '),
tokens = noPunctuation.toLowerCase().split(" "),
hits = 0,
words = [];
View
7 test/test.js
@@ -93,11 +93,16 @@ describe('Analyze', function () {
analyze("Hey scumbag").score.should.equal(-4);
done();
});
- it('should ignore punctuation', function (done) {
+ it('should ignore ending punctuation', function (done) {
analyze("Fearless!").score.should.equal(2);
analyze("Crash!").score.should.equal(-2);
done();
});
+ it('should ignore hashtags', function (done) {
+ analyze("#fearless").score.should.equal(2);
+ analyze("#crash").score.should.equal(-2);
+ done();
+ });
});
describe('#comparative', function () {
it('should equal (positive - negative) / word count ', function (done) {
Please sign in to comment.
Something went wrong with that request. Please try again.