-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalysis-name.js
executable file
·86 lines (74 loc) · 2.24 KB
/
analysis-name.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
var discoveryQuery = require('./discoveryQuery');
var utils = require('./utils');
/**
* Analyse person
* @param {String} catgeory - category to list authors for
*/
function listAuthors(category, dir){
// Analyse hits about a person
discoveryQuery.getAuthorsByCategory(category, writeResultToFile);
//Callback from getAuthorsByCategory to write results to file
function writeResultToFile(err, data){
if(err){
console.log(err);
}
else if(dir){
var processedData = [];
for(var i=0; i < data.length; i++){
var item = {
author: data[i].key,
documents: data[i].matching_results
};
processedData.push(item);
}
// Write data to file as CSV
var filename = 'authors_' + category.replace(/ /g, '_');
filename = category.replace(/\//g, '_') + '.csv';
filename = filename.toLowerCase();
utils.writeCsvDataTofile(dir + '/' + filename, processedData, ['author','documents'], function(writeErr){
if(writeErr){
console.log(writeErr);
}
});
}
};
}
/**
* Analyse person
* @param {String} name - person name
* @param {String} author - author's name
* @param {String} dir - path to output results to
*/
function aggregateSentiment(author, dir){
// Analyse hits about a person
discoveryQuery.getSentimentByAuthor(author, writeResultToFile);
//Callback from analyseTerms to write results to file
function writeResultToFile(err, data){
if(err){
console.log(err);
}
else if(dir){
// Uncomment to output personality insights to to console.
console.dir(data);
processedData = {
};
for(var i=0; i < data.length; i++){
var field = data[i].key;
var value = data[i].matching_results;
processedData[field] = value;
}
// Write data to file as CSV
var filename = 'sentiment_' + author.replace(/ /g, '_');
filename = filename.toLowerCase();
utils.writeCsvDataTofile(dir + '/' + filename + '.csv',processedData, ['negative','positive','neutral'], function(writeErr){
if(writeErr){
console.log(writeErr);
}
});
}
};
}
module.exports = {
listAuthors:listAuthors,
aggregateSentiment: aggregateSentiment
};