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

Refactor finalseg #902

Open
wants to merge 1 commit 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
38 changes: 17 additions & 21 deletions jieba/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ def __cut_DAG_NO_HMM(self, sentence):
buf = ''

def __cut_DAG(self, sentence):

def _cut_finalseg(buf):
if len(buf) == 1:
yield buf
elif not self.FREQ.get(buf):
recognized = finalseg.cut(buf)
for t in recognized:
yield t
else:
for elem in buf:
yield elem

DAG = self.get_DAG(sentence)
route = {}
self.calc(sentence, DAG, route)
Expand All @@ -260,31 +272,15 @@ def __cut_DAG(self, sentence):
buf += l_word
else:
if buf:
if len(buf) == 1:
yield buf
buf = ''
else:
if not self.FREQ.get(buf):
recognized = finalseg.cut(buf)
for t in recognized:
yield t
else:
for elem in buf:
yield elem
buf = ''
for buf_cut in _cut_finalseg(buf):
yield buf_cut
buf = ''
yield l_word
x = y

if buf:
if len(buf) == 1:
yield buf
elif not self.FREQ.get(buf):
recognized = finalseg.cut(buf)
for t in recognized:
yield t
else:
for elem in buf:
yield elem
for buf_cut in _cut_finalseg(buf):
yield buf_cut

def cut(self, sentence, cut_all=False, HMM=True, use_paddle=False):
"""
Expand Down