Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
fix: add fallback for not in trie words
Browse files Browse the repository at this point in the history
  • Loading branch information
yokomotod committed Jun 24, 2021
1 parent 63400e5 commit fd4561c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sudachipy/dictionarylib/doublearraylexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,21 @@ def size(self) -> int:

def get_word_id(self, headword: str, pos_id: int, reading_form: str) -> int:
for wid, _ in self.lookup(headword.encode('utf-8'), 0):
info = self.word_infos.get_word_info(wid)
if info.surface == headword \
and info.pos_id == pos_id \
and info.reading_form == reading_form:
if self._compare_word_id(wid, headword, pos_id, reading_form):
return wid

for wid in range(self.word_infos.size()):
if self._compare_word_id(wid, headword, pos_id, reading_form):
return wid

return -1

def _compare_word_id(self, wid: int, headword: str, pos_id: int, reading_form: str) -> bool:
info = self.word_infos.get_word_info(wid)
return info.surface == headword \
and info.pos_id == pos_id \
and info.reading_form == reading_form

def get_dictionary_id(self, word_id: int) -> int:
return 0

Expand Down

0 comments on commit fd4561c

Please sign in to comment.