2021-08-20 12:41:40 +00:00
|
|
|
from .. import db
|
2020-04-21 16:34:21 +00:00
|
|
|
from ..decorators import background
|
2020-10-08 10:48:29 +00:00
|
|
|
from ..models import Corpus, CorpusFile, QueryResult
|
2020-04-21 16:34:21 +00:00
|
|
|
|
|
|
|
|
2020-04-23 05:56:23 +00:00
|
|
|
@background
|
2020-04-23 06:35:18 +00:00
|
|
|
def build_corpus(corpus_id, *args, **kwargs):
|
|
|
|
app = kwargs['app']
|
2020-04-23 05:56:23 +00:00
|
|
|
with app.app_context():
|
|
|
|
corpus = Corpus.query.get(corpus_id)
|
|
|
|
if corpus is None:
|
2020-07-10 09:36:54 +00:00
|
|
|
raise Exception('Corpus {} not found'.format(corpus_id))
|
|
|
|
corpus.build()
|
2020-04-23 05:56:23 +00:00
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
2020-04-21 16:34:21 +00:00
|
|
|
@background
|
2020-04-23 06:35:18 +00:00
|
|
|
def delete_corpus(corpus_id, *args, **kwargs):
|
2020-07-10 09:36:54 +00:00
|
|
|
with kwargs['app'].app_context():
|
2020-04-21 16:34:21 +00:00
|
|
|
corpus = Corpus.query.get(corpus_id)
|
|
|
|
if corpus is None:
|
2020-07-10 09:36:54 +00:00
|
|
|
raise Exception('Corpus {} not found'.format(corpus_id))
|
2020-04-21 16:34:21 +00:00
|
|
|
corpus.delete()
|
2020-07-10 09:36:54 +00:00
|
|
|
db.session.commit()
|
2020-04-21 16:34:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@background
|
2020-04-23 06:35:18 +00:00
|
|
|
def delete_corpus_file(corpus_file_id, *args, **kwargs):
|
2020-07-10 09:36:54 +00:00
|
|
|
with kwargs['app'].app_context():
|
2020-04-21 16:34:21 +00:00
|
|
|
corpus_file = CorpusFile.query.get(corpus_file_id)
|
|
|
|
if corpus_file is None:
|
2020-07-10 09:36:54 +00:00
|
|
|
raise Exception('Corpus file {} not found'.format(corpus_file_id))
|
|
|
|
corpus_file.delete()
|
|
|
|
db.session.commit()
|
2020-10-08 10:48:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@background
|
|
|
|
def delete_query_result(query_result_id, *args, **kwargs):
|
|
|
|
with kwargs['app'].app_context():
|
|
|
|
query_result = QueryResult.query.get(query_result_id)
|
|
|
|
if query_result is None:
|
|
|
|
raise Exception('QueryResult {} not found'.format(query_result_id))
|
|
|
|
query_result.delete()
|
|
|
|
db.session.commit()
|