named-entity-recognition - TokensregexNER 应该使用哪些设置

标签 named-entity-recognition stanford-nlp

当我尝试 regexner 时,它按预期使用以下设置和数据工作;

props.setProperty("annotators", "tokenize, cleanxml, ssplit, pos, lemma, regexner");

Bachelor of Laws DEGREE
Bachelor of (Arts|Laws|Science|Engineering|Divinity) DEGREE

我想做的是使用 TokenRegex。例如

Bachelor of Laws DEGREE
Bachelor of ([{tag:NNS}] [{tag:NNP}]) DEGREE

我读到要做到这一点,我应该使用 TokensregexNERAnnotator。

我尝试如下使用它,但是没有用。

Pipeline.addAnnotator(new TokensRegexNERAnnotator("expressions.txt", true));

或者我尝试以另一种方式设置注释器,

props.setProperty("annotators", "tokenize, cleanxml, ssplit, pos, lemma, tokenregexner");    
props.setProperty("customAnnotatorClass.tokenregexner", "edu.stanford.nlp.pipeline.TokensRegexNERAnnotator");

我尝试了不同的 TokenRegex 格式,但要么注释器找不到表达式,要么出现 SyntaxException。

在 NER 数据文件上使用 TokenRegex(查询带标签的 token )的正确方法是什么?

顺便说一句,我刚刚在 TokensRegexNERAnnotator.java 文件中看到一条评论。不确定是不是相关的 pos 标签不适用于 RegexNerAnnotator。

if (entry.tokensRegex != null) {
    // TODO: posTagPatterns...
    pattern = TokenSequencePattern.compile(env, entry.tokensRegex);
  }

最佳答案

首先您需要制作一个 TokensRegex 规则文件 (sample_degree.rules)。这是一个例子:

ner = { type: "CLASS", value: "edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation" }

{ pattern: (/Bachelor/ /of/ [{tag:NNP}]), action: Annotate($0, ner, "DEGREE") }

为了解释一下规则,pattern 字段指定要匹配的模式类型。 action 字段是说注释整个匹配中的每个标记(即 $0 代表的),注释 ner 字段(注意我们在规则文件中也指定了 ner = ...,第三个参数表示将字段设置为字符串“DEGREE”)。

然后为命令制作这个 .props 文件 (degree_example.props):

customAnnotatorClass.tokensregex = edu.stanford.nlp.pipeline.TokensRegexAnnotator

tokensregex.rules = sample_degree.rules

annotators = tokenize,ssplit,pos,lemma,ner,tokensregex

然后运行这个命令:

java -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLP -props degree_example.props -file sample-degree-sentence.txt -outputFormat text

您应该看到您想要标记为“DEGREE”的三个标记将被标记。

我想我会对代码进行更改,使 tokensregex 链接到 TokensRegexAnnotator,这样您就不必将其指定为自定义注释器。 但现在您需要在 .props 文件中添加该行。

这个例子应该有助于实现这一点。如果您想了解更多信息,这里有更多资源:

http://nlp.stanford.edu/software/tokensregex.shtml#TokensRegexRules

http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/ling/tokensregex/SequenceMatchRules.html

http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/ling/tokensregex/types/Expressions.html

关于named-entity-recognition - TokensregexNER 应该使用哪些设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42470843/

相关文章:

java - 使用 Stanford 命名实体识别器时如何包含多个分类器?

java - 如何从斯坦福解析器的输出中提取名词及其相应的形容词

nlp - 是否有一个相当准确的启发式方法来检测英语句子的主语和宾语?

python - 用于命名实体识别的 PyTorch Huggingface BERT-NLP

python - python NLTK中使用StanfordNER识别NE的问题

java - 如何在 OpenNLP 中通过 NER 识别印度名字?

nlp - 如何在 NLP 中找到相似的名词短语?

python - NLTK 无法找到 java 文件!用于斯坦福 POS 标记器

text - NLP 寻找实体之间的关系

algorithm - 地理标记或地理标记文本内容的方法