From 94e8d0895c738f510a00c94c6d8976cc5f424f75 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Mon, 2 Dec 2019 16:13:53 +0100 Subject: [PATCH] Add first things to get more context for one match. --- app/corpora/CQiWrapper/CQiWrapper.py | 5 ++- app/corpora/events.py | 17 +++++++++- app/templates/corpora/analyse_corpus.html.j2 | 34 ++++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/corpora/CQiWrapper/CQiWrapper.py b/app/corpora/CQiWrapper/CQiWrapper.py index c19cf84f..dc4ce1e2 100644 --- a/app/corpora/CQiWrapper/CQiWrapper.py +++ b/app/corpora/CQiWrapper/CQiWrapper.py @@ -294,4 +294,7 @@ class CQiWrapper(CQiClient): t1 = time.time() t_total = t1 - t0 logger.warning('Got all sentences informations in {} seconds'. format(t_total)) - return context_sentences, all_cpos_infos, text_lookup + match_context = {'context_s_cpos': context_sentences, + 'cpos_lookup': all_cpos_infos, + 'text_lookup': text_lookup} + return match_context diff --git a/app/corpora/events.py b/app/corpora/events.py index 954e1594..53323506 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -42,7 +42,7 @@ def corpus_analysis(message): socketio.emit('query', '[424]: Failed Dependency', room=request.sid) return - """ Prepare and execute a query """ + # Prepare and execute a query corpus_name = 'CORPUS' query = str(message['query']) result_len = int(message['hits_per_page']) @@ -57,6 +57,21 @@ def corpus_analysis(message): socketio.emit('corpus_analysis', results, room=request.sid) +@socketio.on('inspect_match') +@login_required +def inspect_match(message): + client = corpus_analysis_clients.get(request.sid) + if client is None: + socketio.emit('query', '[424]: Failed Dependency', + room=request.sid) + return + # Get more context for given match CPOS + match_context = client.get_sentences(message['cpos'], + get_surrounding_s=True, + l_r_s_context_additional_len=3) + socketio.emit('match_context', match_context, room=request.sid) + + def corpus_analysis_session_handler(app, corpus_id, session_id): with app.app_context(): ''' Setup analysis session ''' diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 index a488c1e6..ccba4afc 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -137,6 +137,16 @@ + + {% endblock %}