gpt4 book ai didi

python - 使用 python 从文本中获取个人和组织名称的方法

转载 作者:行者123 更新时间:2023-11-30 23:26:34 25 4
gpt4 key购买 nike

我很好奇从文本中获取个人和组织名称的准确方法是什么。我想从文本中绘制基于伙伴关系等的隶属网络。

我尝试过几种方法:• 使用nltk POS - 运行速度太慢,所以我放弃了它• 使用正则表达式来匹配是否有第一个大写的连续单词。然而,这导致了很多异常(exception)和捕获,其中很多都不是很相关(例如,当有人随机大写“社会创新奖”时)。此外,这还漏掉了只有一个单词的名称。

其他人还有其他想法吗?

文本示例

obin Cardozo\r\n\r\nEd Greenspon\r\n\r\nFarouk Jiwa\r\n\r\nDavid Pecaut\r\n\r\nMartha 
Piper\r\n\r\nThe award was presented during the closing dinner of the Social
Entrepreneurship\r\nSummit held at MaRS Centre for Social Innovation in Toronto. The event
gathered\r\nover 250 business, academic and social thought leaders from the
social\r\nentrepreneurship sector in Canada who had convened for a full day of
inspiration\r\nand engagement on ways to address some of the most pressing issues of our

times.\r\n\r\nAn often under-recognized community, social entrepreneurs create and lead

an\r\norganization that are aimed at catalyzing systemic social change through new\r\nideas,

products, services, methodologies and changes in attitude.\r\n\r\nHosted in partnership by

MaRS Centre, The Boston Consulting Group (BCG), the\r\nCentre for Social Innovation and the Toronto City Summit Alliance, the Social\r\nEntrepreneurship Summit

最佳答案

首先清理您的数据:

>>> text = """obin Cardozo\r\n\r\nEd Greenspon\r\n\r\nFarouk Jiwa\r\n\r\nDavid Pecaut\r\n\r\nMartha Piper\r\n\r\nThe award was presented during the closing dinner of the Social Entrepreneurship\r\nSummit held at MaRS Centre for Social Innovation in Toronto. The event gathered\r\nover 250 business, academic and social thought leaders from the social\r\nentrepreneurship sector in Canada who had convened for a full day of inspiration\r\nand engagement on ways to address some of the most pressing issues of our times.\r\n\r\nAn often under-recognized community, social entrepreneurs create and lead an\r\norganization that are aimed at catalyzing systemic social change through new\r\nideas, products, services, methodologies and changes in attitude.\r\n\r\nHosted in partnership by MaRS Centre, The Boston Consulting Group (BCG), the\r\nCentre for Social Innovation and the Toronto City Summit Alliance, the Social\r\nEntrepreneurship Summit"""
>>> text = """obin Cardozo\r\n\r\nEd Greenspon\r\n\r\nFarouk Jiwa\r\n\r\nDavid Pecaut\r\n\r\nMartha Piper\r\n\r\nThe award was presented during the closing dinner of the Social Entrepreneurship\r\nSummit held at MaRS Centre for Social Innovation in Toronto. The event gathered\r\nover 250 business, academic and social thought leaders from the social\r\nentrepreneurship sector in Canada who had convened for a full day of inspiration\r\nand engagement on ways to address some of the most pressing issues of our times.\r\n\r\nAn often under-recognized community, social entrepreneurs create and lead an\r\norganization that are aimed at catalyzing systemic social change through new\r\nideas, products, services, methodologies and changes in attitude.\r\n\r\nHosted in partnership by MaRS Centre, The Boston Consulting Group (BCG), the\r\nCentre for Social Innovation and the Toronto City Summit Alliance, the Social\r\nEntrepreneurship Summit"""
>>> text = [i.replace('\r\n','').strip() for i in text.split('\r\n\r')]>>> text
['obin Cardozo', 'Ed Greenspon', 'Farouk Jiwa', 'David Pecaut', 'Martha Piper', 'The award was presented during the closing dinner of the Social EntrepreneurshipSummit held at MaRS Centre for Social Innovation in Toronto. The event gatheredover 250 business, academic and social thought leaders from the socialentrepreneurship sector in Canada who had convened for a full day of inspirationand engagement on ways to address some of the most pressing issues of our times.', 'An often under-recognized community, social entrepreneurs create and lead anorganization that are aimed at catalyzing systemic social change through newideas, products, services, methodologies and changes in attitude.', 'Hosted in partnership by MaRS Centre, The Boston Consulting Group (BCG), theCentre for Social Innovation and the Toronto City Summit Alliance, the SocialEntrepreneurship Summit']

然后您将需要一个完整的名称实体识别器,尝试以 NLTK ne_chunk 作为起点,然后转向更“最先进”的 NER 识别器:

from nltk import sent_tokenize, word_tokenize, pos_tag
from nltk.tree import Tree
from nltk import batch_ne_chunk as bnc
chunked_text = [[bnc(pos_tag(word_tokenize(j)) for j in sent_tokenize(i))] for i in text]

关于python - 使用 python 从文本中获取个人和组织名称的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22444215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com