首页 > 解决方案 > 实体提及检测无法与 TokensRegex 一起正常工作

问题描述

entitymention 似乎不起作用。我遵循了此处提到的类似方法,将其添加entitymentionsannotators

如何使用 CoreNLP 的 RegexNER 检测超过 1 个单词的命名实体?

输入:“这是你的 24 美元”

我有一个 TokensRegex:

{ ruleType: "tokens", pattern: ([{ner:"NUMBER"}] + [{word:"USD"}]), action: Annotate($0, ner, "NEW_MONEY"), result: "NEW_MONEY_RESULT" }

初始化管道:

props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,tokensregex,entitymentions");
props.setProperty("tokensregex.rules", "basic_ner.rules");

我仍然有 2 个 CoreEntityMention 而不是只有 1 个。

它们都具有相同的值,edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotationNEW_MONEY

但他们有不同的 edu.stanford.nlp.ling.CoreAnnotations$EntityMentionIndexAnnotation

这是0为了24

1为了USD

由于它们都具有相同的实体标签注释,它们如何合并。

3.9.2使用斯坦福图书馆的版本。

标签: stanford-nlp

解决方案


问题是数字具有标准化的名称实体标签。

这是一个可以使用的规则文件:

# these Java classes will be used by the rules
ner = { type: "CLASS", value: "edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation" }
normNER = { type: "CLASS", value: "edu.stanford.nlp.ling.CoreAnnotations$NormalizedNamedEntityTagAnnotation" }
tokens = { type: "CLASS", value: "edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation" }

# rule for recognizing company names
{ ruleType: "tokens", pattern: ([{ner:"NUMBER"}] [{word:"USD"}]), action: (Annotate($0, ner, "NEW_MONEY"), Annotate($0, normNER, "NEW_MONEY")), result: "NEW_MONEY" }

您不应该在最后添加额外的tokensregex注释器和entitymentions注释器。注释器会将这些ner作为子注释器运行。

这是一个示例命令:

java -Xmx10g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner -ner.additional.tokensregex.rules new_money.rules -file new_money_example.txt -outputFormat text

更多文档在这里:

https://stanfordnlp.github.io/CoreNLP/tokensregex.html

https://stanfordnlp.github.io/CoreNLP/ner.html


推荐阅读