mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
corpus logic
This commit is contained in:
parent
860e99dfcb
commit
9a1efbe5f3
@ -34,7 +34,7 @@ def init_corpus_analysis(corpus_id):
|
||||
def corpus_analysis_query(query):
|
||||
client = corpus_analysis_clients.get(request.sid)
|
||||
if client is None:
|
||||
response = {'code': 404, 'desc': 'No client found for this session',
|
||||
response = {'code': 424, 'desc': 'No client found for this session',
|
||||
'msg': 'Failed Dependency'}
|
||||
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||
return
|
||||
@ -44,31 +44,18 @@ def corpus_analysis_query(query):
|
||||
socketio.sleep(0.1)
|
||||
try:
|
||||
corpus = client.corpora.get('CORPUS')
|
||||
except cqi.errors.CQiException as e:
|
||||
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
||||
'payload': {'code': e.code, 'desc': e.description,
|
||||
'msg': e.name}}
|
||||
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||
return
|
||||
try:
|
||||
query_status = corpus.query(query)
|
||||
except cqi.errors.CQiException as e:
|
||||
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
||||
'payload': {'code': e.code, 'desc': e.description,
|
||||
'msg': e.name}}
|
||||
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||
return
|
||||
try:
|
||||
results = corpus.subcorpora.get('Results')
|
||||
except cqi.errors.CQiException as e:
|
||||
payload = {'code': e.code, 'desc': e.description, 'msg': e.name}
|
||||
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
||||
'payload': {'code': e.code, 'desc': e.description,
|
||||
'msg': e.name}}
|
||||
'payload': payload}
|
||||
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||
return
|
||||
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
||||
'payload': {**query_status, 'match_count': results.attrs['size']}}
|
||||
payload = {**query_status, 'match_count': results.attrs['size']}
|
||||
response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': payload}
|
||||
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||
# TODO: Stop here and add a new method for transmission
|
||||
chunk_size = 100
|
||||
chunk_start = 0
|
||||
context = 100
|
||||
@ -99,17 +86,22 @@ def corpus_analysis_inspect_match(payload):
|
||||
payload = payload["payload"]
|
||||
client = corpus_analysis_clients.get(request.sid)
|
||||
if client is None:
|
||||
socketio.emit('query', '[424]: Failed Dependency',
|
||||
room=request.sid)
|
||||
response = {'code': 424, 'desc': 'No client found for this session',
|
||||
'msg': 'Failed Dependency'}
|
||||
socketio.emit('corpus_analysis_inspect_match', response, room=request.sid)
|
||||
return
|
||||
# Get more context for given match CPOS
|
||||
try:
|
||||
corpus = client.corpora.get('CORPUS')
|
||||
s = corpus.structural_attributes.get('s')
|
||||
match_context = s.export(payload['first_cpos'], payload['last_cpos'],
|
||||
context=3, expand_lists=False)
|
||||
match_context['cpos_ranges'] = True
|
||||
socketio.emit('corpus_analysis_match_context', {'payload': match_context},
|
||||
room=request.sid)
|
||||
payload = s.export(payload['first_cpos'], payload['last_cpos'], context=3)
|
||||
payload['cpos_ranges'] = True
|
||||
except cqi.errors.CQiException as e:
|
||||
payload = {'code': e.code, 'desc': e.description, 'msg': e.name}
|
||||
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
||||
'payload': payload}
|
||||
else:
|
||||
response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': payload}
|
||||
socketio.emit('corpus_analysis_inspect_match', response, room=request.sid)
|
||||
|
||||
|
||||
def corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
||||
@ -125,17 +117,21 @@ def corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
||||
response = {'code': 403, 'desc': None, 'msg': 'Forbidden'}
|
||||
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||
return
|
||||
elif corpus.status == 'unprepared':
|
||||
response = {'code': 424, 'desc': 'Corpus is not prepared',
|
||||
'msg': 'Failed Dependency'}
|
||||
socketio.emit('corpus_analysis_init', response, room=request.sid)
|
||||
return
|
||||
while corpus.status != 'analysing':
|
||||
db.session.refresh(corpus)
|
||||
socketio.sleep(3)
|
||||
client = cqi.CQiClient('corpus_{}_analysis'.format(corpus_id))
|
||||
try:
|
||||
connect_status = client.connect()
|
||||
payload = client.connect()
|
||||
except cqi.errors.CQiException as e:
|
||||
payload = {'code': e.code, 'desc': e.description, 'msg': e.name}
|
||||
response = {'code': 500, 'desc': None,
|
||||
'msg': 'Internal Server Error',
|
||||
'payload': {'code': e.code, 'desc': e.description,
|
||||
'msg': e.name}}
|
||||
'msg': 'Internal Server Error', 'payload': payload}
|
||||
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||
return
|
||||
except gaierror:
|
||||
@ -149,8 +145,7 @@ def corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
||||
else:
|
||||
corpus_analysis_sessions[corpus_id].append(session_id)
|
||||
client.status = 'ready'
|
||||
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
||||
'payload': {**connect_status}}
|
||||
response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': payload}
|
||||
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||
''' Observe analysis session '''
|
||||
while session_id in connected_sessions:
|
||||
|
@ -60,7 +60,7 @@ class CorpusAnalysisClient {
|
||||
|
||||
// TODO: set callback for this
|
||||
// get context of one match if inspected via socket.io
|
||||
socket.on("corpus_analysis_match_context", (response) => { results.resultsList.showMatchContext(response)});
|
||||
socket.on("corpus_analysis_inspect_match", (response) => { results.resultsList.showMatchContext(response)});
|
||||
}
|
||||
|
||||
init() {
|
||||
|
@ -163,7 +163,7 @@
|
||||
let analyzeElement, buildElement, progressIndicatorElement, statusElement;
|
||||
|
||||
progressIndicatorElement = document.getElementById("progress-indicator");
|
||||
if (["queued", "running", "start analysis"].includes(status)) {
|
||||
if (["queued", "running", "start analysis", "stop analysis"].includes(status)) {
|
||||
progressIndicatorElement.classList.remove("hide");
|
||||
} else {
|
||||
progressIndicatorElement.classList.add("hide");
|
||||
|
Loading…
Reference in New Issue
Block a user