-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentiment.js
131 lines (110 loc) · 3.07 KB
/
sentiment.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var sentiment = require('sentiment');
var fs = require('fs');
var midiFile = require('jsmidgen');
var AlchemyAPI = require('alchemy-api');
var alchemy = new AlchemyAPI('c3c38a35951890872f9d5670ba6668cd368b3d7c');
var file = new midiFile.File();
var track = new midiFile.Track();
file.addTrack(track);
var score = [];
var music = [];
var alchemyScore = [];
var text;
var textArray;
//var text = "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?'"
fs.readFile('books/alice_scrubbed', 'utf-8', (err, data) => {
if (err) throw err;
textArray = data.split('.');
for (i =0; i < 3; i++) {
var blah = '';
var blah2 = '';
var blah3 = '';
//console.log(sentiment(textArray[i]))
score[i] = sentiment(textArray[i]).score;
alchemy.sentiment(textArray[i], {}, function(err, response) {
if (err) throw err;
// See http://www.alchemyapi.com/api/ for format of returned object
alchemySentiment = response.docSentiment;
console.log(JSON.stringify(alchemySentiment));
// Do something with data
alchemyScore.push( JSON.stringify(alchemySentiment));
})
if (score[i] % 7 === 0) {
blah += 'c';
} else if (score[i] % 7 == 1 || score[i] % 7 == -1) {
blah += 'd';
} else if (score[i] % 7 == 2 || score[i] % 7 == -2) {
blah += 'e';
} else if (score[i] % 7 == 3 || score[i] % 7 == -3) {
blah += 'f';
} else if (score[i] % 7 == 4 || score[i] % 7 == -4) {
blah += 'g';
} else if (score[i] % 7 == 5 || score[i] % 7 == -5) {
blah += 'a';
} else if (score[i] % 7 == 6 || score[i] % 7 == -6) {
blah += 'b';
} else {
console.log('wut');
}
if (score[i] < -5) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < -4) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < -3) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < -2) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < -1) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < 0) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < 1) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < 2) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < 3) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else if (score[i] < 4) {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
} else {
blah2 = blah + 4;
blah3 = blah + 6;
blah += 2;
}
chord = [blah, blah2, blah3];
music.push(chord);
}
for (var j = 0; j < music.length; j++ ) {
track.note(0, music[j][0], 64);
track.noteOn(0, music[j][1]);
track.noteOn(0, music[j][2]);
}
fs.writeFileSync('test.mid', file.toBytes(), 'binary');
});
setTimeout(writeFile,3000);
function writeFile(){
fs.writeFile('alice-test.json', alchemyScore, (err) => {
console.log('write file function');
if (err) throw err;
});
}