diff --git a/app/corpora/CQiWrapper/CQiWrapper.py b/app/corpora/CQiWrapper/CQiWrapper.py index b1ca3f6f..133157a0 100644 --- a/app/corpora/CQiWrapper/CQiWrapper.py +++ b/app/corpora/CQiWrapper/CQiWrapper.py @@ -51,7 +51,7 @@ class CQiWrapper(CQiClient): self.attr_strings['positional_attrs'][p_attr] = (self.corpus_name + '.' + p_attr) - for struct_attr in struct_attrs[:-1]: + for struct_attr in struct_attrs[2:-1]: self.attr_strings['struct_attrs'][struct_attr] = (self.corpus_name + '.' + struct_attr) @@ -64,7 +64,6 @@ class CQiWrapper(CQiClient): self.__create_attribute_strings() logger.warning('{} does exist.'.format(corpus_name)) else: - self.disconnect() logger.warning('{} does not exist.'.format(corpus_name)) def disconnect(self): @@ -126,7 +125,6 @@ class CQiWrapper(CQiClient): self.nr_matches = min(result_len, self.nr_matches) if self.nr_matches == 0: logger.warning('Query resulted in 0 matches.') - self.disconnect return None else: # Get match cpos boundries @@ -227,11 +225,14 @@ class CQiWrapper(CQiClient): all_cpos) cpos_infos[p_attr_key] = match_str elif attr_dict == 'struct_attrs': - for struct_attr_key in self.attr_strings[attr_dict].keys(): - struct_entry = self.cl_cpos2struc(self.attr_strings['struct_attrs'][self.meta_struct_element], - all_cpos) - match_str = self.cl_struc2str(self.attr_strings[attr_dict][struct_attr_key], struct_entry) - cpos_infos[struct_attr_key] = match_str + # for struct_attr_key in self.attr_strings[attr_dict].keys(): + # logger.warning('HIER:' + struct_attr_key + " " + " " + self.attr_strings[attr_dict][struct_attr_key]) + # struct_entry = self.cl_cpos2struc(self.attr_strings['struct_attrs'][self.meta_struct_element], + # all_cpos) + # logger.warning(struct_entry) + # match_str = self.cl_struc2str(self.attr_strings[attr_dict][struct_attr_key], struct_entry) + # cpos_infos[struct_attr_key] = match_str + pass tmp_list = [] attr_key_list = [] for key in cpos_infos.keys(): diff --git a/app/corpora/events.py b/app/corpora/events.py index 6edd7a2f..ff7a6f89 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -37,10 +37,10 @@ def init_corpus_analysis(corpus_id): while corpus.status != 'analysing': db.session.refresh(corpus) socketio.sleep(3) - analysis_clients[request.sid] = CQiClient( + analysis_clients[request.sid] = CQiWrapper( host='{}_analysis_container{}'.format(corpus.creator.username, corpus.id)) - analysis_clients[request.sid].ctrl_connect('opaque', 'opaque') + analysis_clients[request.sid].connect() socketio.emit('init_corpus_analysis', 'Ready', room=request.sid) socketio.start_background_task(observe_corpus_analysis_connection, current_app._get_current_object(), @@ -58,41 +58,10 @@ def recv_query(message): """ Prepare and execute a query """ corpus_name = 'CORPUS' query = message['query'] - query_subcorpus = 'Results' - analysis_client.cqp_query(corpus, query_subcorpus, query) - """ Evaluate query results """ - match_corpus = '{}:{}'.format(corpus, query_subcorpus) - match_num = min(int(message['hits_per_page']) - 1, - analysis_client.cqp_subcorpus_size(match_corpus)) - if match_num == 0: - print('No matches found.') - exit() - if not analysis_client.cqp_subcorpus_has_field(match_corpus, CONST_FIELD_MATCH): - print('Error.') - exit() - 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: - matches.append({'cpos_list': list(range(match_start, match_end + 1))}) - cpos_list = [] - 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) - socketio.emit('query', matches, room=request.sid) + analysis_client.select_corpus(corpus_name) + analysis_client.query_subcorpus(query) + results = analysis_client.show_query_results(result_len=2) + socketio.emit('query', results, room=request.sid) def observe_corpus_analysis_connection(app, corpus_id, session_id): @@ -101,7 +70,7 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id): socketio.sleep(3) analysis_client = analysis_clients.pop(session_id, None) if analysis_client is not None: - analysis_client.ctrl_bye() + analysis_client.disconnect() analysis_sessions[corpus_id].remove(session_id) if not analysis_sessions[corpus_id]: analysis_sessions.pop(corpus_id, None) diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 index 71760f32..64794325 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -117,8 +117,9 @@ }); socket.on('query', function(results) { queryResultsElement.innerHTML = ''; - for (let result of results) { - queryResultsElement.innerHTML += '
' + result['word_list'] + '
'; + for (let key in results) { + console.log(results[key]); + queryResultsElement.innerHTML += '' + results[key]['match_cpos_list'] + '
'; } }); diff --git a/app/templates/corpora/corpus_analysis.html.j2 b/app/templates/corpora/corpus_analysis.html.j2 deleted file mode 100644 index 5cf903b2..00000000 --- a/app/templates/corpora/corpus_analysis.html.j2 +++ /dev/null @@ -1,143 +0,0 @@ -{% extends "full_width.html.j2" %} - -{% block page_content %} - - -