Я использую правила сопоставления последовательности как часть TokenRegex в библиотеке Stanfords CoreNLP, и у меня возникают некоторые проблемы с получением обновленной аннотации на основе оценки действия в правилах сопоставления.
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"
}
Как мне получить значение "RetrieveThisValue"
из аннотированной карты ядра. Согласно документам здесь, я бы подумал, что могу получить значение из согласованного выражения CoreMap. Когда я использую что-то вроде matchedexpression.get(0).getAnnotation().get(CoreAnnotations.TokensAnnotation.class).toString()
, я получаю поле результатов «Это результат», и я также не получаю «RetrieveThisValue».
Я могу найти «RetrieveThisValue» глубоко в функции извлечения MatchedExpression.
Как мне получить 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!"
}
Код:
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));
}
}
}
}
ПРИМЕЧАНИЕ. Я не думаю, что вам следует использовать аннотацию GoldAnswer, вам, вероятно, следует создать новый класс аннотаций для обработки вашего варианта использования. Но я просто использовал это как пример.
Спасибо. Я рассмотрю и при наличии достаточного вознаграждения с ответом.