mirror of
https://github.com/fxsjy/jieba.git
synced 2025-07-10 00:01:33 +08:00
paddle coredump exception fix (#807)
* paddle_null_point_fix * add core expception note * delete yield * modify test paddle for supporting enable_paddle()
This commit is contained in:
parent
dc2b788eb3
commit
d703bce302
3
jieba/__init__.py
Normal file → Executable file
3
jieba/__init__.py
Normal file → Executable file
@ -298,8 +298,9 @@ class Tokenizer(object):
|
||||
is_paddle_installed = check_paddle_install['is_paddle_installed']
|
||||
sentence = strdecode(sentence)
|
||||
if use_paddle and is_paddle_installed:
|
||||
# if sentence is null, it will raise core exception in paddle.
|
||||
if sentence is None or sentence == "" or sentence == u"":
|
||||
yield sentence
|
||||
return
|
||||
import jieba.lac_small.predict as predict
|
||||
results = predict.get_sent(sentence)
|
||||
for sent in results:
|
||||
|
@ -279,8 +279,9 @@ def cut(sentence, HMM=True, use_paddle=False):
|
||||
"""
|
||||
is_paddle_installed = check_paddle_install['is_paddle_installed']
|
||||
if use_paddle and is_paddle_installed:
|
||||
# if sentence is null, it will raise core exception in paddle.
|
||||
if sentence is None or sentence == "" or sentence == u"":
|
||||
yield pair(None, None)
|
||||
return
|
||||
import jieba.lac_small.predict as predict
|
||||
sents, tags = predict.get_result(strdecode(sentence))
|
||||
for i, sent in enumerate(sents):
|
||||
|
2
test/test_paddle.py
Normal file → Executable file
2
test/test_paddle.py
Normal file → Executable file
@ -2,7 +2,7 @@
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
import jieba
|
||||
|
||||
jieba.enable_paddle()
|
||||
|
||||
def cuttest(test_sent):
|
||||
result = jieba.cut(test_sent, use_paddle=True)
|
||||
|
3
test/test_paddle_postag.py
Normal file → Executable file
3
test/test_paddle_postag.py
Normal file → Executable file
@ -2,7 +2,8 @@
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
import jieba.posseg as pseg
|
||||
|
||||
import jieba
|
||||
jieba.enable_paddle()
|
||||
|
||||
def cuttest(test_sent):
|
||||
result = pseg.cut(test_sent, use_paddle=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user