mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
Handle new data structure
This commit is contained in:
parent
9f42b9b99d
commit
d63b5ec266
@ -103,78 +103,60 @@
|
|||||||
<script>
|
<script>
|
||||||
var loadingModal;
|
var loadingModal;
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
loadingModal = M.Modal.init(document.getElementById("loading-modal"),
|
loadingModal = M.Modal.init(document.getElementById("loading-modal"),
|
||||||
{"dismissible": false});
|
{"dismissible": false});
|
||||||
loadingModal.open();
|
loadingModal.open();
|
||||||
|
socket.emit("request_corpus_analysis", {{ corpus_id }});
|
||||||
});
|
});
|
||||||
socket.emit('request_corpus_analysis', {{ corpus_id }});
|
|
||||||
socket.on('request_corpus_analysis', function(msg) {
|
socket.on("request_corpus_analysis", function(msg) {
|
||||||
if (msg === '[201]: Created') {loadingModal.close();}
|
if (msg === "[201]: Created") {loadingModal.close();}
|
||||||
});
|
});
|
||||||
|
|
||||||
var queryFormElement = document.getElementById("query-form");
|
var queryFormElement = document.getElementById("query-form");
|
||||||
var queryFormSubmitElement = document.getElementById("query-form-submit");
|
var queryFormSubmitElement = document.getElementById("query-form-submit");
|
||||||
var queryResultsElement = document.getElementById("query-results");
|
var queryResultsElement = document.getElementById("query-results");
|
||||||
|
|
||||||
queryFormSubmitElement.addEventListener('click', function(event) {
|
queryFormSubmitElement.addEventListener("click", function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let formData = new FormData(queryFormElement);
|
let formData = new FormData(queryFormElement);
|
||||||
let queryData = {'context': formData.get('context'),
|
let queryData = {"context": formData.get("context"),
|
||||||
'hits_per_page': formData.get('hits_per_page'),
|
"hits_per_page": formData.get("hits_per_page"),
|
||||||
'query': formData.get('query')};
|
"query": formData.get("query")};
|
||||||
socket.emit('corpus_analysis', queryData);
|
socket.emit('corpus_analysis', queryData);
|
||||||
M.toast({html: 'Query has been sent!'});
|
M.toast({html: 'Query has been sent!'});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('corpus_analysis', function(matches) {
|
socket.on('corpus_analysis', function(result) {
|
||||||
if (matches === null) {
|
console.log(result['matches']);
|
||||||
M.toast({html: 'Query has no results!'});
|
|
||||||
} else {
|
var htmlString;
|
||||||
console.log(matches);
|
var token;
|
||||||
let htmlString = "";
|
|
||||||
for (let match of Object.values(matches)) {
|
for (let match of result['matches']) {
|
||||||
niceMatch = matchInfo(match);
|
htmlString = `<tr class="match">`;
|
||||||
htmlString += `<tr><td>${niceMatch["text_title"]}</td><td>${niceMatch["left"]}</td><td>${niceMatch["match"]}</td><td>${niceMatch["right"]}</td></tr>`;
|
htmlString += `<td class="left-context">`;
|
||||||
|
for (cpos of match['lc']) {
|
||||||
|
token = result['cpos_lookup'][cpos];
|
||||||
|
htmlString += `<span data-cpos="${cpos}">${token['word']}</span>`;
|
||||||
}
|
}
|
||||||
queryResultsElement.innerHTML = htmlString;
|
htmlString += `</td>`;
|
||||||
|
htmlString += `<td class="hit">`;
|
||||||
|
for (cpos of match["hit"]) {
|
||||||
|
token = result['cpos_lookup'][cpos];
|
||||||
|
htmlString += `<span data-cpos="${cpos}">${token['word']}</span>`;
|
||||||
|
}
|
||||||
|
htmlString += `</td>`;
|
||||||
|
htmlString += `<td class="right-context">`;
|
||||||
|
for (cpos of match['rc']) {
|
||||||
|
token = result['cpos_lookup'][cpos];
|
||||||
|
htmlString += `<span data-cpos="${cpos}">${token['word']}</span>`;
|
||||||
|
}
|
||||||
|
htmlString += `</td>`;
|
||||||
|
htmlString += `</tr>`;
|
||||||
|
queryResultsElement.insertAdjacentHTML("beforeend", htmlString);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function matchInfo(match) {
|
|
||||||
var niceMatch = {"left": "", "match": "", "right": ""};
|
|
||||||
var tmp = Object.values(Object.values(match["match_cpos"])[0])[0];
|
|
||||||
niceMatch["text_author"] = tmp["text_author"][1];
|
|
||||||
niceMatch["text_title"] = tmp["text_title"][1];
|
|
||||||
niceMatch["publishing_year"] = tmp["text_publishing_year"][1];
|
|
||||||
for (let token of Object.values(match['left_context_cpos'])) {
|
|
||||||
tmp = Object.values(token)[0];
|
|
||||||
if (tmp["simple_pos"] != "PUNCT") {niceMatch["left"] += " ";}
|
|
||||||
niceMatch["left"] += '<span class="token">'
|
|
||||||
+ '<span class="word">' + tmp["word"] + '</span>'
|
|
||||||
+ '<span class="pos">' + tmp["pos"] + '</span>'
|
|
||||||
+ '<span class="lemma">' + tmp["lemma"] + '</span>'
|
|
||||||
+ '</span>';
|
|
||||||
}
|
|
||||||
for (let token of Object.values(match['match_cpos'])) {
|
|
||||||
tmp = Object.values(token)[0];
|
|
||||||
if (tmp["simple_pos"] != "PUNCT") {niceMatch["match"] += " ";}
|
|
||||||
niceMatch["match"] += '<span class="token" data-cpos="">'
|
|
||||||
+ '<span class="word">' + tmp["word"] + '</span>'
|
|
||||||
+ '<span class="pos">' + tmp["pos"] + '</span>'
|
|
||||||
+ '<span class="lemma">' + tmp["lemma"] + '</span>'
|
|
||||||
+ '</span>';
|
|
||||||
}
|
|
||||||
for (let token of Object.values(match['right_context_cpos'])) {
|
|
||||||
tmp = Object.values(token)[0];
|
|
||||||
if (tmp["simple_pos"] != "PUNCT") {niceMatch["right"] += " ";}
|
|
||||||
niceMatch["right"] += '<span class="token">'
|
|
||||||
+ '<span class="word">' + tmp["word"] + '</span>'
|
|
||||||
+ '<span class="pos">' + tmp["pos"] + '</span>'
|
|
||||||
+ '<span class="lemma">' + tmp["lemma"] + '</span>'
|
|
||||||
+ '</span>';
|
|
||||||
}
|
|
||||||
return niceMatch
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user