Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_project_en(app):
with app.app_context():
project = annif.project.get_project('dummy-en')
assert project.project_id == 'dummy-en'
assert project.language == 'en'
assert project.analyzer.name == 'snowball'
assert project.analyzer.param == 'english'
assert project.access == Access.hidden
assert isinstance(project.backend, annif.backend.dummy.DummyBackend)
def test_project_learn(app, tmpdir):
tmpdir.join('doc1.txt').write('doc1')
tmpdir.join('doc1.tsv').write('\tkey1')
tmpdir.join('doc2.txt').write('doc2')
tmpdir.join('doc2.tsv').write('\tkey2')
docdir = annif.corpus.DocumentDirectory(str(tmpdir))
with app.app_context():
project = annif.project.get_project('dummy-fi')
project.learn(docdir)
result = project.suggest('this is some text')
assert len(result) == 1
assert result[0].uri == 'http://example.org/key1'
assert result[0].label == 'key1'
assert result[0].score == 1.0
def test_project_initialized(app_with_initialize):
with app_with_initialize.app_context():
project = annif.project.get_project('dummy-en')
assert project.initialized
assert project.backend.initialized
def test_project_load_vocabulary_tfidf(app, vocabulary, testdatadir):
with app.app_context():
project = annif.project.get_project('tfidf-fi')
project.vocab.load_vocabulary(vocabulary)
assert testdatadir.join('vocabs/yso-fi/subjects').exists()
assert testdatadir.join('vocabs/yso-fi/subjects').size() > 0
def test_project_load_vocabulary_fasttext(app, vocabulary, testdatadir):
pytest.importorskip("annif.backend.fasttext")
with app.app_context():
project = annif.project.get_project('fasttext-fi')
project.vocab.load_vocabulary(vocabulary)
assert testdatadir.join('vocabs/yso-fi/subjects').exists()
assert testdatadir.join('vocabs/yso-fi/subjects').size() > 0
def show_project(project_id):
"""
Show project information.
Usage: annif show-project
REST equivalent:
GET /projects/
"""
try:
return annif.project.get_project(project_id).dump()
except ValueError:
return "No projects found with id \'{0}\'.".format(project_id)
def _get_input(self, input, project, text):
if input == '_text_':
return self._normalize_text(project, text)
else:
proj = annif.project.get_project(input)
result = proj.suggest(text)
features = [
'{}:{}'.format(self._cleanup_text(hit.uri), hit.score)
for hit in result.hits]
return ' '.join(features)