gpt4 book ai didi

java - 规则文件应该位于 Eclipse IDE 中 TokenRegex(StanfordCoreNLP) 中的什么位置?

转载 作者:太空宇宙 更新时间:2023-11-04 09:34:02 24 4
gpt4 key购买 nike

所以我正在使用 stanford core 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);
}
}

}

Project Structure

最佳答案

我认为如果您将文件 basic_ner.rules 放在工作目录中(不会是“src”),它应该可以工作。您应该在 Eclipse 中找到默认工作目录。我假设它只是整个项目的根目录。您也可以只输入规则文件的绝对路径。

关于java - 规则文件应该位于 Eclipse IDE 中 TokenRegex(StanfordCoreNLP) 中的什么位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56733132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com