Java 规则文件应该位于EclipseIDE中的TokenRegex(StanfordCoreNLP)中的什么位置?
所以我用斯坦福核心nlp库做了一个关于TokenRegex模式匹配的例子。需要帮助将规则文件放置在适当的位置。尝试将其放置在src文件夹中,但无效 代码:-Java 规则文件应该位于EclipseIDE中的TokenRegex(StanfordCoreNLP)中的什么位置?,java,eclipse,stanford-nlp,Java,Eclipse,Stanford Nlp,所以我用斯坦福核心nlp库做了一个关于TokenRegex模式匹配的例子。需要帮助将规则文件放置在适当的位置。尝试将其放置在src文件夹中,但无效 代码:- public static void main(String[] args) throws ClassNotFoundException { // set properties Properties props = new Properties(); props.setProperty("annotators",
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);
}
}
}
我认为如果您将文件
基本规则
放在工作目录(不是“src”)中,它应该可以工作。您应该在Eclipse中找到默认的工作目录。我假设它只是整个项目的根目录。您也可以只放置规则文件的绝对路径。我认为,如果您将文件basic\u ner.rules
放在工作目录中(而不是“src”)应该可以工作。您应该在Eclipse中找到默认的工作目录。我假设它只是整个项目的根目录。您也可以只放置规则文件的绝对路径