【发布时间】:2019-06-24 09:00:23
【问题描述】:
所以我正在使用斯坦福核心 nlp 库做一个关于 TokenRegex 模式匹配的示例。需要帮助将规则文件放置在适当的位置。尝试将其放在 src 文件夹中,但没有成功
代码:-
public static void main(String[] args) throws ClassNotFoundException
{
// set properties
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,tokensregex");
props.setProperty("tokensregex.rules", "basic_ner.rules");
props.setProperty("tokensregex.matchedExpressionsAnnotationKey","edu.stanford.nlp.examples.TokensRegexAnnotatorDemo$MyMatchedExpressionAnnotation");
// build pipeline
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// annotate
Annotation ann = new Annotation("There will be a big announcement by Apple Inc today at 5:00pm. " +
"She has worked at Miller Corp. for 5 years.");
pipeline.annotate(ann);
// show results
System.out.println("---");
System.out.println("tokens\n");
for (CoreMap sentence : ann.get(CoreAnnotations.SentencesAnnotation.class))
{
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class))
{
System.out.println(token.word() + "\t" + token.ner());
}
System.out.println("");
}
System.out.println("---");
System.out.println("matched expressions\n");
for (CoreMap me : ann.get(MyMatchedExpressionAnnotation.class))
{
System.out.println(me);
}
}
}
【问题讨论】:
标签: java eclipse stanford-nlp