From 9b71fb0cc95d7e10a517e3672e05e88599955a0d Mon Sep 17 00:00:00 2001 From: Patrick Jentsch
Title | @@ -138,14 +130,18 @@ var expertModeSwitchElement = document.getElementById("expert-mode-switch"); var tokenElements = []; + var result; expertModeSwitchElement.addEventListener('change', function(event) { if (event.target.checked) { tokenElements.forEach(function(tokenElement) { - tokenElement.classList.add("token-box"); + tokenElement.classList.add("chip"); + token = result["cpos_lookup"][tokenElement.dataset.cpos]; + addToolTipToTokenElement(tokenElement, token); }); } else { tokenElements.forEach(function(tokenElement) { - tokenElement.classList.remove("token-box"); + tokenElement.classList.remove("chip"); + tokenElement.M_Tooltip.destroy() }); } }) @@ -163,61 +159,95 @@ M.toast({html: "Query has been sent!"}); }); - socket.on("corpus_analysis", function(result) { - console.log(result); - var htmlString = ""; + socket.on("corpus_analysis", function(message) { + var matchElement; + var matchTextTitlesElement; + var matchLeftContextElement; + var matchHitElement; + var matchRightContextElement; var textTitles; var token; + var tokenElement; - if (result['matches'].length === 0) { - M.toast({html: 'No results!'}); - } + result = message; + + queryResultsElement.innerHTML = ""; for (let match of result['matches']) { - htmlString += `|||
---|---|---|---|
`; + matchElement = document.createElement("tr"); + matchElement.classList.add("match"); + matchTextTitlesElement = document.createElement("td"); + matchTextTitlesElement.classList.add("text-titles"); + matchElement.append(matchTextTitlesElement); + matchLeftContextElement = document.createElement("td"); + matchLeftContextElement.classList.add("left-context"); + for (cpos of match["lc"]) { + token = result["cpos_lookup"][cpos]; + tokenElement = document.createElement("span"); + tokenElement.classList.add("token"); + tokenElement.dataset.cpos = cpos; + tokenElement.innerText = token["word"]; + if (expertModeSwitchElement.checked) { + tokenElement.classList.add("chip"); + addToolTipToTokenElement(tokenElement, token); + } + matchLeftContextElement.append(tokenElement); + matchLeftContextElement.append(document.createTextNode(" ")); + tokenElements.push(tokenElement); + } + matchElement.append(matchLeftContextElement); + matchHitElement = document.createElement("td"); + matchHitElement.classList.add("hit"); textTitles = new Set(); for (cpos of match["hit"]) { token = result["cpos_lookup"][cpos]; + tokenElement = document.createElement("span"); + tokenElement.classList.add("token"); + tokenElement.dataset.cpos = cpos; + tokenElement.innerText = token["word"]; + if (expertModeSwitchElement.checked) { + tokenElement.classList.add("chip"); + addToolTipToTokenElement(tokenElement, token); + } + matchHitElement.append(tokenElement); + matchHitElement.append(document.createTextNode(" ")); + tokenElements.push(tokenElement); textTitles.add(result["text_loopup"][token["text_id"]]["title"]); } - htmlString += [...textTitles].join(","); - htmlString += ` | `; - htmlString += ``; - for (cpos of match["lc"]) { - token = result["cpos_lookup"][cpos]; - htmlString += " "; - htmlString += `${token["word"]}`; - } - htmlString += ` | `; - htmlString += ``; - for (cpos of match["hit"]) { - token = result["cpos_lookup"][cpos]; - htmlString += " "; - htmlString += `${token["word"]}`; - } - htmlString += ` | `; - htmlString += ``; + matchTextTitlesElement.innerText = [...textTitles].join(","); + matchElement.append(matchHitElement); + matchRightContextElement = document.createElement("td"); + matchRightContextElement.classList.add("right-context"); for (cpos of match["rc"]) { token = result["cpos_lookup"][cpos]; - htmlString += " "; - htmlString += `${token["word"]}`; + tokenElement = document.createElement("span"); + tokenElement.classList.add("token"); + tokenElement.dataset.cpos = cpos; + tokenElement.innerText = token["word"]; + if (expertModeSwitchElement.checked) { + tokenElement.classList.add("chip"); + addToolTipToTokenElement(tokenElement, token); + } + matchRightContextElement.append(tokenElement); + matchRightContextElement.append(document.createTextNode(" ")); + tokenElements.push(tokenElement); } - htmlString += ` | `; - htmlString += `