-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassifier.js
76 lines (61 loc) · 2.19 KB
/
classifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var words = require('./words');
var helper = require('./helper');
var _ = require('lodash');
var classifier = {};
// classifier.isBlacklistComposite = function(fn){
//
// }
classifier.isUserBlacklist = function (screen_name) {
var rank = words.userRank[screen_name];
return rank === 0;
};
classifier.isUserBlacklistRT = function (tweet) {
var userMatched = null;
_.some(words.userRank, function (value, key) {
if (value === 0 && tweet.text.match('RT @' + key)) {
userMatched = key;
return true;
}
});
return userMatched;
};
classifier.isTextBlacklist = function (tweet) {
return classifier.textLucky(tweet) === 0;
};
// Tem que haver alguma url sem ser https://twitter.com*, e não
// pode ter palavras da blacklist
classifier.validUrls = function(urlsCurrent) {
return _.filter(urlsCurrent, function(o){
return o.expanded_url.match(words.urlExceptions);
});
};
classifier.isValidUrls = function(urlsCurrent) {
var urls = classifier.validUrls(urlsCurrent);
return urls && urls.length > 0;
};
// retorna o menor level match, de 0 - 10. Senão 10 (default)
classifier.textLucky = function (tweet) {
var level = helper.filterTextMinMatch(words.textRank, tweet.text);
return level === undefined || level === null ? 10 : level;
};
// retorna o menor level match, de 0 - 10. Senão 10 (default)
classifier.userLucky = function (tweet) {
var level = helper.filterUserRankMatch(words.userRank, tweet.user.screen_name);
return level === undefined || level === null ? 10 : level;
};
classifier.isTextWhitelist = function (text) {
var pattern = words.textWhitelistPattern.toLowerCase();
var str = text.toLowerCase();
return str.match(pattern);
};
// retorna o maior bias matched, de 0 - j
classifier.biasRetweetValue = function (originalValue, tweet) {
var biasValue = helper.filterMaxMatch(words.textBiasPercent, tweet.text);
if(!_.isNumber(biasValue)) {
return originalValue;
}
// Arredonda: 1.4 = 1; 1.6 = 2; 1.5 = 2;
return _.round(helper.biasCalc(originalValue, biasValue));
};
module.exports = classifier;
// var userBlacklistRTPattern = new RegExp(_userBlacklistRT.join('|'));