Skip to content

Commit

Permalink
Fix bug when trie is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
Crivella committed Oct 9, 2023
1 parent 96b1f60 commit 06f9bd9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ocr_translate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
###################################################################################
"""OCR and translation of images."""

__version__ = '0.3.1'
__version__ = '0.3.2'
4 changes: 1 addition & 3 deletions ocr_translate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06f9bd9

Please sign in to comment.