所以我试着用斯坦福的CoreNLP编写一个非常简单的程序,但是在获得StreamCorruptedException之前我还没有走得太远。我正在使用Scala,但我认为这不应该有所作为。
以下是代码:
object Hello {
def main(args: Array[String]) {
val str = "The dog went to the park."
val props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, depparse");
val pipeline = new StanfordCoreNLP(props);
// more to be added
}
}
当我尝试运行此代码(sbt run)时,出现以下错误:
Caused by: java.io.StreamCorruptedException: invalid stream header: 54686973
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:806)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299)
at edu.stanford.nlp.tagger.maxent.TaggerConfig.readConfig(TaggerConfig.java:748)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:803)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:766)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:297)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:262)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:97)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:77)
at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(AnnotatorImplementations.java:57)
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:276)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:289)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:126)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:122)
at Hello$.main(Hello.scala:13)
at Hello.main(Hello.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
有什么想法吗?
谢谢!
答案 0 :(得分:3)
很可能你没有模型而且CoreNLP无法加载它们。要运行CoreNLP,您需要同时拥有stanford-corenlp-3.5.0.jar
和stanford-corenlp-3.5.0-models.jar
。两者都应该添加到构建路径中。