diff --git a/lib/sentimental.js b/lib/sentimental.js index 5386927..e2211e8 100644 --- a/lib/sentimental.js +++ b/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 = [];