python识别中文人名_使用Python在NLP中的命名实体识别中提取人名
我有一句话,我需要单独识别人名:
例如:
sentence = "Larry Page is an American business magnate and computer scientist who is the co-founder of Google, alongside Sergey Brin"
我使用下面的代码来识别NER.
from nltk import word_tokenize, pos_tag, ne_chunk
print(ne_chunk(pos_tag(word_tokenize(sentence))))
我收到的输出是:
(S
(PERSON Larry/NNP)
(ORGANIZATION Page/NNP)
is/VBZ
an/DT
(GPE American/JJ)
business/NN
magnate/NN
and/CC
computer/NN
scientist/NN
who/WP
is/VBZ
the/DT
co-founder/NN
of/IN
(GPE Google/NNP)
,/,
alongside/RB
(PERSON Sergey/NNP Brin/NNP))
我想提取所有人名,例如
Larry Page
Sergey Brin
为了达到这个目的,我对这个link进行了测试并尝试了这一点.
from nltk.tag.stanford import StanfordNERTagger
st = StanfordNERTagger('/usr/share/stanford-ner/classifiers/english.all.3class.distsim.crf.ser.gz','/usr/share/stanford-ner/stanford-ner.jar')
但是我继续得到这个错误:
LookupError: Could not find stanford-ner.jar jar file at /usr/share/stanford-ner/stanford-ner.jar
我在哪里可以下载这个文件?
如上所述,我期望以列表或字典的形式出现的结果是:
Larry Page
Sergey Brin
最佳答案 在龙
请仔细阅读:
了解解决方案,不要只是复制和粘贴.
TL; DR
在终端:
pip install -U nltk
wget http://nlp.stanford.edu/software/stanford-corenlp-full-2016-10-31.zip
unzip stanford-corenlp-full-2016-10-31.zip && cd stanford-corenlp-full-2016-10-31
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer \
-preload tokenize,ssplit,pos,lemma,parse,depparse \
-status_port 9000 -port 9000 -timeout 15000
在Python中
from nltk.tag.stanford import CoreNLPNERTagger
def get_continuous_chunks(tagged_sent):
continuous_chunk = []
current_chunk = []
for token, tag in tagged_sent:
if tag != "O":
current_chunk.append((token, tag))
else:
if current_chunk: # if the current chunk is not empty
continuous_chunk.append(current_chunk)
current_chunk = []
# Flush the final current_chunk into the continuous_chunk, if any.
if current_chunk:
continuous_chunk.append(current_chunk)
return continuous_chunk
stner = CoreNLPNERTagger()
tagged_sent = stner.tag('Rami Eid is studying at Stony Brook University in NY'.split())
named_entities = get_continuous_chunks(tagged_sent)
named_entities_str_tag = [(" ".join([token for token, tag in ne]), ne[0][1]) for ne in named_entities]
print(named_entities_str_tag)
[OUT]:
[('Rami Eid', 'PERSON'), ('Stony Brook University', 'ORGANIZATION'), ('NY', 'LOCATION')]
python识别中文人名_使用Python在NLP中的命名实体识别中提取人名相关推荐
- Python深度学习-NLP实战:命名实体识别(NER)之分词与序列标注、实体识别任务简介
系列文章目录 Python深度学习-NLP实战:深度学习系列培训教程 Linux服务器软件的简单使用 Linux命令的简单使用 训练集.测试集.验证集的介绍及制作 字向量的训练与生成 文本分类之SVM ...
- 实体对齐 算法_中英命名实体识别及对齐中的中文分词优化 论文笔记
1.计算命名实体词汇对齐的置信度:对一个中英双语句对,中文在初始分词的基础上进行命名实体识别. 2.分词工具:采用中科院分词工具ICTCLAS.Stanford分词工具对中文句子进行分词,其中Stan ...
- 【NLP】BiLSTM 命名实体识别 手写代码
[参考:pytorch_BiLSTM 命名实体识别 手写代码_哔哩哔哩_bilibili] [参考:shouxieai/nlp-bilstm_crf-ner: nlp-bilstm+crf-ner] ...
- python统计中文字符_使用 Python 统计中文字符的数量
使用 Python 统计中文字符的数量 方法一,排除法 假设只有中英文字符: import string def str_count(str): '''找出字符串中的中英文.空格.数字.标点符号个数' ...
- python打开中文文件名_解决python打开中文文件名乱码的问题
解决python打开中文文件名乱码的问题 发布时间:2020-07-27 11:20:22 来源:亿速云 阅读:162 作者:清晨 小编给大家分享一下解决python打开中文文件名乱码的问题,相信大部 ...
- python打开中文文件名_[请教]python的中文文件名处理
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 3 楼的可以用 sys.getfilesystemencoding 检测,但由於文件系统的差异,文件名 100% 无损转还是不太可,比如很多 *nix 的 ...
- python处理中文字符串_处理python字符串中的中文字符
# -*- coding:utf-8 -*- import sys,os txta = open('a.txt','r') str = '' for line in txta: str += line ...
- python爬虫中文乱码_解决Python爬虫处理文件时候中文名称出现乱码问题
当下如果需要批量处理文件,爬虫网页和图片的时候使用Python是最为简单和高效的.但是在处理过程中还是有一些细节问题,比如在爬虫中文名称和处理中文文件URL的时候会出现乱码.实际上就是因为编码的问题. ...
- python支持中文路径_打开python遍历中文目录得到的文件路径报错
各位朋友们好,我是一名python新手,现在遇到一个问题,恳请各位朋友们能指点一下我. 我的环境是:ubuntu14.04系统,python2.7 用python遍历一个目录,目录层次结构如下: 这是 ...
最新文章
- github pages_使用GitHub Pages和Lighthouse增强您的开发人员产品组合
- BaaS后端即服务 - 分析篇
- 如果编程语言是超级英雄……
- myeclipse连接mysql怎么调用_myeclipse连接mysql数据库详细步骤
- Linux驱动程序的数据封装
- C#的多线程机制探索3
- php 初始化model,TP5 model类研究
- Hutool:时间日期工具
- c语言实验分支程序设计二,C语言程序实验报告分支结构的程序设计(0页).doc
- 代的划分是根据计算机的运算速度来划分,计算机的发展经历了四代,代的划分是根据计算机的运算速度来划分....
- 专门为某种用途而设计的计算机 称为,专门为某种用途而设计的计算机,称为计算机...
- iphone4 通讯录数据库文件!
- easyui酷黑风格主题模板组件html
- Robo 3T 使用教程
- Ubuntu 14.04安装 skype
- 原来没有网络也能扫码支付,都是因为它啊!
- Keras和TensorFlow的安装配置
- python爬虫实例网易云-Python3爬虫实例之网易云音乐爬虫
- 【手绘漫画】图解LeetCode之旋转链表(LeetCode 61题)
- 可见的轮廓线用虚线绘制_绘制视图时,可见的轮廓线用粗实线绘制,不可见的轮廓线用细虚线绘制 答案:√...