使用NLTK进行英文分词

使用NLTK进行英文分词

import nltk
import re
english='C:\\Users\\pc\\CapStone\\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))) #对分完词的结果进行词性标注

#result

['Trump', 'was', 'born', 'and', 'raised', 'in', 'the', 'New', 'York', 'City', 'borough', 'of', 'Queens', 'and', 'received', 'an', 'economics', 'degree', 'from', 'the', 'Wharton', 'School', 'He', 'was', 'appointed', 'president', 'of', 'his', 'familys', 'real', 'estate', 'business', 'in', '1971', 'renamed', 'it', 'The', 'Trump', 'Organization', 'and', 'expanded', 'it', 'from', 'Queens', 'and', 'Brooklyn', 'into', 'Manhattan', 'The', 'company', 'built', 'or', 'renovated', 'skyscrapers', 'hotels', 'casinos', 'and', 'golf', 'courses', 'Trump', 'later', 'started', 'various', 'side', 'ventures', 'including', 'licensing', 'his', 'name', 'for', 'real', 'estate', 'and', 'consumer', 'products', 'He', 'managed', 'the', 'company', 'until', 'his', '2017', 'inauguration', 'He', 'coauthored', 'several', 'books', 'including', 'The', 'Art', 'of', 'the', 'Deal', 'He', 'owned', 'the', 'Miss', 'Universe', 'and', 'Miss', 'USA', 'beauty', 'pageants', 'from', '1996', 'to', '2015', 'and', 'he', 'produced', 'and', 'hosted', 'The', 'Apprentice', 'a', 'reality', 'television', 'show', 'from', '2003', 'to', '2015', 'Forbes', 'estimates', 'his', 'net', 'worth', 'to', 'be', '31', 'billion']
[('Trump', 'NNP'), ('was', 'VBD'), ('born', 'VBN'), ('and', 'CC'), ('raised', 'VBN'), ('in', 'IN'), ('the', 'DT'), ('New', 'NNP'), ('York', 'NNP'), ('City', 'NNP'), ('borough', 'NN'), ('of', 'IN'), ('Queens', 'NNP'), ('and', 'CC'), ('received', 'VBD'), ('an', 'DT'), ('economics', 'NNS'), ('degree', 'NN'), ('from', 'IN'), ('the', 'DT'), ('Wharton', 'NNP'), ('School', 'NNP'), ('He', 'PRP'), ('was', 'VBD'), ('appointed', 'VBN'), ('president', 'NN'), ('of', 'IN'), ('his', 'PRP$'), ('familys', 'JJ'), ('real', 'JJ'), ('estate', 'NN'), ('business', 'NN'), ('in', 'IN'), ('1971', 'CD'), ('renamed', 'VBD'), ('it', 'PRP'), ('The', 'DT'), ('Trump', 'NNP'), ('Organization', 'NNP'), ('and', 'CC'), ('expanded', 'VBD'), ('it', 'PRP'), ('from', 'IN'), ('Queens', 'NNP'), ('and', 'CC'), ('Brooklyn', 'NNP'), ('into', 'IN'), ('Manhattan', 'NNP'), ('The', 'DT'), ('company', 'NN'), ('built', 'VBD'), ('or', 'CC'), ('renovated', 'VBD'), ('skyscrapers', 'NNS'), ('hotels', 'NNS'), ('casinos', 'NNS'), ('and', 'CC'), ('golf', 'NN'), ('courses', 'NNS'), ('Trump', 'NNP'), ('later', 'RB'), ('started', 'VBD'), ('various', 'JJ'), ('side', 'NN'), ('ventures', 'NNS'), ('including', 'VBG'), ('licensing', 'VBG'), ('his', 'PRP$'), ('name', 'NN'), ('for', 'IN'), ('real', 'JJ'), ('estate', 'NN'), ('and', 'CC'), ('consumer', 'NN'), ('products', 'NNS'), ('He', 'PRP'), ('managed', 'VBD'), ('the', 'DT'), ('company', 'NN'), ('until', 'IN'), ('his', 'PRP$'), ('2017', 'CD'), ('inauguration', 'NN'), ('He', 'PRP'), ('coauthored', 'VBD'), ('several', 'JJ'), ('books', 'NNS'), ('including', 'VBG'), ('The', 'DT'), ('Art', 'NN'), ('of', 'IN'), ('the', 'DT'), ('Deal', 'NNP'), ('He', 'PRP'), ('owned', 'VBD'), ('the', 'DT'), ('Miss', 'NNP'), ('Universe', 'NNP'), ('and', 'CC'), ('Miss', 'NNP'), ('USA', 'NNP'), ('beauty', 'NN'), ('pageants', 'NNS'), ('from', 'IN'), ('1996', 'CD'), ('to', 'TO'), ('2015', 'CD'), ('and', 'CC'), ('he', 'PRP'), ('produced', 'VBD'), ('and', 'CC'), ('hosted', 'VBD'), ('The', 'DT'), ('Apprentice', 'NNP'), ('a', 'DT'), ('reality', 'NN'), ('television', 'NN'), ('show', 'NN'), ('from', 'IN'), ('2003', 'CD'), ('to', 'TO'), ('2015', 'CD'), ('Forbes', 'NNP'), ('estimates', 'VBZ'), ('his', 'PRP$'), ('net', 'JJ'), ('worth', 'NN'), ('to', 'TO'), ('be', 'VB'), ('31', 'CD'), ('billion', 'CD')]

 

 

english.txt内容:

Trump was born and raised in the New York City borough of Queens and received an economics degree from the Wharton School. He was appointed president of his family's real estate business in 1971, renamed it The Trump Organization, and expanded it from Queens and Brooklyn into Manhattan. The company built or renovated skyscrapers, hotels, casinos, and golf courses. Trump later started various side ventures, including licensing his name for real estate and consumer products. He managed the company until his 2017 inauguration. He co-authored several books, including The Art of the Deal. He owned the Miss Universe and Miss USA beauty pageants from 1996 to 2015, and he produced and hosted The Apprentice, a reality television show, from 2003 to 2015. Forbes estimates his net worth to be $3.1 billion.

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值