-
Notifications
You must be signed in to change notification settings - Fork 2
/
parsing.js
118 lines (95 loc) · 3.74 KB
/
parsing.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
function initParseModalButton() {
document.getElementById('parse-modal').classList.remove("hidden");
document.getElementById('parse-overlay').classList.remove("hidden");
}
function initGetParsedModalButton(parse_data_id) {
// hides the parse-modal
document.getElementById('parse-modal').classList.add("hidden");
document.getElementById('parse-overlay').classList.add("hidden");
// show the update tree modal
document.getElementById('get-parsed-modal').classList.remove("hidden");
document.getElementById('get-parsed-overlay').classList.remove("hidden");
// set up button that sends a request to the backend to get the new trees
closeButton = document.getElementById("get-parsed-btn");
closeButton.textContent = 'View trees';
closeButton.addEventListener('click', () => {
document.getElementById('get-parsed-modal').classList.add("hidden");
document.getElementById('get-parsed-overlay').classList.add("hidden");
getParsedData(parse_data_id)
});
}
function parseFile() {
let textSentences = $("#treedata2").val();
let parserType = $("#select-parser").val();
// removing empty lines
textSentences = textSentences.split("\n");
textSentences = textSentences.filter(function(el) { return el != ""});
if(parserType === "") {
alert("Please select a parser");
return;
}
let myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
let raw = JSON.stringify({"sentences": textSentences, "parserType": parserType});
let requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://mra9407.pythonanywhere.com/parse_data", requestOptions)
.then(res => res.text())
.then(data => {
initGetParsedModalButton(data)
})
.catch(error => console.log('error', error));
initParseModalButton();
}
// var readConfigFileForParsedSentences = async function () {
// await readConfigFile();
// }
function getParsedData(parse_data_id) {
let myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
let requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch(`https://mra9407.pythonanywhere.com/get_parsed_data?data_id=${parse_data_id}`, requestOptions)
.then(response => response.text())
.then(data => {
readConfigFile();
// readConfigFileForParsedSentences();
treesArray = convertToJSON(data);
currentTreeIndex = 0;
UndoRedoHelperOnTreePageSetUp();
view([$(".upload")], hideComponents);
addFilenameToHtmlElements('Untitled.conllx');
getTree(treesArray[0]);
isConlluLocal = true;
})
.catch(error => console.log('error', error));
// fetch(`https://mra9407.pythonanywhere.com/get_parsed_data/?parsed_conll_file_id=${parse_data_id}`, {method: 'GET'})
// .then(res => res.json())
// .then(data => {
// file_data = data[0]['parsed_data'];
// treesArray = convertToJSON(file_data);
// // reinitialize trees
// // setupPageZero(file_data);
// // UndoRedoHelperOnTreePageSetUp();
// // hide upload window
// view([$(".upload")], hideComponents);
// getTree(treesArray[0]);
// // sessionStorage.removeItem("treeData");
// // saveTree();
// // d3.select("body").select("svg").remove();
// // getTree(json_data);
// // update(root);
// // selectRoot();
// // showSelection();
// // // reset focusWindow
// // focusWindow = "";
// });
// // initParseModalButton();
}