-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (53 loc) · 2.36 KB
/
Copy pathmain.js
File metadata and controls
64 lines (53 loc) · 2.36 KB
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
var svg = d3.select("svg.viz");
var topics = [];
// this API Key will only work on Algorithmia's website; get your own key at https://algorithmia.com/user#credentials
var client = Algorithmia.client('simqgqIaOE5ScOF4+Wb/L+VsIXg1');
// Update visualization on page load
window.addEventListener("load", function() {
updateD3();
});
// Render data using D3
function updateD3() {
var width = $(".viz-container").width();
var height = $(".viz-container").height();
Algorithmia.viz.drawTopics(svg, topics, width, height);
};
function analyze() {
document.getElementById("demo-status").innerHTML = "";
// Build instance
var numTopics = document.getElementById("numTopics").value;
var strings = document.getElementById("inputStrings").value;
// Twitter Search Input
var searchString = strings;
document.getElementById("tweets-in").innerHTML = "<pre>"+JSON.stringify(searchString, null, 2)+"</pre>";
// Search for tweets
client.algo("/diego/RetrieveTweetsWithKeyword").pipe(searchString).then(function(tweets) {
// Print debug output
if(tweets.error) {
document.getElementById("tweets-out").innerHTML = '<span class="text-danger">' + (tweets.error.message || tweets.error) + '</span>';
document.getElementById("demo-status").innerHTML = '<span class="text-danger">' + (tweets.error.message || tweets.error) + '</span>';
return;
}
document.getElementById("tweets-out").innerHTML = "<pre>" + JSON.stringify(tweets.result, null, 2) + "</pre>";
// LDA Input
var algorithmInput = [
tweets.result,
numTopics
];
document.getElementById("topics-in").innerHTML = "<pre>"+JSON.stringify(algorithmInput, null, 2)+"</pre>";
// Query topic analysis
client.algo("/nlp/LDA").pipe(algorithmInput).then(function(new_topics) {
// Print debug output
if(new_topics.error) {
document.getElementById("topics-out").innerHTML = '<span class="text-danger">' + (new_topics.error.message || new_topics.error) + '</span>';
document.getElementById("demo-status").innerHTML = '<span class="text-danger">' + (new_topics.error.message || new_topics.error) + '</span>';
return;
}
document.getElementById("topics-out").innerHTML = "<pre>" + JSON.stringify(new_topics.result, null, 2) + "</pre>";
topics = [];
updateD3();
topics = new_topics.result;
updateD3();
});
});
};