diff --git a/CHANGELOG.md b/CHANGELOG.md index d356f5c..ee6d7f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ List of changes between versions +## 0.3.2 + +restore_missing_spaces with no trie (None for that language) was causing exceptions. +Now the server will skip this step if the trie for the selected language is not found. + ## 0.3.1 Removed runaway print statements diff --git a/ocr_translate/__init__.py b/ocr_translate/__init__.py index bb19f55..29d284a 100644 --- a/ocr_translate/__init__.py +++ b/ocr_translate/__init__.py @@ -18,4 +18,4 @@ ################################################################################### """OCR and translation of images.""" -__version__ = '0.3.1' +__version__ = '0.3.2' diff --git a/ocr_translate/models.py b/ocr_translate/models.py index af6e799..477a399 100644 --- a/ocr_translate/models.py +++ b/ocr_translate/models.py @@ -361,9 +361,7 @@ def pre_tokenize( else: text = text.replace('\n', ' ') - if restore_missing_spaces: - trie = get_trie_src() - + if restore_missing_spaces and not (trie := get_trie_src()) is None: res = [ trie.decompose(split, min_length=1) if not trie.search(split, strict=False) else diff --git a/tests/test_models.py b/tests/test_models.py index 7e1760e..edb0c38 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -240,11 +240,6 @@ def test_tsl_pre_tokenize_restorespaces(monkeypatch): res = m.TSLModel.pre_tokenize('applepie', restore_missing_spaces=True) assert res == ['apple pie'] -def test_tsl_pre_tokenize_restorespaces_notrie(): - """Test pre_tokenize with restore spaces.""" - with pytest.raises(AttributeError): - m.TSLModel.pre_tokenize('applepie', restore_missing_spaces=True) - def test_tsl_run( monkeypatch, mock_called, text: m.Text, language: m.Language, tsl_model: m.TSLModel, option_dict: m.OptionDict