2022-02-08 12:26:20 +01:00
|
|
|
from app import db
|
|
|
|
from app.decorators import background
|
|
|
|
from app.models import Corpus, CorpusFile
|
2020-04-21 18:34:21 +02:00
|
|
|
|
|
|
|
|
2020-04-23 07:56:23 +02:00
|
|
|
@background
|
2020-04-23 08:35:18 +02:00
|
|
|
def build_corpus(corpus_id, *args, **kwargs):
|
|
|
|
app = kwargs['app']
|
2020-04-23 07:56:23 +02:00
|
|
|
with app.app_context():
|
|
|
|
corpus = Corpus.query.get(corpus_id)
|
|
|
|
if corpus is None:
|
2021-12-08 14:45:05 +01:00
|
|
|
raise Exception(f'Corpus {corpus_id} not found')
|
2020-07-10 11:36:54 +02:00
|
|
|
corpus.build()
|
2020-04-23 07:56:23 +02:00
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
2020-04-21 18:34:21 +02:00
|
|
|
@background
|
2020-04-23 08:35:18 +02:00
|
|
|
def delete_corpus(corpus_id, *args, **kwargs):
|
2020-07-10 11:36:54 +02:00
|
|
|
with kwargs['app'].app_context():
|
2020-04-21 18:34:21 +02:00
|
|
|
corpus = Corpus.query.get(corpus_id)
|
|
|
|
if corpus is None:
|
2021-12-08 14:45:05 +01:00
|
|
|
raise Exception(f'Corpus {corpus_id} not found')
|
2020-04-21 18:34:21 +02:00
|
|
|
corpus.delete()
|
2020-07-10 11:36:54 +02:00
|
|
|
db.session.commit()
|
2020-04-21 18:34:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
@background
|
2020-04-23 08:35:18 +02:00
|
|
|
def delete_corpus_file(corpus_file_id, *args, **kwargs):
|
2020-07-10 11:36:54 +02:00
|
|
|
with kwargs['app'].app_context():
|
2020-04-21 18:34:21 +02:00
|
|
|
corpus_file = CorpusFile.query.get(corpus_file_id)
|
|
|
|
if corpus_file is None:
|
2021-12-08 14:45:05 +01:00
|
|
|
raise Exception(f'Corpus file {corpus_file_id} not found')
|
2020-07-10 11:36:54 +02:00
|
|
|
corpus_file.delete()
|
|
|
|
db.session.commit()
|