-
Notifications
You must be signed in to change notification settings - Fork 1
/
isthatsmart.js
47 lines (36 loc) · 1.15 KB
/
isthatsmart.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
var TweetSamples = {
drug_names: ["ritalin", "adderall"],
positive: ["I need my ritalin",
"I can't focus, need ritalin"],
negative: ["Ritalin is funny",
"My kid is on ritalin because he has ADHD"]
}
var natural = require('natural');
var TweetClassifier = exports.TweetClassifier = functions(options) {
for (var o in options) {
this[o] = options[o];
}
}
TweetClassifier.prototype.init = function() {
this.engine = new natural.BayesClassifier();
for(var drugNameIdx in TweetSamples.drug_names) {
var drugName = TweetSamples.drug_names[drugNameIdx];
for(var positiveIdx in TweetSamples.positive) {
var cleanString = TweetSamples.positive[positiveIdx];
cleanString.replace("###", drugName);
this.engine.addDocument(cleanString, "1");
}
for(var negativeIdx in TweetSamples.negative) {
var cleanString = TweetSamples.negative[negativeIdx];
cleanString.replace("###", drugName);
this.engine.addDocument(cleanString, "0");
}
}
}
TweetClassifier.prototype.classify = function(tweetData) {
var retVal = false;
if(parseInt(this.engine.classify(tweetData))) {
retVal = true;
}
return retVal;
}