jieba nltk 进行中英文分词

Jieba、NLTK等中英文分词工具进行分词
建议:中文分词使用 jieba(SnowNlp、THULAC、NLPIR、StanfordCoreNLP)进行分词,英文使用 NLTK进行分词;还有git上的一个英文文本分词(无空格)模块wordninja
1.中文分词
1.jieba分词
import jieba import re
Chinese=‘央视315晚会曝光湖北省知名的神丹牌、莲田牌“土鸡蛋”实为普通鸡蛋冒充,同时在商标上玩猫腻,分别注册“鲜土”、注册“好土”商标,让消费者误以为是“土鸡蛋”。3月15日晚间,新京报记者就此事致电湖北神丹健康食品有限公司方面,其工作人员表示不知情,需要了解清楚情况,截至发稿暂未取得最新回应。新京报记者还查询发现,湖北神丹健康食品有限公司为农业产业化国家重点龙头企业、高新技术企业,此前曾因涉嫌虚假宣传“中国最大的蛋品企业”而被罚6万元。’
str=re.sub(’[^\w]’,’’,chinese) #使用正则去符号,之后都是用这个str字符串
seg_list=jieba.cut(s_list, cut_all=False) #精确模式 print(’/’.join(seg_list))

2.nltk分词
import nltk import re
english=‘H:\\自然语言处理\\Experiment2\\English.txt’ with open(english,‘r’,encoding=‘utf-8’) as file:
u=file.read() str=re.sub(’[^\w ]’,’’,u) print(nltk.word_tokenize(str)) print(nltk.pos_tag(nltk.word_tokenize(str)))
#对分完词的结果进行词性标注

3.模块wordninja 分词
下面简单以实例看一下它的功能: ‘’’ https://github.com/yishuihanhan/wordninja ‘’’
import wordninja
print(wordninja.split(‘derekanderson’) print(wordninja.split(‘imateapot’) print(wordninja.split(‘wethepeopleoftheunitedstatesinordertoformamoreperfectunionestablishjusticeinsuredomestictranquilityprovideforthecommondefencepromotethegeneralwelfareandsecuretheblessingsoflibertytoourselvesandourposteritydoordainandestablishthisconstitutionfortheunitedstatesofamerica’) print(wordninja.split(‘littlelittlestar’)
结果如下: [‘derek’, ‘anderson’] [‘im’, ‘a’, ‘teapot’] [‘we’, ‘the’, ‘people’, ‘of’, ‘the’, ‘united’, ‘states’, ‘in’, ‘order’, ‘to’, ‘form’, ‘a’, ‘more’, ‘perfect’, ‘union’, ‘establish’, ‘justice’, ‘in’, ‘sure’, ‘domestic’, ‘tranquility’, ‘provide’, ‘for’, ‘the’, ‘common’, ‘defence’, ‘promote’, ‘the’, ‘general’, ‘welfare’, ‘and’, ‘secure’, ‘the’, ‘blessings’, ‘of’, ‘liberty’, ‘to’, ‘ourselves’, ‘and’, ‘our’, ‘posterity’, ‘do’, ‘ordain’, ‘and’, ‘establish’, ‘this’, ‘constitution’, ‘for’, ‘the’, ‘united’, ‘states’, ‘of’, ‘america’] [‘little’, ‘little’, ‘star’]

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小金子的夏天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值