-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (51 loc) · 1.86 KB
/
script.js
File metadata and controls
61 lines (51 loc) · 1.86 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
// Cite: https://stackoverflow.com/a/18324384
function callAjax(url, callback){
var xmlhttp;
// compatible with IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
callback(xmlhttp.responseText);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
// We use AWS Lambda for actual processing.
var base_url = "https://64zej0ymo1.execute-api.us-east-2.amazonaws.com/prod";
var url = base_url + "/nol_parser" + window.location.search;
function include_results(response_text) {
parsed = JSON.parse(response_text);
// Cite: https://www.w3schools.com/js/js_htmldom_nodes.asp
var text = JSON.stringify(parsed['parts-of-speech'], null, 2);
var para = document.createElement("p");
var node = document.createTextNode(text);
para.appendChild(node);
var token_div = document.getElementById("div-token");
token_div.appendChild(para);
for (i in parsed['trees']) {
var div = document.createElement("div");
var tree_div = document.getElementById("div-tree");
div.innerHTML = parsed['trees'][i];
tree_div.appendChild(div);
}
};
// Cite: https://stackoverflow.com/a/14853880
var counter = 0;
function add_annotation_field() {
var container = document.getElementById("container");
function add_input(label, name) {
container.appendChild(document.createTextNode(label));
var input = document.createElement("input");
input.type = "text";
input.name = name;
container.appendChild(input);
}
add_input("Index: ", "index" + counter);
add_input("Value: ", "value" + counter);
container.appendChild(document.createElement("br"));
counter += 1;
}
if (window.location.search) {
callAjax(url, include_results);
}