Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
9b71fb0c
Commit
9b71fb0c
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add tooltips to query ui
parent
acedd35e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/corpora/events.py
+3
-2
3 additions, 2 deletions
app/corpora/events.py
app/templates/corpora/analyse_corpus.html.j2
+83
-53
83 additions, 53 deletions
app/templates/corpora/analyse_corpus.html.j2
with
86 additions
and
55 deletions
app/corpora/events.py
+
3
−
2
View file @
9b71fb0c
...
@@ -73,13 +73,14 @@ def corpus_analysis(message):
...
@@ -73,13 +73,14 @@ def corpus_analysis(message):
for
match
in
data
[
'
matches
'
]:
for
match
in
data
[
'
matches
'
]:
cpos_list
+=
match
[
'
lc
'
]
+
match
[
'
hit
'
]
+
match
[
'
rc
'
]
cpos_list
+=
match
[
'
lc
'
]
+
match
[
'
hit
'
]
+
match
[
'
rc
'
]
cpos_list
=
list
(
set
(
cpos_list
))
cpos_list
=
list
(
set
(
cpos_list
))
lemma_list
=
client
.
cl_cpos2str
(
'
{}.lemma
'
.
format
(
corpus
),
cpos_list
)
pos_list
=
client
.
cl_cpos2str
(
'
{}.pos
'
.
format
(
corpus
),
cpos_list
)
pos_list
=
client
.
cl_cpos2str
(
'
{}.pos
'
.
format
(
corpus
),
cpos_list
)
simple_pos_list
=
client
.
cl_cpos2str
(
'
{}.simple_pos
'
.
format
(
corpus
),
cpos_list
)
simple_pos_list
=
client
.
cl_cpos2str
(
'
{}.simple_pos
'
.
format
(
corpus
),
cpos_list
)
s_id_list
=
client
.
cl_cpos2struc
(
'
{}.s
'
.
format
(
corpus
),
cpos_list
)
s_id_list
=
client
.
cl_cpos2struc
(
'
{}.s
'
.
format
(
corpus
),
cpos_list
)
text_id_list
=
client
.
cl_cpos2struc
(
'
{}.text
'
.
format
(
corpus
),
cpos_list
)
text_id_list
=
client
.
cl_cpos2struc
(
'
{}.text
'
.
format
(
corpus
),
cpos_list
)
word_list
=
client
.
cl_cpos2str
(
'
{}.word
'
.
format
(
corpus
),
cpos_list
)
word_list
=
client
.
cl_cpos2str
(
'
{}.word
'
.
format
(
corpus
),
cpos_list
)
for
cpos
,
pos
,
simple_pos
,
s_id
,
text_id
,
word
in
zip
(
cpos_list
,
pos_list
,
simple_pos_list
,
s_id_list
,
text_id_list
,
word_list
):
for
cpos
,
lemma
,
pos
,
simple_pos
,
s_id
,
text_id
,
word
in
zip
(
cpos_list
,
lemma_list
,
pos_list
,
simple_pos_list
,
s_id_list
,
text_id_list
,
word_list
):
data
[
'
cpos_lookup
'
][
cpos
]
=
{
'
pos
'
:
pos
,
'
simple_pos
'
:
simple_pos
,
'
s_id
'
:
s_id
,
'
text_id
'
:
text_id
,
'
word
'
:
word
}
data
[
'
cpos_lookup
'
][
cpos
]
=
{
'
lemma
'
:
lemma
,
'
pos
'
:
pos
,
'
simple_pos
'
:
simple_pos
,
'
s_id
'
:
s_id
,
'
text_id
'
:
text_id
,
'
word
'
:
word
}
text_author_list
=
client
.
cl_struc2str
(
'
{}.text_author
'
.
format
(
corpus
),
text_id_list
)
text_author_list
=
client
.
cl_struc2str
(
'
{}.text_author
'
.
format
(
corpus
),
text_id_list
)
text_publishing_year_list
=
client
.
cl_struc2str
(
'
{}.text_publishing_year
'
.
format
(
corpus
),
text_id_list
)
text_publishing_year_list
=
client
.
cl_struc2str
(
'
{}.text_publishing_year
'
.
format
(
corpus
),
text_id_list
)
text_title_list
=
client
.
cl_struc2str
(
'
{}.text_title
'
.
format
(
corpus
),
text_id_list
)
text_title_list
=
client
.
cl_struc2str
(
'
{}.text_title
'
.
format
(
corpus
),
text_id_list
)
...
...
This diff is collapsed.
Click to expand it.
app/templates/corpora/analyse_corpus.html.j2
+
83
−
53
View file @
9b71fb0c
...
@@ -2,16 +2,8 @@
...
@@ -2,16 +2,8 @@
{% block page_content %}
{% block page_content %}
<style>
<style>
.token-box {
.token.chip:hover {
padding: 5px;
background-color: #9e9e9e;
margin: 2px 0;
border-radius: 5px;
background-color: #009688;
display: inline-block;
color: white;
}
.token-box:hover {
background-color: #00bfa5;
cursor: pointer;
cursor: pointer;
}
}
</style>
</style>
...
@@ -88,7 +80,7 @@
...
@@ -88,7 +80,7 @@
<div class="card-content">
<div class="card-content">
<span class="card-title">Query Results</span>
<span class="card-title">Query Results</span>
<div>
<div>
<table
class="highlight"
>
<table>
<thead>
<thead>
<tr>
<tr>
<th style="width: 5%">Title</th>
<th style="width: 5%">Title</th>
...
@@ -138,14 +130,18 @@
...
@@ -138,14 +130,18 @@
var expertModeSwitchElement = document.getElementById("expert-mode-switch");
var expertModeSwitchElement = document.getElementById("expert-mode-switch");
var tokenElements = [];
var tokenElements = [];
var result;
expertModeSwitchElement.addEventListener('change', function(event) {
expertModeSwitchElement.addEventListener('change', function(event) {
if (event.target.checked) {
if (event.target.checked) {
tokenElements.forEach(function(tokenElement) {
tokenElements.forEach(function(tokenElement) {
tokenElement.classList.add("token-box");
tokenElement.classList.add("chip");
token = result["cpos_lookup"][tokenElement.dataset.cpos];
addToolTipToTokenElement(tokenElement, token);
});
});
} else {
} else {
tokenElements.forEach(function(tokenElement) {
tokenElements.forEach(function(tokenElement) {
tokenElement.classList.remove("token-box");
tokenElement.classList.remove("chip");
tokenElement.M_Tooltip.destroy()
});
});
}
}
})
})
...
@@ -163,61 +159,95 @@
...
@@ -163,61 +159,95 @@
M.toast({html: "Query has been sent!"});
M.toast({html: "Query has been sent!"});
});
});
socket.on("corpus_analysis", function(result) {
socket.on("corpus_analysis", function(message) {
console.log(result);
var matchElement;
var htmlString = "";
var matchTextTitlesElement;
var matchLeftContextElement;
var matchHitElement;
var matchRightContextElement;
var textTitles;
var textTitles;
var token;
var token;
var tokenElement;
if (
result
['matches'].length === 0) {
result
= message;
M.toast({html: 'No results!'});
}
queryResultsElement.innerHTML = "";
for (let match of result['matches']) {
for (let match of result['matches']) {
htmlString += `<tr class="match">`;
matchElement = document.createElement("tr");
htmlString += `<td class="title">`;
matchElement.classList.add("match");
textTitles = new Set();
matchTextTitlesElement = document.createElement("td");
for (cpos of match["hit"]) {
matchTextTitlesElement.classList.add("text-titles");
token = result["cpos_lookup"][cpos];
matchElement.append(matchTextTitlesElement);
textTitles.add(result["text_loopup"][token["text_id"]]["title"]);
matchLeftContextElement = document.createElement("td");
}
matchLeftContextElement.classList.add("left-context");
htmlString += [...textTitles].join(",");
htmlString += `</td>`;
htmlString += `<td class="left-context">`;
for (cpos of match["lc"]) {
for (cpos of match["lc"]) {
token = result["cpos_lookup"][cpos];
token = result["cpos_lookup"][cpos];
htmlString += " ";
tokenElement = document.createElement("span");
htmlString += `<span class="token" data-cpos="${cpos}">${token["word"]}</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);
}
}
htmlString += `</td>`;
matchElement.append(matchLeftContextElement);
htmlString += `<td class="hit">`;
matchHitElement = document.createElement("td");
matchHitElement.classList.add("hit");
textTitles = new Set();
for (cpos of match["hit"]) {
for (cpos of match["hit"]) {
token = result["cpos_lookup"][cpos];
token = result["cpos_lookup"][cpos];
htmlString += " ";
tokenElement = document.createElement("span");
htmlString += `<span class="token" data-cpos="${cpos}">${token["word"]}</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 += `</td>`;
matchTextTitlesElement.innerText = [...textTitles].join(",");
htmlString += `<td class="right-context">`;
matchElement.append(matchHitElement);
matchRightContextElement = document.createElement("td");
matchRightContextElement.classList.add("right-context");
for (cpos of match["rc"]) {
for (cpos of match["rc"]) {
token = result["cpos_lookup"][cpos];
token = result["cpos_lookup"][cpos];
htmlString += " ";
tokenElement = document.createElement("span");
htmlString += `<span class="token" data-cpos="${cpos}">${token["word"]}</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 += `</td>`
;
matchElement.append(matchRightContextElement)
;
htmlString += `</tr>`
;
queryResultsElement.append(matchElement)
;
}
}
queryResultsElement.innerHTML = htmlString;
tokenElements = queryResultsElement.querySelectorAll(".token");
tokenElements.forEach(function(tokenElement) {
tokenElement.addEventListener("click", function(event) {
if (!expertModeSwitchElement.checked) {return;}
var token = result["cpos_lookup"][tokenElement.dataset.cpos];
var text = result["text_loopup"][token["text_id"]];
alert(`${token["word"]} // ${token["pos"]} // ${token["simple_pos"]} // ${text["title"]}`);
});
});
});
});
function addToolTipToTokenElement(tokenElement, token) {
M.Tooltip.init(tokenElement,
{"html": `<p>Token information</p>
<p class="left-align">
word: ${token["word"]}<br>
lemma: ${token["lemma"]}<br>
pos: ${token["pos"]}<br>
simple_pos: ${token["simple_pos"]}<br>
text: ${result["text_loopup"][token["text_id"]]["title"]}
</p>`,
"position": "top"});
}
</script>
</script>
{% endblock %}
{% endblock %}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment