一:首先要装第三方库
1 pip install pyhanlp
二:复制粘贴以下代码:
1 from pyhanlp import * 2 3 if __name__ == '__main__': 4 text1 = "1998年11月11日,马化腾和同学张志东在广东省深圳市正式注册成立“深圳市腾讯计算机系统有限公司”," 5 "之后许晨晔、陈一丹、曾李青相继加入。当时公司的业务是拓展无线网络寻呼系统,为寻呼台建立网上寻呼系统," 6 "这种针对企业或单位的软件开发工程是所有中小型网络服务公司的最佳选择。" 7 CRFnewSegment=HanLP.newSegment("crf") 8 9 term_list=CRFnewSegment.seg(text1) 10 print(term_list) 11 12 rmlist=[] 13 compliist=[] 14 for term in term_list: 15 nature=str(term.nature) 16 if(nature=="nr"): 17 rmlist.append(term.word) 18 print(term) 19 if(nature=='nt'): 20 compliist.append(term.word) 21 print(rmlist) 22 print(compliist)