Java 斯坦福NLP:检索SequenceMatchRules中操作的更新注释

Java 斯坦福NLP:检索SequenceMatchRules中操作的更新注释,java,stanford-nlp,Java,Stanford Nlp,我正在使用序列匹配规则作为Stanfords CoreNLP库中TokenRegex的一部分,并且在基于匹配规则中操作的评估检索更新的注释时遇到一些问题 rule = { type: "CLASS" , value: "edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation" { "ruleType":"tokens", "pattern": ( /This/ /should/ /match/ ) , "action

我正在使用序列匹配规则作为Stanfords CoreNLP库中TokenRegex的一部分,并且在基于匹配规则中操作的评估检索更新的注释时遇到一些问题

rule = { type: "CLASS" , value: "edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation" 

{  
   "ruleType":"tokens",
   "pattern": ( /This/ /should/ /match/ ) ,
   "action": (  Annotate($0, rule, "RetrieveThisValue" ) ),
   "result":"This is the result"
}
如何从带注释的coremap中检索值
“RetrieveThisValue”
。根据文档,我本以为可以从匹配的表达式CoreMap中检索值。当我使用类似于
matchedexpression.get(0).getAnnotation().get(CoreAnnotations.TokensAnnotation.class).toString()的内容时,我会得到结果字段“这是结果”,而不会得到“RetrieveThisValue”

我可以在MatchedExpression的extract函数中找到“RetrieveThisValue”


如何在匹配表达式时检索“RetrieveThisValue”

规则文件:this-should-match.Rules

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

{
   "pattern": ( /This/ /should/ /match/ ),
   "action": ( Annotate($0, ruleClass, "this should match!") ),
   "result": "This is the result!"
}
代码:


注意:我认为您不应该使用GoldAnswer注释,您可能应该创建一个全新的注释类来处理您的用例。但我只是举个例子。

谢谢。我会审查,如果有足够的奖励与答案。
package edu.stanford.nlp.examples;

import edu.stanford.nlp.util.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;

import java.util.*;


public class TokensRegexExampleTwo {

  public static void main(String[] args) {

    // set up properties
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,tokensregex");
    props.setProperty("tokensregex.rules", "this-should-match.rules");
    props.setProperty("tokensregex.caseInsensitive", "true");

    // set up pipeline
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

    // set up text to annotate
    Annotation annotation = new Annotation("This should match.");

    // annotate text
    pipeline.annotate(annotation);

    // print out found entities
    for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
      for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
        System.out.println(token.word() + "\t" +
            token.get(edu.stanford.nlp.ling.CoreAnnotations.GoldAnswerAnnotation.class));
      }
    }
  }
}