【问题标题】:Where should the rules file be located in TokenRegex(StanfordCoreNLP) in Eclipse IDE?规则文件应该位于 Eclipse IDE 的 TokenRegex(StanfordCoreNLP) 中的什么位置?
【发布时间】: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);
    }
}

}

Project Structure

【问题讨论】:

    标签: java eclipse stanford-nlp


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 2012-08-10
      • 2019-10-31
      • 1970-01-01
      • 2016-09-21
      • 1970-01-01
      • 2014-07-31
      相关资源
      最近更新 更多