斯坦福NLP检测带有介词的复合实体



基本上,在句子中:

<Lord of the bracelets> is a fantasy movie.

我想将化合物Lord of the bracelets检测为一个实体(也可以在实体链接注释器中链接(。这意味着使用NNPDTNNPNNINDTNNP等形式的POS标签检测结构。

这在CoreNLP中可能吗?

我当前的设置无法检测到它们,并且我找不到一种方法来做到这一点。


public NamedEntityRecognition() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,entitylink");
props.setProperty("tokenize.options", "untokenizable=noneDelete");
pipeline = new StanfordCoreNLP(props);
}

public CoreDocument recogniseEntities(String text) {
CoreDocument doc = new CoreDocument(text);
pipeline.annotate(doc);
return doc;
}

谢谢!

你可以用TokensRegex来做到这一点(可能是RegexNER,尽管我不这么认为(。 您可以在规则中指定要将某些词性标记模式标记为实体。

TokensRegex的完整描述如下:

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

虽然@StanfordNLPHelp的回答很有帮助,但我想我会在我的最终解决方案中添加更多细节。

选项 1:

添加一个令牌正则表达式注释器,如上一个答案所指出的那样。这会向管道添加更可自定义的注释器,并且可以在文本文件中指定自己的规则。

这是我的规则文件 (extended_ner.rules( 的样子:

# these Java classes will be used by the rules
ner = { type: "CLASS", value: "edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation" }
tokens = { type: "CLASS", value: "edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation" }
# rule for recognizing compound names
{ ruleType: "tokens", pattern: ([{tag:"NN"}] [{tag:"IN"}] [{tag:"DT"}] [{tag:"NNP"}]), action: Annotate($0, ner, "COMPOUND"), result: "COMPOUND_RESULT" }

您可以在此处查看规则sintax的细分。

注意:令牌正则表达式注释器必须添加到 ner 注释器之后。否则,结果将被覆盖。

这是 Java 代码的样子:

public NamedEntityRecognition() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,tokensregex,entitylink");
props.setProperty("tokensregex.rules", "extended_ner.rules");
props.setProperty("tokenize.options", "untokenizable=noneDelete");
pipeline = new StanfordCoreNLP(props);
}

选项 2(已选择一项(

无需添加另一个注释器,规则文件可以通过 de"ner.additional.tokensregex.rules"属性发送到 ner 注释器。以下是文档。

我选择此选项是因为它看起来更简单,并且向管道添加另一个注释器对于我的情况似乎有点过头了。

规则文件与选项 1 中的完全相同,java 代码现在是:

public NamedEntityRecognition() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,entitylink");
props.setProperty("ner.additional.tokensregex.rules", "extended_ner.rules");
props.setProperty("tokenize.options", "untokenizable=noneDelete");
pipeline = new StanfordCoreNLP(props);
}

注意:要使此操作正常工作,属性"ner.applyFineGrained"必须为 true(默认值(。

最新更新