NLP常用工具包实战 (4)spacy工具包:文本处理、词性、命名体识别、案例一(找出所有人物名字)、案例二(恐怖袭击文本资料分析)

导入工具包和英文模型

# python -m spacy download en 用管理员身份打开CMD
import spacy
nlp = spacy.load('en')
from spacy import displacy
from collections import Counter, defaultdict
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

1 文本处理

doc = nlp('Weather is good, very windy and sunny. We have no classes in the afternoon.')
# 分词
for token in doc:
    print(token)
# 分句
for sent in doc.sents:
    print(sent)

2 词性

for token in doc:
    print('{}-{}'.format(token, token.pos_))

3 命名体识别

doc_2 = nlp("I went to Paris where I met my old friend Jack from uni.")
for ent in doc_2.ents:
    print('{}-{}'.format(ent, ent.label_)
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值