加载标记模型时可能出错(可能缺少模型文件)

时间:2018-01-30 13:24:40

标签: eclipse stanford-nlp pos-tagger

我正在尝试实现以下代码:

import java.util.Properties;
import edu.stanford.nlp.coref.CorefCoreAnnotations;
import edu.stanford.nlp.coref.CorefCoreAnnotations;
import edu.stanford.nlp.coref.data.CorefChain;
import edu.stanford.nlp.coref.data.Mention;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;

public class CorefResolver {
  public static void main(String[] args) throws Exception {
  Annotation document = new Annotation("Barack Obama was born in Hawaii.  He is the president. Obama was elected in 2008.");
  Properties props = new Properties();
  props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,mention,coref");
  StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
  pipeline.annotate(document);
  System.out.println("---");
  System.out.println("coref chains");
  for (CorefChain cc : document.get(CorefCoreAnnotations.CorefChainAnnotation.class).values()) {
  System.out.println("\t" + cc);
  }
  for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
  System.out.println("---");
  System.out.println("mentions");
  for (Mention m : sentence.get(CorefCoreAnnotations.CorefMentionsAnnotation.class)) {
    System.out.println("\t" + m);
    }
  }
 }
}

这是来自stanford corenlp的代码。我使用eclipse作为框架。下图显示了eclipse中的视图。

enter image description here

运行代码时,我收到以下错误。我试过包括模型标记等。仍然显示相同的错误。

Adding annotator tokenize
No tokenizer type provided. Defaulting to PTBTokenizer.
Adding annotator ssplit
Adding annotator pos
Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Error while loading a tagger model (probably missing model file)
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:245)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:152)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:451)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:154)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:150)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:137)
at CorefResolver.main(CorefResolver.java:16)
Caused by: edu.stanford.nlp.io.RuntimeIOException: Error while loading a tagger model (probably missing model file)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:791)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:312)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:265)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:85)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:73)
at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(AnnotatorImplementations.java:63)
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:243)
... 6 more
Caused by: java.io.IOException: Unable to open "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as class path, filename or URL
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:470)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:789)
... 12 more

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

包括Stanford corenlp 3.8 jar和Stanford corenlp 3.8型号。现在共参考解决方案正在运作

enter image description here