This commit is contained in:
Patrick Jentsch 2020-03-29 20:54:51 +02:00
parent 4ff372de77
commit 6e3579b33f
9 changed files with 19 additions and 11 deletions

View File

@ -1,5 +1,5 @@
from time import sleep from time import sleep
from .. import specification from . import specification
from ..errors import cl_error_lookup, error_lookup, cqp_error_lookup from ..errors import cl_error_lookup, error_lookup, cqp_error_lookup
import socket import socket
import struct import struct

View File

@ -1,4 +1,4 @@
from . import specification from .api import specification
class CQiException(Exception): class CQiException(Exception):

View File

@ -64,5 +64,4 @@ class Corpus:
return lookups return lookups
def query(self, query, subcorpus_name='Results'): def query(self, query, subcorpus_name='Results'):
self.client.api.cqp_query(self.name, subcorpus_name, query) return self.client.api.cqp_query(self.name, subcorpus_name, query)
return self.subcorpora.get('Results')

View File

@ -1,5 +1,5 @@
from ..specification import (CONST_FIELD_KEYWORD, CONST_FIELD_MATCH, from ..api.specification import (CONST_FIELD_KEYWORD, CONST_FIELD_MATCH,
CONST_FIELD_MATCHEND, CONST_FIELD_TARGET) CONST_FIELD_MATCHEND, CONST_FIELD_TARGET)
class SubcorpusCollection: class SubcorpusCollection:

View File

@ -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) version = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)

View File

@ -1,5 +1,5 @@
from .api import APIClient 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 import time

View File

@ -52,7 +52,7 @@ def corpus_analysis_query(query):
return return
corpus = client.corpora.get('CORPUS') corpus = client.corpora.get('CORPUS')
try: try:
results = corpus.query(query) corpus.query(query)
except Exception as e: except Exception as e:
logger.warning(e) logger.warning(e)
response = str(e) response = str(e)
@ -60,6 +60,7 @@ def corpus_analysis_query(query):
response = {'code': 1} response = {'code': 1}
socketio.emit('corpus_analysis_query', response, room=request.sid) socketio.emit('corpus_analysis_query', response, room=request.sid)
else: else:
results = corpus.subcorpora.get('Results')
chunk_size = 100 chunk_size = 100
chunk_start = 0 chunk_start = 0
context = 100 context = 100

View File

@ -47,7 +47,15 @@ def pj_corpus_analysis_query(query):
socketio.emit('pj_corpus_analysis_query', response, room=request.sid) socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
return return
try: 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: except cqi.errors.CQiException as e:
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': {'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) socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
return return
response = {'code': 200, 'desc': None, 'msg': 'OK', 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) socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
chunk_size = 100 chunk_size = 100
chunk_start = 0 chunk_start = 0