polarity-rate
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "polarity-rate", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Text miner, polarity rater with results between -100% and +100%", | ||
@@ -30,3 +30,3 @@ "main": "polarity-rate.js", | ||
"xregexp": "^3.2.0", | ||
"franc-min": "^3.1.1" | ||
"xlsx": "^0.11.13" | ||
}, | ||
@@ -33,0 +33,0 @@ "devDependencies": { |
var XLSX = require('xlsx'); | ||
var XRegExp = require('xregexp'); | ||
const RATE_LIMIT = 5; | ||
var franc = require('franc-min'); | ||
function _cleanText(text) { | ||
//https://www.npmjs.com/package/stopwords-iso | ||
//mail find? | ||
//initial clean | ||
let cleanedText = XRegExp.replace(text,XRegExp('[^\\pL]+','g'), ' ').toLowerCase(); | ||
//cross check lang dedection libraries. | ||
//language dedection, top 2 lang | ||
console.log(franc.all(cleanedText, {blacklist: []})); | ||
let termArr = cleanedText.split(' '); | ||
let cleanedTermArr = new Array(termArr.length); | ||
for(let i=0,j=0;i<termArr.length;i++){ | ||
if(termArr[0] !== undefined && termArr[0].length>3) | ||
{ | ||
} | ||
} | ||
//clear word less then 4 length. | ||
//clear stopword by default and current language | ||
//build ngaram array | ||
//return text.replace(/[^a-zA-Z0-9ğĞçÇöÖüÜıIİişŞ]/g,' ').replace(/[\s]+/gm,' ').replace(/\s[a-zA-Z0-9ğĞçÇöÖüÜıIİişŞ]{1,3}\s/g,' ').replace(/[\s]+/g,' ').toLowerCase().trim(); | ||
return cleanedText; | ||
} | ||
function _getWordList(fileName) | ||
@@ -124,3 +89,3 @@ { | ||
*/ | ||
function _calculate(findedWordsMap) | ||
function _calculate(findedWordsMap,rateLimit) | ||
{ | ||
@@ -162,3 +127,3 @@ let rate = 0; | ||
{ | ||
let tempRate = rate + (100 - rate)*point/(100.0*RATE_LIMIT); | ||
let tempRate = rate + (100 - rate)*point/(100.0*rateLimit); | ||
rate = tempRate >= 100 ? rate : tempRate; | ||
@@ -168,3 +133,3 @@ } | ||
{ | ||
let tempRate = rate + (100 + rate)*point/(100.0*RATE_LIMIT); | ||
let tempRate = rate + (100 + rate)*point/(100.0*rateLimit); | ||
rate = tempRate <= -100 ? rate : tempRate; | ||
@@ -191,3 +156,3 @@ } | ||
*/ | ||
function Miner(text,wordList) { | ||
function Miner(text,wordList,rateLimit) { | ||
@@ -199,4 +164,13 @@ if (typeof wordList == 'undefined') | ||
if (typeof rateLimit == 'undefined') | ||
{ | ||
rateLimit = RATE_LIMIT; | ||
} | ||
//sort list by lenght | ||
wordList.sort((a,b)=>a[0].length < b[0].length); | ||
// Storage objects | ||
text = _cleanText(text); | ||
//XRegExp.replace(text,XRegExp('[^\\pL]+','g'), ' ').toLowerCase(); | ||
text = XRegExp.replace(text,XRegExp('[^\\pL]+','g'), ' ').toLowerCase(); | ||
let wordCount = text.split(' ').length; | ||
@@ -274,3 +248,3 @@ let findedWordsMap = new Map(); | ||
let _result = _calculate(findedWordsMap); | ||
let _result = _calculate(findedWordsMap,rateLimit); | ||
@@ -295,6 +269,11 @@ let result = { | ||
{ | ||
var testWordList = _getWordList('WordListTest.xlsx'); | ||
var result = Miner("aaaa bbbb cccc dddd eeee",testWordList); | ||
//var testWordList = _getWordList('WordListTest.xlsx'); | ||
let wordList = [ | ||
["aaaa",10], | ||
["aaaa bbbb",50], | ||
["aaaa bbbb cccc xxxx",60] | ||
]; | ||
var result = Miner("aaaa bbbb cccc dddd eeee",wordList); | ||
console.log(result); | ||
} | ||
//const PolarityRate = require('polarity-rate'); | ||
const PolarityRate = require('./'); | ||
const PolarityRate = require('./'); | ||
var XRegExp = require('xregexp'); | ||
var unicodeWord = XRegExp('^\\pL+$'); | ||
console.log(XRegExp.replace('şşğğğiiIIğğğРусский 111 日本語 222العربية ------ 💩💩💩',XRegExp('[^\\pL]+','g'), ' ')); | ||
var noneUnicodeBlock = XRegExp('[^\\pL]+','g'); | ||
console.log('şşğğğiiIIğğğРусский 111 日本語 222العربية ------ 💩💩💩'.replace(noneUnicodeBlock,' ')); |
@@ -21,3 +21,10 @@ # polarity-rate | ||
let text = "aaaa bbbb cccc dddd eeee"; | ||
let wordList = [ | ||
["aaaa",10], | ||
["aaaa bbbb",50], | ||
["aaaa bbbb cccc xxxx",60] | ||
]; | ||
var result = PolarityRate(text,wordList); | ||
console.log(result.rate);//50.1 | ||
``` | ||
@@ -24,0 +31,0 @@ |
const assert = require('assert'); | ||
const PolarityRate = require('../'); | ||
describe('contains test', function() { | ||
it('should match', function() { | ||
//let res = EasyMatch(['it@abc.com','itit@abc.com','xyz@abc.com', 'abcit@domain.com','abcit@'], ['it@']); | ||
//assert.equal(res.valid.length,4); | ||
describe('negative-positive must be equal', function() { | ||
it('should equal', function() { | ||
let text = "aaaa bbbb cccc dddd eeee"; | ||
let positiveWordList = [ | ||
["aaaa",10], | ||
["aaaa bbbb",50], | ||
["aaaa bbbb cccc xxxx",60] | ||
]; | ||
var positiveResult = PolarityRate(text,positiveWordList); | ||
let negativeWordList = [ | ||
["aaaa",-10], | ||
["aaaa bbbb",-50], | ||
["aaaa bbbb cccc xxxx",-60] | ||
]; | ||
var negativeResult = PolarityRate(text,negativeWordList); | ||
assert.equal(positiveResult.rate,-1*negativeResult.rate); | ||
}); | ||
}); | ||
describe('unicode negative-positive must be equal', function() { | ||
it('should equal', function() { | ||
let text = "şşğI кийй 日本語語 العربية eeee"; | ||
let positiveWordList = [ | ||
["şşğI",10], | ||
["şşğI кийй",50], | ||
["şşğI кийй 日本語語 xxxx",60] | ||
]; | ||
var positiveResult = PolarityRate(text,positiveWordList); | ||
let negativeWordList = [ | ||
["şşğI",-10], | ||
["şşğI кийй",-50], | ||
["şşğI кийй 日本語語 xxxx",-60] | ||
]; | ||
var negativeResult = PolarityRate(text,negativeWordList); | ||
assert.equal(positiveResult.rate,-1*negativeResult.rate); | ||
}); | ||
}); | ||
@@ -7,3 +7,3 @@ var XRegExp = require('xregexp'); | ||
console.log(XRegExp.replace('şşğğğiiIIğğğРусский 111 日本語 222العربية ------ 💩💩💩',XRegExp('[^\\pL]+','g'), ' ')); | ||
console.log(XRegExp.replace('şşğğğiiIIğğğРусский 111 日本語 ------ 💩💩💩',XRegExp('[^\\pL]+','g'), ' ')); | ||
@@ -14,2 +14,2 @@ | ||
var noneUnicodeBlock = XRegExp('[^\\pL]+','g'); | ||
console.log('şşğğğiiIIğğğРусский 111 日本語 222العربية ------ 💩💩💩'.replace(noneUnicodeBlock,' ')); | ||
console.log('şşğğğiiIIğğğРусский 111 日本語 العربية ------ 💩💩💩'.replace(noneUnicodeBlock,' ')); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
298
35
41571
13
+ Addedxlsx@^0.11.13
+ Addedadler-32@1.2.0(transitive)
+ Addedcfb@1.0.8(transitive)
+ Addedcodepage@1.12.2(transitive)
+ Addedcommander@2.13.02.14.12.20.3(transitive)
+ Addedcrc-32@1.2.2(transitive)
+ Addedexit-on-epipe@1.0.1(transitive)
+ Addedfrac@1.1.2(transitive)
+ Addedprintj@1.1.2(transitive)
+ Addedssf@0.10.3(transitive)
+ Addedxlsx@0.11.19(transitive)
- Removedfranc-min@^3.1.1
- Removedcollapse-white-space@1.0.6(transitive)
- Removedfranc-min@3.1.1(transitive)
- Removedn-gram@1.1.2(transitive)
- Removedtrigram-utils@1.0.3(transitive)
- Removedtrim@0.0.1(transitive)