pkuseg-python
pkuseg-python copied to clipboard
自定义的用户词典添加的包含空格的关键词无法生效
seg2 = pkuseg.pkuseg(model_name='web', user_dict=["Color OS", "前摄像头"]) print(seg2.cut("Color OS")) # ['Color', 'OS'] print(seg2.cut("前摄像头")) # ['前摄像头']
在用户词典中添加带有空格的关键词,但是在后续的分词过程中并没有生效。
分别添加Color和OS即可
def cut(self, txt): """分词,结果返回一个list"""
# txt = txt.strip()
ret = []
usertags = []
if not txt:
return ret
# imary = txt.split() # 根据空格分为多个片段
imary = [txt]
修改两个注释掉的句子,可以解决