命名实体识别介绍

1 初始化数据

paragraph1 = """Please send this message to those people who mean something to 
you,to those who have touched your life in one way or another,to those who make you 
smile when you really need it,to those that make you see the brighter side of things 
when you are really down,to those who you want to let them know that you appreciate 
their friendship.And if you don’t, don’t worry,nothing bad will happen to you,you 
will just miss out on the opportunity to brighten someone’s day with this message.
 """
paragraph2 = 'Beijing, Shanghai, Tianjin'

2 查看nltk的版本

# 查看nltk的版本
import nltk
print('NLTK version: %s' % (nltk.__version__))

输出

版本

3 导入包

# 需要导入的包
from nltk import word_tokenize, pos_tag, ne_chunk

nltk.download('words')
nltk.download('averaged_perceptron_tagger')
nltk.download('punkt')
nltk.download('maxent_ne_chunker')

输出

输出

4 进行分词

# 进行分词!
results = ne_chunk(pos_tag(word_tokenize(paragraph1)))
print('The sentence is: %s' % (paragraph1))
print()
for x in str(results).split('\n'):
    if '/NNP' in x:
        print(x)

输出1

输出啊

results = ne_chunk(pos_tag(word_tokenize(paragraph2)))
print(paragraph2)
print()
for x in str(results).split('\n'):
    if '/NNP' in x:
        print(x)

输出2

输出

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值