diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 index a5a303cb..abe800eb 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -115,14 +115,50 @@ socket.on('init_corpus_analysis', function(msg) { if (msg === 'Ready') {loadingModal.close();} }); + function decodeResults(resultsByteArray) { + console.log(resultsByteArray); + var decompressedData = pako.inflate(resultsByteArray); // decompresses the recieved ArrayBuffer holding the compressed Byte data + console.log(decompressedData); + utf8decoder = new TextDecoder(); // default is utf-8 + var decodedStrData = utf8decoder.decode(decompressedData); // decodes the decompressed Uint8Array as an utf-8 string + console.log(decodedStrData); + return decodedStrData + } + function getResultInfos(matchObject) { + for (var key in matchObject) { + var token = matchObject[key]; + for (var key in token) { + infos += token[key]['word'] + ' '; + } + var infos = infos; + } + return infos + } socket.on('query', function(results) { - queryResultsElement.innerHTML = ''; - console.log(results) - var decoder = new TextDecoder().decode(results) - console.log(results) - for (let key in results) { - console.log(results[key]); - queryResultsElement.innerHTML += '

' + results[key]['match_cpos_list'] + '

'; + console.log(results); + var decodedJSONStr = decodeResults(results); + var results = JSON.parse(decodedJSONStr); + if (results === null){ + M.toast({html: 'Query has no results!'}); + } + else { + console.log(results); + html_txt = ''; + for (var key in results) { + var hit = results[key]; + var left_context = hit['context_before_cpos_list'] + var match = hit['match_cpos_list'] + var right_context = hit['context_after_cpos_list'] + var l_text = getResultInfos(left_context) + var m_text = getResultInfos(match) + var r_text = getResultInfos(right_context) + html_txt += ''; + l_text = ''; + m_text = ''; + } + html_txt += '
Left contextMatchRight Context
' + l_text + '' + m_text + '' + r_text + '
'; + console.log(html_txt); + queryResultsElement.innerHTML = html_txt; } });