Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development

This commit is contained in:
Stephan Porada 2019-11-27 09:41:22 +01:00
commit b5afdf74f2
3 changed files with 52 additions and 63 deletions

View File

@ -23,7 +23,7 @@ def create_app(config_name):
db.init_app(app) db.init_app(app)
login_manager.init_app(app) login_manager.init_app(app)
mail.init_app(app) mail.init_app(app)
socketio.init_app(app, message_qeue='redis://redis:6379') socketio.init_app(app, message_queue='redis://redis:6379')
from . import events from . import events

View File

@ -64,7 +64,19 @@
<div class="card"> <div class="card">
<div class="card-content"> <div class="card-content">
<span class="card-title">Query Results</span> <span class="card-title">Query Results</span>
<div id="query-results"></div> <div>
<table class="highlight">
<thead>
<tr>
<th>Title</th>
<th>Left context</th>
<th>Match</th>
<th>Right Context</th>
</tr>
</thead>
<tbody id="query-results"></tbody>
</table>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -91,80 +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(results) { socket.on('corpus_analysis', function(result) {
if (results === null) { console.log(result['matches']);
M.toast({html: 'Query has no results!'});
} else { var htmlString;
console.log(results); var token;
html_txt = '<table class="highlight"> <thead><tr><th>Title</th><th>Left context</th><th>Match</th><th>Right Context</th></tr></thead>';
for (let [key, hit] of Object.entries(results)) { for (let match of result['matches']) {
resultInfo(hit, "word"); htmlString = `<tr class="match">`;
var left_context = hit['left_context_cpos'] htmlString += `<td class="left-context">`;
var match = hit['match_cpos'] for (cpos of match['lc']) {
var right_context = hit['right_context_cpos'] token = result['cpos_lookup'][cpos];
var l_text = getResultInfos(left_context, 'word') htmlString += `<span data-cpos="${cpos}">${token['word']}</span>`;
var m_text = getResultInfos(match, 'word')
var r_text = getResultInfos(right_context, 'word')
var match_source = getResultInfos(match, 'text_title', 1)
html_txt += '<tr> <td>' + match_source + '</td><td>' + l_text + '</td><td>' + m_text + '</td><td>' + r_text + '</td></tr>';
l_text = '';
m_text = '';
} }
html_txt += '</table>'; htmlString += `</td>`;
queryResultsElement.innerHTML = html_txt; 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 resultInfo(result) {
left = "";
for (let entry of result['left_context_cpos']) {
let foo = Object.values(entry)[0]
left += foo["simple_pos"] === "PUNCT" ? foo["word"] : " " + foo["word"];
}
console.log("Diese andere Info:");
console.log(left);
}
function getResultInfos(matchObject, info_key, slice) {
var infos = [];
for (let token of Object.values(matchObject)) {
for (let key in token) {
infos.push(token[key][info_key]);
}
}
if (slice) {
console.log(infos);
var infos = infos[slice];
return infos;
} else {
return infos;
}
}
</script> </script>
{% endblock %} {% endblock %}

View File

@ -2,9 +2,6 @@ version: '3'
services: services:
web: web:
depends_on:
- db
- redis
deploy: deploy:
placement: placement:
constraints: constraints:
@ -17,9 +14,8 @@ services:
- 5000:5000 - 5000:5000
volumes: volumes:
- storage:/mnt/opaque - storage:/mnt/opaque
- ./logs:/home/opaque/logs
daemon: daemon:
depends_on:
- db
deploy: deploy:
placement: placement:
constraints: constraints:
@ -30,6 +26,7 @@ services:
image: gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/opaque_daemon:latest image: gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/opaque_daemon:latest
volumes: volumes:
- storage:/mnt/opaque - storage:/mnt/opaque
- ./logs:/home/opaque_daemon/logs
- $HOME/.docker/config.json:/home/opaque_daemon/.docker/config.json - $HOME/.docker/config.json:/home/opaque_daemon/.docker/config.json
db: db:
deploy: deploy: