python 使用spaCy 进行NLP处理
原文:http://mp.weixin.qq.com/s/sqa-Ca2oXhvcPHJKg9PuVg
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("The big grey dog ate all of the chocalate,but fortunately he wasn't sick!")
# 利用空格分开
print(doc.text.split())
# 利用token的.orth_方法,可以识别标点符号
print([token.orth_ for token in doc])
# 带下划线的方法返回字符、不带下划线的方法返回数字
print([(token, token.orth_, token.orth) for token in doc])
# 分词,去除标点和空格
print([token.orth_ for token in doc if not token.is_punct | token.is_space])
# 标准化到基本形式
practice = "practice practiced practicing"
nlp_practice = nlp(practice)
print([word.lemma_ for word in nlp_practice])
# 词性标注 可以使用.pos_ 和 .tag_方法访问粗粒度POS标记和细粒度POS标记
doc2 = nlp("Conor's dog's toy was hidden under the man's sofa in the woman's house")
pos_tags = [(i, i.tag_) for i in doc2]
print(pos_tags)
# 's 的标签被标记为 POS.可以利用这个标记提取所有者和他们拥有的东西
owners_possessions = []
for i in pos_tags:
if i[1] == "POS":
owner = i[0].nbor(-1)
possession = i[0].nbor(1)
owners_possessions.append((owner, possession))
print(owners_possessions)
# 简化代码
print([(i[0].nbor(-1), i[0].nbor(1)) for i in pos_tags if i[1] == "POS"])
# 实体识别 PERSON 是不言自明的;NORP是国籍或宗教团体;GGPE标识位置(城市、国家等等);DATE 标识特定的日期或日期范围, ORDINAL标识一个表示某种类型的顺序的单词或数字。
wiki_obama = """Barack Obama is an American politician who served as the 44th President of the United States from 2009 to 2017. He is the first African American to have served as president, as well as the first born outside the contiguous United States."""
nlp_obama = nlp(wiki_obama)
print([(i, i.label_, i.label) for i in nlp_obama.ents])
# 将文章分成句子
for ix, sent in enumerate(nlp_obama.sents,1):
print("Sentence number {}:{}".format(ix,sent))
python 使用spaCy 进行NLP处理的更多相关文章
- 搜索引擎如何检索结果:Python和spaCy信息提取简介
概览 像Google这样的搜索引擎如何理解我们的查询并提供相关结果? 了解信息提取的概念 我们将使用流行的spaCy库在Python中进行信息提取 介绍 作为一个数据科学家,在日常工作中,我严重依赖搜 ...
- [转]【NLP】干货!Python NLTK结合stanford NLP工具包进行文本处理 阅读目录
[NLP]干货!Python NLTK结合stanford NLP工具包进行文本处理 原贴: https://www.cnblogs.com/baiboy/p/nltk1.html 阅读目录 目 ...
- 【NLP】干货!Python NLTK结合stanford NLP工具包进行文本处理
干货!详述Python NLTK下如何使用stanford NLP工具包 作者:白宁超 2016年11月6日19:28:43 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的 ...
- 机器学习资源汇总----来自于tensorflow中文社区
新手入门完整教程进阶指南 API中文手册精华文章TF社区 INTRODUCTION 1. 新手入门 1.1. 介绍 1.2. 下载及安装 1.3. 基本用法 2. 完整教程 2.1. 总览 2.2. ...
- 使用Python中的NLTK和spaCy删除停用词与文本标准化
概述 了解如何在Python中删除停用词与文本标准化,这些是自然语言处理的基本技术 探索不同的方法来删除停用词,以及讨论文本标准化技术,如词干化(stemming)和词形还原(lemmatizatio ...
- 自然语言处理NLP程序包(NLTK/spaCy)使用总结
NLTK和SpaCy是NLP的Python应用,提供了一些现成的处理工具和数据接口.下面介绍它们的一些常用功能和特性,便于对NLP研究的组成形式有一个基本的了解. NLTK Natural Langu ...
- Python 和 R 数据分析/挖掘工具互查
如果大家已经熟悉python和R的模块/包载入方式,那下面的表查找起来相对方便.python在下表中以模块.的方式引用,部分模块并非原生模块,请使用 pip install * 安装:同理,为了方便索 ...
- 自然语言处理NLP快速入门
自然语言处理NLP快速入门 https://mp.weixin.qq.com/s/J-vndnycZgwVrSlDCefHZA [导读]自然语言处理已经成为人工智能领域一个重要的分支,它研究能实现人与 ...
- Spacy 使用
# 前提是必须安装: python -m spacy download ennlp = spacy.load('en')text = u"you are best. it is lemmat ...
随机推荐
- Alpha冲刺! Day1 - 磨刀
Alpha冲刺! Day1 - 磨刀 序章 Alpha冲刺开始的比印象中的计划早,翻回去看系统设计那篇作业博客的实践时间安排表格发现不!见!了!! 因为计划提前,但又必须在编码开始之前把所有逻辑讨论清 ...
- EJB3.0中的session bean以及MDB解析
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/aboy123/article/details/24587133 大型业务系统面临的主要问题就是高并发 ...
- UVA11853-Paintball(对偶图)
Problem UVA11853-Paintball Accept:229 Submit:1830 Time Limit: 3000 mSec Problem Description You are ...
- trace文件解读
*********************************************************************示例:全表扫描的10046文件解读************** ...
- 转://执行impdp时出现ORA-39154错误的解决案例
问题描述如下导出过程正常:expdp \"/ as sysdba\" tables=user_a.t directory=mydir dumpfile=t.dmp logfile= ...
- vue.js 传参 href传参 与router-link传参
每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code 1. <a v-bind:href="'#/appinfo/'+cateApp ...
- ethereum/EIPs-55 Mixed-case checksum address encoding
eip title author type category status created 55 Mixed-case checksum address encoding Vitalik Buteri ...
- 监控nginx
vi nginx_status.sh #!/bin/bash HOST="127.0.0.1" PORT="9222" # 检测nginx进程是否存在 func ...
- linux外接显示屏,关掉本身的笔记本电脑
https://blog.csdn.net/a2020883119/article/details/79561035 先用xrandr命令查看: eDP-1 connected eDP-1是连接着的 ...
- ConcurrentHashMap中的putIfAbsent方法的使用以及返回值的含义
public V putIfAbsent(@NotNull K key, @NotNull V value) putIfAbsent方法主要是在向ConcurrentHashMap中添加键—值对的时候 ...