Skip to content

Commit

Permalink
Merge pull request #619 from NatLibFi/fix-vocab-id-hyphen
Browse files Browse the repository at this point in the history
Allow use of hyphens in vocabulary IDs
  • Loading branch information
osma authored Sep 2, 2022
2 parents 48b23f7 + b9af8b2 commit da680d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion annif/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion tests/projects.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ analyzer=snowball(english)
[noname]
language=en
backend=tfidf
vocab=dummy
vocab=dummy-noname
analyzer=snowball(english)

[noparams-tfidf-fi]
Expand Down
6 changes: 6 additions & 0 deletions tests/test_vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit da680d3

Please sign in to comment.