From b9af8b270b2f9af6e458a0366e16e792a635d074 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Fri, 2 Sep 2022 16:47:18 +0300 Subject: [PATCH] allow use of hyphens in vocabulary IDs --- annif/registry.py | 2 +- tests/projects.cfg | 2 +- tests/test_vocab.py | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/annif/registry.py b/annif/registry.py index 0d4648958..57c77a94c 100644 --- a/annif/registry.py +++ b/annif/registry.py @@ -76,7 +76,7 @@ def get_vocab(self, vocab_spec, default_language): vocab_spec. If no language information is specified, use the given default language.""" - match = re.match(r'(\w+)(\((.*)\))?', vocab_spec) + match = re.match(r'([\w-]+)(\((.*)\))?$', vocab_spec) if match is None: raise ValueError( f"Invalid vocabulary specification: {vocab_spec}") diff --git a/tests/projects.cfg b/tests/projects.cfg index 1c7b7ad40..5069a51dd 100644 --- a/tests/projects.cfg +++ b/tests/projects.cfg @@ -68,7 +68,7 @@ analyzer=snowball(english) [noname] language=en backend=tfidf -vocab=dummy +vocab=dummy-noname analyzer=snowball(english) [noparams-tfidf-fi] diff --git a/tests/test_vocab.py b/tests/test_vocab.py index cc79dd6b3..3721b3bdc 100644 --- a/tests/test_vocab.py +++ b/tests/test_vocab.py @@ -25,6 +25,12 @@ def test_get_vocab_invalid(registry): assert 'Invalid vocabulary specification' in str(excinfo.value) +def test_get_vocab_hyphen(registry): + vocab, lang = registry.get_vocab('dummy-noname', None) + assert vocab.vocab_id == 'dummy-noname' + assert vocab is not None + + def test_update_subject_index_with_no_changes(tmpdir): vocab = load_dummy_vocab(tmpdir)