mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-04-05 08:44:22 +00:00
Code update to new request system
This commit is contained in:
parent
baf06d3106
commit
7dd55c47a0
@ -29,8 +29,10 @@ def init_corpus_analysis(corpus_id):
|
|||||||
if not (corpus.creator == current_user or current_user.is_administrator()):
|
if not (corpus.creator == current_user or current_user.is_administrator()):
|
||||||
socketio.emit('init_corpus_analysis', '[ERROR 403]: Forbidden',
|
socketio.emit('init_corpus_analysis', '[ERROR 403]: Forbidden',
|
||||||
room=request.sid)
|
room=request.sid)
|
||||||
if str(corpus_id) not in analysis_sessions:
|
if corpus_id not in analysis_sessions:
|
||||||
analysis_sessions[str(corpus_id)] = [request.sid]
|
analysis_sessions[corpus_id] = [request.sid]
|
||||||
|
else:
|
||||||
|
analysis_sessions[corpus_id].append(request.sid)
|
||||||
socketio.start_background_task(observe_corpus_analysis_connection,
|
socketio.start_background_task(observe_corpus_analysis_connection,
|
||||||
current_app._get_current_object(),
|
current_app._get_current_object(),
|
||||||
corpus_id, request.sid)
|
corpus_id, request.sid)
|
||||||
@ -48,8 +50,8 @@ def recv_query(message):
|
|||||||
analysis_client.cqp_query(corpus, query_subcorpus, query)
|
analysis_client.cqp_query(corpus, query_subcorpus, query)
|
||||||
""" Evaluate query results """
|
""" Evaluate query results """
|
||||||
match_corpus = '{}:{}'.format(corpus, query_subcorpus)
|
match_corpus = '{}:{}'.format(corpus, query_subcorpus)
|
||||||
match_num = analysis_client.cqp_subcorpus_size(match_corpus)
|
match_num = min(int(message['hits_per_page']) - 1,
|
||||||
match_num = min(int(message['hits_per_page']) - 1, match_num)
|
analysis_client.cqp_subcorpus_size(match_corpus))
|
||||||
if match_num == 0:
|
if match_num == 0:
|
||||||
print('No matches found.')
|
print('No matches found.')
|
||||||
exit()
|
exit()
|
||||||
@ -63,9 +65,20 @@ def recv_query(message):
|
|||||||
analysis_client.cqp_dump_subcorpus(match_corpus, CONST_FIELD_MATCHEND, 0, match_num - 1))
|
analysis_client.cqp_dump_subcorpus(match_corpus, CONST_FIELD_MATCHEND, 0, match_num - 1))
|
||||||
matches = []
|
matches = []
|
||||||
for match_start, match_end in match_boundaries:
|
for match_start, match_end in match_boundaries:
|
||||||
tokens = analysis_client.cl_cpos2str('{}.word'.format(corpus), range(match_start, match_end + 1))
|
matches.append({'cpos_list': list(range(match_start, match_end + 1))})
|
||||||
pos = analysis_client.cl_cpos2str('{}.pos'.format(corpus), range(match_start, match_end + 1))
|
cpos_list = []
|
||||||
matches.append({'tokens': tokens, 'pos': pos})
|
for match in matches:
|
||||||
|
cpos_list = cpos_list + match['cpos_list']
|
||||||
|
cpos_list = list(set(cpos_list))
|
||||||
|
pos_list = analysis_client.cl_cpos2str('{}.pos'.format(corpus), cpos_list)
|
||||||
|
word_list = analysis_client.cl_cpos2str('{}.word'.format(corpus), cpos_list)
|
||||||
|
foo = {}
|
||||||
|
for cpos, pos, word in zip(cpos_list, pos_list, word_list):
|
||||||
|
foo[cpos] = {'pos': pos, 'word': word}
|
||||||
|
for match in matches:
|
||||||
|
match['pos_list'] = [foo[cpos]['pos'] for cpos in match['cpos_list']]
|
||||||
|
match['word_list'] = [foo[cpos]['word'] for cpos in match['cpos_list']]
|
||||||
|
match.pop('cpos_list', None)
|
||||||
logger.warning(matches)
|
logger.warning(matches)
|
||||||
socketio.emit('query_results', matches, room=request.sid)
|
socketio.emit('query_results', matches, room=request.sid)
|
||||||
|
|
||||||
@ -81,20 +94,11 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
|||||||
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:
|
||||||
'''
|
|
||||||
try:
|
|
||||||
analysis_client.ctrl_ping()
|
|
||||||
except Exception as err:
|
|
||||||
logger.warning('[Exception]: {}'.format(err))
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
socketio.sleep(3)
|
|
||||||
'''
|
|
||||||
socketio.sleep(3)
|
socketio.sleep(3)
|
||||||
analysis_client.ctrl_bye()
|
analysis_client.ctrl_bye()
|
||||||
analysis_clients.pop(session_id, None)
|
analysis_clients.pop(session_id, None)
|
||||||
analysis_sessions[str(corpus_id)].remove(session_id)
|
analysis_sessions[corpus_id].remove(session_id)
|
||||||
if not analysis_sessions[str(corpus_id)]:
|
if not analysis_sessions[corpus_id]:
|
||||||
analysis_sessions.pop(str(corpus_id), None)
|
analysis_sessions.pop(corpus_id, None)
|
||||||
corpus.status = 'stop analysis'
|
corpus.status = 'stop analysis'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -78,7 +78,7 @@ socket.on('query_results', function(json_results) {
|
|||||||
console.log(json_results)
|
console.log(json_results)
|
||||||
var queryResultsElement = document.getElementById("query-results");
|
var queryResultsElement = document.getElementById("query-results");
|
||||||
for (let json_result of json_results) {
|
for (let json_result of json_results) {
|
||||||
queryResultsElement.innerHTML += json_result['tokens'] + '<br>';
|
queryResultsElement.innerHTML += json_result['word_list'] + '<br>';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user