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

问题描述 投票:0回答:1

我的目标是用PERSON实体注释科学文章中的作者姓名。我对与这种格式匹配的名称(作者名等日期)特别感兴趣。例如,我想对这句话(Minot et al。2000)=>注释Minot作为PERSON。我正在使用斯坦福大学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,而米诺特是CITY的,因为它是美国的城市之一,但在此特殊句子中,应使用作者的名字注释。

我尝试解决此问题的方法是将此行添加到我传递给corenlpclient的rgxrules.txt文件中。这是该文件中的这一行:

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

这不能解决您可以检查是否运行代码的问题。我也不知道该如何添加这样的事实,即我只想要与“ [[A-Z] [a-z]]”匹配的单词,且该单词早于et al。用PERSON注释,而不是整个句子“ Minot et al。”例如。

知道如何解决这个问题。

先谢谢您。

python regex stanford-nlp ner
1个回答
0
投票

关于匹配Java正则表达式,我很确定你想要类似的东西

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

但是,我不知道有什么方法可以避免将et al.标记为诸如令牌先行。如果然后在正则表达式文件中添加另一行以et al.替换O会发生什么情况?可能需要说PERSONO的允许覆盖

© www.soinside.com 2019 - 2024. All rights reserved.