mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Temp event query handling
This commit is contained in:
parent
5fdd67ebf2
commit
ae6e252830
@ -3,8 +3,7 @@ from app.events import connected_sessions
|
|||||||
from app.models import Corpus
|
from app.models import Corpus
|
||||||
from flask import current_app, request
|
from flask import current_app, request
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from .CQiWrapper.CQiClient import CQiClient
|
from .CQiWrapper.CQiWrapper import CQiWrapper
|
||||||
from .CQiWrapper.CQi import CONST_FIELD_MATCH, CONST_FIELD_MATCHEND
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -41,32 +40,22 @@ def init_corpus_analysis(corpus_id):
|
|||||||
def recv_query(message):
|
def recv_query(message):
|
||||||
logger.warning(message)
|
logger.warning(message)
|
||||||
analysis_client = analysis_clients[request.sid]
|
analysis_client = analysis_clients[request.sid]
|
||||||
|
analysis_client.connect()
|
||||||
""" Prepare and execute a query """
|
""" Prepare and execute a query """
|
||||||
corpus = 'CORPUS'
|
corpus_name = 'CORPUS'
|
||||||
query = message['query']
|
query = message['query']
|
||||||
query_subcorpus = 'Results'
|
result_subcorpus_name = 'Results'
|
||||||
analysis_client.cqp_query(corpus, query_subcorpus, query)
|
analysis_client.set_corpus_name(corpus_name)
|
||||||
""" Evaluate query results """
|
logger.warning('Corpus name has been set.')
|
||||||
match_corpus = '{}:{}'.format(corpus, query_subcorpus)
|
analysis_client.create_attribute_strings()
|
||||||
match_num = analysis_client.cqp_subcorpus_size(match_corpus)
|
logger.warning('Attribute Strings have been created.')
|
||||||
match_num = min(int(message['hits_per_page']) - 1, match_num)
|
analysis_client.query_subcorpus(result_subcorpus_name, query)
|
||||||
if match_num == 0:
|
logger.warning('Subcorpus from query has been created.')
|
||||||
print('No matches found.')
|
subcorpora = analysis_client.show_subcorpora()
|
||||||
exit()
|
logger.warning('Known subcorpora: {}'.format(subcorpora))
|
||||||
if not analysis_client.cqp_subcorpus_has_field(match_corpus, CONST_FIELD_MATCH):
|
matches = analysis_client.show_results(result_start_count=1,
|
||||||
print('Error.')
|
result_max_count=3)
|
||||||
exit()
|
logger.warning('Match data: {}'.format(matches))
|
||||||
if not analysis_client.cqp_subcorpus_has_field(match_corpus, CONST_FIELD_MATCHEND):
|
|
||||||
print('Error')
|
|
||||||
exit()
|
|
||||||
match_boundaries = zip(analysis_client.cqp_dump_subcorpus(match_corpus, CONST_FIELD_MATCH, 0, match_num - 1),
|
|
||||||
analysis_client.cqp_dump_subcorpus(match_corpus, CONST_FIELD_MATCHEND, 0, match_num - 1))
|
|
||||||
matches = []
|
|
||||||
for match_start, match_end in match_boundaries:
|
|
||||||
tokens = analysis_client.cl_cpos2str('{}.word'.format(corpus), range(match_start, match_end + 1))
|
|
||||||
pos = analysis_client.cl_cpos2str('{}.pos'.format(corpus), range(match_start, match_end + 1))
|
|
||||||
matches.append({'tokens': tokens, 'pos': pos})
|
|
||||||
logger.warning(matches)
|
|
||||||
socketio.emit('query_results', matches, room=request.sid)
|
socketio.emit('query_results', matches, room=request.sid)
|
||||||
|
|
||||||
|
|
||||||
@ -76,8 +65,7 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
|||||||
while corpus.status != 'analysing':
|
while corpus.status != 'analysing':
|
||||||
db.session.refresh(corpus)
|
db.session.refresh(corpus)
|
||||||
socketio.sleep(3)
|
socketio.sleep(3)
|
||||||
analysis_client = CQiClient(host='{}_analysis_container{}'.format(corpus.creator.username, corpus.id), port=4877)
|
analysis_client = CQiWrapper(host='{}_analysis_container{}'.format(corpus.creator.username, corpus.id), port=4877, password='opaque', username='opaque')
|
||||||
analysis_client.ctrl_connect('opaque', 'opaque')
|
|
||||||
analysis_clients[session_id] = analysis_client
|
analysis_clients[session_id] = analysis_client
|
||||||
socketio.emit('init_corpus_analysis', 'Ready', room=session_id)
|
socketio.emit('init_corpus_analysis', 'Ready', room=session_id)
|
||||||
while session_id in connected_sessions:
|
while session_id in connected_sessions:
|
||||||
@ -91,7 +79,7 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
|||||||
socketio.sleep(3)
|
socketio.sleep(3)
|
||||||
'''
|
'''
|
||||||
socketio.sleep(3)
|
socketio.sleep(3)
|
||||||
analysis_client.ctrl_bye()
|
analysis_client.disconnect()
|
||||||
analysis_clients.pop(session_id, None)
|
analysis_clients.pop(session_id, None)
|
||||||
analysis_sessions[str(corpus_id)].remove(session_id)
|
analysis_sessions[str(corpus_id)].remove(session_id)
|
||||||
if not analysis_sessions[str(corpus_id)]:
|
if not analysis_sessions[str(corpus_id)]:
|
||||||
|
Loading…
Reference in New Issue
Block a user