Skip to content

Commit

Permalink
engine: Fix a bug
Browse files Browse the repository at this point in the history
engine/dictionary.py (assisted_lookup)
  • Loading branch information
ShikiOkasaka committed Sep 23, 2024
1 parent ceb9dcd commit 2180b83
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions engine/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ def assisted_lookup(self, model, text, pos, anchor=0):
else:
cand = []
stem = ''
pos_found = -1
pos_shrunk = -1
for i in range(suffix - 1, anchor - 1, -1):
if text[i] not in HIRAGANA:
break
Expand All @@ -566,10 +568,12 @@ def assisted_lookup(self, model, text, pos, anchor=0):
if not cand:
continue
if shrunk:
# Remove shrunk found in the previous lookup.
assert shrunk in cand
cand.remove(shrunk)
shrunk = text[i] + stem
# Remove shrunk created in the previous lookup
cand_shrunk = self._dict.get(text[pos_shrunk:suffix + 1])
assert shrunk in cand_shrunk
cand_shrunk.remove(shrunk)
shrunk = text[i:pos_found] + stem
pos_shrunk = i
if shrunk not in cand:
# Temporarily register shrunk in the working dictionary
cand = cand[:]
Expand All @@ -581,6 +585,7 @@ def assisted_lookup(self, model, text, pos, anchor=0):
cont = self.lookup_next_yougen(text, i, pos, suffix)
if yomi != self._yomi:
yomi = self._yomi
pos_found = i
stem_list = self._get_stem_list()
p_dict = model.assist_yougen(text[:pos - len(yomi)], yomi, stem_list)
suggested = max(p_dict, key=p_dict.get)
Expand Down

0 comments on commit 2180b83

Please sign in to comment.