Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix userword match #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions pkuseg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,23 @@ def solve(self, txt):
now = self.trie
j = i
found = False
last_word_idx = -1 # 表示从当前位置i往后匹配,最长匹配词词尾的idx
while True:
c = txt[j]
if not c in now.children:
if not c in now.children and last_word_idx != -1:
found = True
break
if not c in now.children and last_word_idx == -1:
break
now = now.children[c]
j += 1
if now.isword:
found = True
last_word_idx = j
j += 1
if j == l and last_word_idx == -1:
break
if j == l:
if j == l and last_word_idx != -1 :
j = last_word_idx + 1
found = True
break
if found:
if last != i:
Expand Down