diff --git a/app/corpora/cqi/api/client.py b/app/corpora/cqi/api/client.py index d0f328c9..cbf28f14 100644 --- a/app/corpora/cqi/api/client.py +++ b/app/corpora/cqi/api/client.py @@ -1,5 +1,5 @@ from time import sleep -from .. import specification +from . import specification from ..errors import cl_error_lookup, error_lookup, cqp_error_lookup import socket import struct diff --git a/app/corpora/cqi/specification.py b/app/corpora/cqi/api/specification.py similarity index 100% rename from app/corpora/cqi/specification.py rename to app/corpora/cqi/api/specification.py diff --git a/app/corpora/cqi/errors.py b/app/corpora/cqi/errors.py index fa0d33a0..f2a8c9aa 100644 --- a/app/corpora/cqi/errors.py +++ b/app/corpora/cqi/errors.py @@ -1,4 +1,4 @@ -from . import specification +from .api import specification class CQiException(Exception): diff --git a/app/corpora/cqi/models/corpora.py b/app/corpora/cqi/models/corpora.py index 0e8b8bed..e81056ab 100644 --- a/app/corpora/cqi/models/corpora.py +++ b/app/corpora/cqi/models/corpora.py @@ -64,5 +64,4 @@ class Corpus: return lookups def query(self, query, subcorpus_name='Results'): - self.client.api.cqp_query(self.name, subcorpus_name, query) - return self.subcorpora.get('Results') + return self.client.api.cqp_query(self.name, subcorpus_name, query) diff --git a/app/corpora/cqi/models/subcorpora.py b/app/corpora/cqi/models/subcorpora.py index d7698eba..0e774db0 100644 --- a/app/corpora/cqi/models/subcorpora.py +++ b/app/corpora/cqi/models/subcorpora.py @@ -1,5 +1,5 @@ -from ..specification import (CONST_FIELD_KEYWORD, CONST_FIELD_MATCH, - CONST_FIELD_MATCHEND, CONST_FIELD_TARGET) +from ..api.specification import (CONST_FIELD_KEYWORD, CONST_FIELD_MATCH, + CONST_FIELD_MATCHEND, CONST_FIELD_TARGET) class SubcorpusCollection: diff --git a/app/corpora/cqi/version.py b/app/corpora/cqi/version.py index b00e2679..e9c2235f 100644 --- a/app/corpora/cqi/version.py +++ b/app/corpora/cqi/version.py @@ -1,4 +1,4 @@ -from .specification import MAJOR_VERSION, MINOR_VERSION +from .api.specification import MAJOR_VERSION, MINOR_VERSION version = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION) diff --git a/app/corpora/cqi/wrapper.py b/app/corpora/cqi/wrapper.py index daba87c8..f6c58395 100644 --- a/app/corpora/cqi/wrapper.py +++ b/app/corpora/cqi/wrapper.py @@ -1,5 +1,5 @@ from .api import APIClient -from .specification import CONST_FIELD_MATCH, CONST_FIELD_MATCHEND +from .api.specification import CONST_FIELD_MATCH, CONST_FIELD_MATCHEND import time diff --git a/app/corpora/events.py b/app/corpora/events.py index bc0ebc40..4032ded5 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -52,7 +52,7 @@ def corpus_analysis_query(query): return corpus = client.corpora.get('CORPUS') try: - results = corpus.query(query) + corpus.query(query) except Exception as e: logger.warning(e) response = str(e) @@ -60,6 +60,7 @@ def corpus_analysis_query(query): response = {'code': 1} socketio.emit('corpus_analysis_query', response, room=request.sid) else: + results = corpus.subcorpora.get('Results') chunk_size = 100 chunk_start = 0 context = 100 diff --git a/app/corpora/pj_events.py b/app/corpora/pj_events.py index 836b4d36..ab2bc94c 100644 --- a/app/corpora/pj_events.py +++ b/app/corpora/pj_events.py @@ -47,7 +47,15 @@ def pj_corpus_analysis_query(query): socketio.emit('pj_corpus_analysis_query', response, room=request.sid) return try: - results = 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('pj_corpus_analysis_query', response, room=request.sid) + return + try: + results = corpus.subcorpora.get('Results') except cqi.errors.CQiException as e: response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error', 'payload': {'code': e.code, 'desc': e.description, @@ -55,7 +63,7 @@ def pj_corpus_analysis_query(query): socketio.emit('pj_corpus_analysis_query', response, room=request.sid) return response = {'code': 200, 'desc': None, 'msg': 'OK', - 'payload': {'num_matches': results.size}} + 'payload': {**query_status, 'num_matches': results.size}} socketio.emit('pj_corpus_analysis_query', response, room=request.sid) chunk_size = 100 chunk_start = 0