方法是加入常用词词典或完螫词典
通过宇符串与词典中单词
匹配的个数,最终选中正确的一个结果或缩小正确的结果为2到几句
子,减少人工干预,实现计算机智能选择正确结果。
简单示例:
d={'hi','hello','world','have','a','nice','day'}
s=['this is a nice day','hello world','this is a test','hi,this is a nice day']
import jieba
res={}
for st in s:
w=jieba.cut(st)
m=len(set(w)&d)
res[st]=m
od=sorted(res.items(),key=lambda x:x[1],reverse=True)
print('results:\n',od[0],'freq is:',round(od[0][1]/len(d),2),'\n',od[1],'freq is:',round(od[1][1]/len(d),2))
results:
('hi,this is a nice day', 4) freq is: 0.57
('this is a nice day', 3) freq is: 0.43
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!