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):
|
def corpus_analysis_query(query):
|
||||||
client = corpus_analysis_clients.get(request.sid)
|
client = corpus_analysis_clients.get(request.sid)
|
||||||
if client is None:
|
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'}
|
'msg': 'Failed Dependency'}
|
||||||
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||||
return
|
return
|
||||||
@ -44,31 +44,18 @@ def corpus_analysis_query(query):
|
|||||||
socketio.sleep(0.1)
|
socketio.sleep(0.1)
|
||||||
try:
|
try:
|
||||||
corpus = client.corpora.get('CORPUS')
|
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)
|
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')
|
results = corpus.subcorpora.get('Results')
|
||||||
except cqi.errors.CQiException as e:
|
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',
|
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
||||||
'payload': {'code': e.code, 'desc': e.description,
|
'payload': payload}
|
||||||
'msg': e.name}}
|
|
||||||
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||||
return
|
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)
|
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||||
|
# TODO: Stop here and add a new method for transmission
|
||||||
chunk_size = 100
|
chunk_size = 100
|
||||||
chunk_start = 0
|
chunk_start = 0
|
||||||
context = 100
|
context = 100
|
||||||
@ -99,17 +86,22 @@ def corpus_analysis_inspect_match(payload):
|
|||||||
payload = payload["payload"]
|
payload = payload["payload"]
|
||||||
client = corpus_analysis_clients.get(request.sid)
|
client = corpus_analysis_clients.get(request.sid)
|
||||||
if client is None:
|
if client is None:
|
||||||
socketio.emit('query', '[424]: Failed Dependency',
|
response = {'code': 424, 'desc': 'No client found for this session',
|
||||||
room=request.sid)
|
'msg': 'Failed Dependency'}
|
||||||
|
socketio.emit('corpus_analysis_inspect_match', response, room=request.sid)
|
||||||
return
|
return
|
||||||
# Get more context for given match CPOS
|
try:
|
||||||
corpus = client.corpora.get('CORPUS')
|
corpus = client.corpora.get('CORPUS')
|
||||||
s = corpus.structural_attributes.get('s')
|
s = corpus.structural_attributes.get('s')
|
||||||
match_context = s.export(payload['first_cpos'], payload['last_cpos'],
|
payload = s.export(payload['first_cpos'], payload['last_cpos'], context=3)
|
||||||
context=3, expand_lists=False)
|
payload['cpos_ranges'] = True
|
||||||
match_context['cpos_ranges'] = True
|
except cqi.errors.CQiException as e:
|
||||||
socketio.emit('corpus_analysis_match_context', {'payload': match_context},
|
payload = {'code': e.code, 'desc': e.description, 'msg': e.name}
|
||||||
room=request.sid)
|
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):
|
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'}
|
response = {'code': 403, 'desc': None, 'msg': 'Forbidden'}
|
||||||
socketio.emit('corpus_analysis_init', response, room=session_id)
|
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||||
return
|
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':
|
while corpus.status != 'analysing':
|
||||||
db.session.refresh(corpus)
|
db.session.refresh(corpus)
|
||||||
socketio.sleep(3)
|
socketio.sleep(3)
|
||||||
client = cqi.CQiClient('corpus_{}_analysis'.format(corpus_id))
|
client = cqi.CQiClient('corpus_{}_analysis'.format(corpus_id))
|
||||||
try:
|
try:
|
||||||
connect_status = client.connect()
|
payload = client.connect()
|
||||||
except cqi.errors.CQiException as e:
|
except cqi.errors.CQiException as e:
|
||||||
|
payload = {'code': e.code, 'desc': e.description, 'msg': e.name}
|
||||||
response = {'code': 500, 'desc': None,
|
response = {'code': 500, 'desc': None,
|
||||||
'msg': 'Internal Server Error',
|
'msg': 'Internal Server Error', 'payload': payload}
|
||||||
'payload': {'code': e.code, 'desc': e.description,
|
|
||||||
'msg': e.name}}
|
|
||||||
socketio.emit('corpus_analysis_init', response, room=session_id)
|
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||||
return
|
return
|
||||||
except gaierror:
|
except gaierror:
|
||||||
@ -149,8 +145,7 @@ def corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
|||||||
else:
|
else:
|
||||||
corpus_analysis_sessions[corpus_id].append(session_id)
|
corpus_analysis_sessions[corpus_id].append(session_id)
|
||||||
client.status = 'ready'
|
client.status = 'ready'
|
||||||
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': payload}
|
||||||
'payload': {**connect_status}}
|
|
||||||
socketio.emit('corpus_analysis_init', response, room=session_id)
|
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||||
''' Observe analysis session '''
|
''' Observe analysis session '''
|
||||||
while session_id in connected_sessions:
|
while session_id in connected_sessions:
|
||||||
|
@ -60,7 +60,7 @@ class CorpusAnalysisClient {
|
|||||||
|
|
||||||
// TODO: set callback for this
|
// TODO: set callback for this
|
||||||
// get context of one match if inspected via socket.io
|
// 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() {
|
init() {
|
||||||
|
@ -163,7 +163,7 @@
|
|||||||
let analyzeElement, buildElement, progressIndicatorElement, statusElement;
|
let analyzeElement, buildElement, progressIndicatorElement, statusElement;
|
||||||
|
|
||||||
progressIndicatorElement = document.getElementById("progress-indicator");
|
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");
|
progressIndicatorElement.classList.remove("hide");
|
||||||
} else {
|
} else {
|
||||||
progressIndicatorElement.classList.add("hide");
|
progressIndicatorElement.classList.add("hide");
|
||||||
|
Loading…
Reference in New Issue
Block a user