forked from mitushaa/Sentiment-Analysis-using-node.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
47 lines (36 loc) · 999 Bytes
/
sketch.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
var afinn;
function preload() {
afinn = loadJSON('afinn111.json');
}
//adding a new afinn 111 dictionary
function setup() {
noCanvas();
console.log(afinn);
var txt = select('#txt');
txt.input(typing);
function typing() {
var textinput = txt.value();
var words = textinput.split(/\W/);
console.log(words);
var scoredwords = [];
var totalScore = 0;
for (var i = 0; i < words.length; i++) {
var word = words[i].toLowerCase();
if (afinn.hasOwnProperty(word)) {
var score = afinn[word];
console.log(word, score);
totalScore += Number(score);
scoredwords.push(word + ': ' + score + ' ');
}
}
var scorePar = select('#scoreP');
scorePar.html('score: ' + totalScore);
var comp = select('#comparativeP');
comp.html('comparative: ' + totalScore / words.length);
var wordlist = select('#wordlistP');
wordlist.html(scoredwords);
//console.log(txt.value());
}
}
function draw() {
}