pkuseg-python icon indicating copy to clipboard operation
pkuseg-python copied to clipboard

自定义的用户词典添加的包含空格的关键词无法生效

Open tlemar opened this issue 6 years ago • 2 comments

seg2 = pkuseg.pkuseg(model_name='web', user_dict=["Color OS", "前摄像头"])

print(seg2.cut("Color OS"))   # ['Color', 'OS']
print(seg2.cut("前摄像头"))   # ['前摄像头']

在用户词典中添加带有空格的关键词,但是在后续的分词过程中并没有生效。

tlemar avatar Nov 21 '19 02:11 tlemar

分别添加Color和OS即可

ZhiyiLan avatar Dec 16 '19 07:12 ZhiyiLan

def cut(self, txt): """分词,结果返回一个list"""

    # txt = txt.strip()

    ret = []
    usertags = []

    if not txt:
        return ret

    # imary = txt.split()  # 根据空格分为多个片段
    imary = [txt]

修改两个注释掉的句子,可以解决

Nisoka avatar Nov 30 '20 02:11 Nisoka