This commit is contained in:
Patrick Jentsch
2019-11-27 13:29:43 +01:00
parent 5411bd91bd
commit 54f3036d89
2 changed files with 71 additions and 25 deletions

View File

@ -42,6 +42,7 @@
<div class="card">
<div class="card-content">
<span class="card-title">Query Link</span>
<form id="download-form" method="POST">
{{ query_download_form.hidden_tag() }}
<span class="card-title">Download Results</span>
@ -124,39 +125,55 @@
let queryData = {"context": formData.get("context"),
"hits_per_page": formData.get("hits_per_page"),
"query": formData.get("query")};
socket.emit('corpus_analysis', queryData);
M.toast({html: 'Query has been sent!'});
socket.emit("corpus_analysis", queryData);
M.toast({html: "Query has been sent!"});
});
socket.on('corpus_analysis', function(result) {
console.log(result['matches']);
var htmlString;
socket.on("corpus_analysis", function(result) {
console.log(result);
var htmlString = "";
var token;
if (result['matches'].length === 0) {
M.toast({html: 'No results!'});
}
for (let match of result['matches']) {
htmlString = `<tr class="match">`;
htmlString += `<tr class="match">`;
htmlString += `<td class="title"></td>`
htmlString += `<td class="left-context">`;
for (cpos of match['lc']) {
token = result['cpos_lookup'][cpos];
htmlString += `<span data-cpos="${cpos}">${token['word']}</span>`;
for (cpos of match["lc"]) {
token = result["cpos_lookup"][cpos];
htmlString += token["simple_pos"] != "PUNCT" ? " " : "";
htmlString += `<span class="token" data-cpos="${cpos}">${token["word"]}</span>`;
}
htmlString += `</td>`;
htmlString += `<td class="hit">`;
for (cpos of match["hit"]) {
token = result['cpos_lookup'][cpos];
htmlString += `<span data-cpos="${cpos}">${token['word']}</span>`;
token = result["cpos_lookup"][cpos];
htmlString += token["simple_pos"] != "PUNCT" ? " " : "";
htmlString += `<span class="token" 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>`;
for (cpos of match["rc"]) {
token = result["cpos_lookup"][cpos];
htmlString += token["simple_pos"] != "PUNCT" ? " " : "";
htmlString += `<span class="token" data-cpos="${cpos}">${token["word"]}</span>`;
}
htmlString += `</td>`;
htmlString += `</tr>`;
queryResultsElement.insertAdjacentHTML("beforeend", htmlString);
}
queryResultsElement.innerHTML = htmlString;
queryResultsElement.querySelectorAll(".token").forEach(function(tokenElement) {
tokenElement.addEventListener("click", function(event) {
let token = result["cpos_lookup"][tokenElement.dataset.cpos];
let text = result["text_loopup"][token["text_id"]];
alert(`${token["word"]} // ${token["pos"]} // ${token["simple_pos"]} // ${text["title"]}`);
});
});
});
</script>
{% endblock %}