首页 > 解决方案 > 覆盖斯坦福 TokensRegex 的默认环境设置

问题描述

添加令牌正则表达式规则时edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation要 覆盖的设置是什么。edu.stanford.nlp.ling.CoreAnnotations$OriginalTextAnnotation

示例:

#123456在斯坦福大学被标记为 MONEY,因此为了超越 NER 行为,我编写了标记123456为 NUMBER 而不是 MONEY 的规则。作为副作用,以下£20.49现在被标记为 NUMBER。

我调试了代码并意识到应用模式时edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation用于匹配。因此,在什么情况下£20.49,输入£是 的值,edu.stanford.nlp.ling.CoreAnnotations$OriginalTextAnnotation并且#是 的值edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation

是否有环境设置来改变这种行为?

示例规则

# make all patterns case-sensitive
ENV.defaultStringMatchFlags = 0
ENV.defaultStringPatternFlags = 0

# 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" }

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

{ ruleType: "tokens", pattern: (([{word:"#"}]) ([{ner:"MONEY"}])), action: (Annotate($1, ner, "IGNORE"), Annotate($2, ner, "NUMBER"), Annotate($0, normalizedValue, "TOKENS_REGEX")), result: "NUMBER" }

标签: stanford-nlp

解决方案


您应该使用 GitHub 上的最新版本或版本 3.9.2。货币不再规范化,所以英镑符号将不再默认变成“#”。

你应该能够做类似的事情

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

然后你可以word在你的规则中替换为originalWord.


推荐阅读