使用stanfordnlp库中的REGEXNER注释作者姓名

2024-05-13 12:00:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是用实体PERSON注释科学文章中的作者姓名。 我对符合这种格式的名称特别感兴趣(authorname等人,date)。 例如,我希望这句话(Minot等人,2000)=>;将Minot注释为一个人。 我正在使用斯坦福nlp团队官方页面中的代码的改编版本:

import stanfordnlp

from stanfordnlp.server import CoreNLPClient
# example text
print('---')
print('input text')
print('')

text = "In practice, its scope is broad and includes the analysis of a diverse set of samples such as gut microbiome (Qin et al., 2010), (Minot et al., 2011), environmental (Mizuno et al., 2013) or clinical (Willner et al., 2009), (Negredo et al., 2011), (McMullan et al., 2012) samples."

# set up the client
print('---')
print('starting up Java Stanford CoreNLP Server...')
#Properties dictionary
prop={'regexner.mapping': 'rgxrules.txt', 'annotators': 'tokenize,ssplit,pos,lemma,ner,regexner'}
# set up the client


with CoreNLPClient(properties=prop,timeout=100000, memory='16G',be_quiet=False ) as client:
    # submit the request to the server
    ann = client.annotate(text)
    # get the first sentence
    sentence = ann.sentence[0]

运行代码后,我得到以下误报和误报: 内格罗多不是用PERSON来注释的,而是用O和Minot来注释的,因为它是美国的城市之一,但在这句话中,它应该用作者的名字来注释

我试图解决这个问题,是将这一行添加到我传递给corenlpclient的rgxrules.txt文件中。以下是我在此文件中的行:

[[A-Z][a-z]] /et/ /al\./\tPERSON

这并不能解决您可以检查是否运行代码的问题。此外,我不知道如何添加这样一个事实,即我只希望与“[[A-Z][A-Z]]”匹配的单词(位于et al.之前)用PERSON注释,而不是整个句子“Minot et al.”

你知道我怎么解决这个问题吗

先谢谢你


Tags: the代码textimportclientserversentenceet
1条回答
网友
1楼 · 发布于 2024-05-13 12:00:15

在匹配java正则表达式方面,我很确定您希望

[A-Za-z]+ et al[.]

但是,我不知道有什么方法可以避免标记et al.,比如使用令牌前瞻。如果在regex文件中添加另一行,将et al.替换为O,会发生什么情况?可能需要说PERSONO允许的覆盖

相关问题 更多 >