Skip to content

Commit

Permalink
Fixture of corpus of docs with one subject only for SVC backend training
Browse files Browse the repository at this point in the history
  • Loading branch information
juhoinkinen committed Jul 1, 2021
1 parent 38d7aec commit efced0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ def document_corpus(subject_index):
return doc_corpus


@pytest.fixture(scope='module')
def document_corpus_single_subject(document_corpus):
docs_single_subj = []
for doc in document_corpus.documents:
uri = list(doc.uris)[0] if len(doc.uris) > 0 else None
label = list(doc.labels)[0] if len(doc.labels) > 0 else None
docs_single_subj.append(
annif.corpus.Document(doc.text, {uri}, {label}))
return annif.corpus.DocumentList(docs_single_subj)


@pytest.fixture(scope='module')
def pretrained_vectors():
return py.path.local(os.path.join(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_backend_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ def test_svc_suggest_no_vectorizer(project):
svc.suggest("example text")


def test_svc_train(datadir, document_corpus, project):
def test_svc_train(datadir, document_corpus_single_subject, project):
svc_type = annif.backend.get_backend('svc')
svc = svc_type(
backend_id='svc',
config_params={},
project=project)

svc.train(document_corpus)
svc.train(document_corpus_single_subject)
assert svc._model is not None
assert datadir.join('svc-model.gz').exists()


def test_svc_train_ngram(datadir, document_corpus, project):
def test_svc_train_ngram(datadir, document_corpus_single_subject, project):
svc_type = annif.backend.get_backend('svc')
svc = svc_type(
backend_id='svc',
config_params={'ngram': 2},
project=project)

svc.train(document_corpus)
svc.train(document_corpus_single_subject)
assert svc._model is not None
assert datadir.join('svc-model.gz').exists()

Expand Down

0 comments on commit efced0a

Please sign in to comment.