我想知道是否有人可以帮助我 .

我正在使用stanford-corenlp 3.5.2 maven包从教程中运行OpenIEDemo .

我收到以下输出: -

添加注释器标记化TokenizerAnnotator:未提供标记器类型 . 默认为PTBTokenizer . 添加注释器ssplit添加注释器pos从edu / stanford读取POS标记器模型/ nlp / models / pos-tagger / english-left3words / english-left3words-distsim.tagger ...完成[1.5秒] . 添加注释引理添加注释器depparse加载depparse模型文件:edu / stanford / nlp / models / parser / nndep / english_UD.gz ... PreComputed 100000,Elapsed Time:1.451(s)初始化依赖性解析器已完成[4.7 sec] . 添加注释器解析从序列化文件加载解析器edu / stanford / nlp / models / lexparser / englishPCFG.ser.gz ...完成[2.2秒] . 添加注释器natlog添加注释器openie线程“main”中的异常java.lang.IllegalArgumentException:在edu.stanford.nlp.pipeline的edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:83)中没有名为openie的注释器 . StanfordCoreNLP.construct(StanfordCoreNLP.java:289)at edu.stanford.nlp.pipeline.StanfordCoreNLP . (StanfordCoreNLP.java:126)at edu.stanford.nlp.pipeline.StanfordCoreNLP . (StanfordCoreNLP.java:122)at com.test .OpenIEDemo.OpenIEDemo.main(OpenIEDemo.java:22)

代码是根据教程,但有例外

  • 我更改了包名 .

  • 我之前有一个错误,即解析注释器是natlog注释器的依赖项,因此将解析注释器添加到annotators属性中 .


package com.test.OpenIEDemo;

import edu.stanford.nlp.ie.util.RelationTriple;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.naturalli.*;
import edu.stanford.nlp.util.CoreMap;
import java.util.Collection;
import java.util.Properties;

/**
 * A demo illustrating how to call the OpenIE system programmatically.
 */

public class OpenIEDemo {

  public static void main(String[] args) throws Exception {
    // Create the Stanford CoreNLP pipeline
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,parse,natlog,openie");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

    // Annotate an example document.
    Annotation doc = new Annotation("Obama was born in Hawaii. He is our president.");
    pipeline.annotate(doc);

    // Loop over sentences in the document
    for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
      // Get the OpenIE triples for the sentence
      Collection<RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
      // Print the triples
      for (RelationTriple triple : triples) {
        System.out.println(triple.confidence + "\t" +
            triple.subjectLemmaGloss() + "\t" +
            triple.relationLemmaGloss() + "\t" +
            triple.objectLemmaGloss());
      }
    }
  }
}