Permalink
Browse files

Merge pull request #13 from andremw/master

Removing duplicate code
  • Loading branch information...
2 parents 9b0b4f8 + 41e764f commit bd80b17b5cd0aa9235449d81a32bf7da580f1ed6 @thinkroth committed on GitHub Jul 24, 2016
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/sentimental.js
View
10 lib/sentimental.js
@@ -1,5 +1,9 @@
var afinn = require('../wordLists/afinn.json');
+var tokenizeWithNoPunctuation = function (phrase) {
+ var noPunctuation = phrase.replace(/[^a-zA-Z ]+/g, ' ').replace('/ {2,}/',' ');
+ return noPunctuation.toLowerCase().split(" ");
+};
// Calculates the negative sentiment of a sentence
// -------------------------------------------------- //
@@ -10,8 +14,7 @@ function negativity (phrase) {
words.push(t);
};
- var noPunctuation = phrase.replace(/[^a-zA-Z ]+/g, ' ').replace('/ {2,}/',' '),
- tokens = noPunctuation.toLowerCase().split(" "),
+ var tokens = tokenizeWithNoPunctuation(phrase),
hits = 0,
words = [];
@@ -40,8 +43,7 @@ function positivity (phrase) {
words.push(t);
};
- var noPunctuation = phrase.replace(/[^a-zA-Z ]+/g, ' ').replace('/ {2,}/',' '),
- tokens = noPunctuation.toLowerCase().split(" "),
+ var tokens = tokenizeWithNoPunctuation(phrase),
hits = 0,
words = [];

0 comments on commit bd80b17

Please sign in to comment.