我只是想运行一个简单的例子来开始使用CoreNLP从here。我已经将coreNLP和模型3.6添加到我的pom.xml中。我也为我的pom添加了com.google.protobuf(3.0.0-beta-3)。斯坦福CoreNLP简单API错误
这是我的代码如下所示:
Document doc = new Document("add your text here! It can contain multiple sentences.");
for (Sentence sent : doc.sentences()) { // Will iterate over two sentences
// We're only asking for words -- no need to load any models yet
System.out.println("The second word of the sentence '" + sent + "' is " + sent.word(1));
// When we ask for the lemma, it will load and run the part of speech tagger
System.out.println("The third lemma of the sentence '" + sent + "' is " + sent.lemma(2));
// When we ask for the parse, it will load and run the parser
System.out.println("The parse of the sentence '" + sent + "' is " + sent.parse());
// ...
}
而这里的例外:
java.lang.NoSuchMethodError: edu.stanford.nlp.util.ArrayCoreMap.keySetNotNull()Ljava/util/Set; at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.toProtoBuilder(ProtobufAnnotationSerializer.java:377) at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.toProtoBuilder(ProtobufAnnotationSerializer.java:332) at edu.stanford.nlp.simple.Document.sentences(Document.java:480) at edu.stanford.nlp.simple.Document.sentences(Document.java:499)
UPDATE:
我刚刚降级的protobuf到2.6.1,仍然同样的问题。在这里,我的pom看起来像:
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.6.0</version>
<classifier>models</classifier>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
我刚刚用2.6.1试过,仍然出现同样的错误 – webber
也许试试清除你的本地maven缓存? –
你的例子说的是“2.6.0”而不是“2.6.1”......同样重要的是你使用2.6.1,并确保没有别的东西拉动protobuf的不同版本,因为它不会与其他版本一起工作。 .. @ gabor顺便说一句我用2.5回去试了一下,我认为它失败了,所以我认为它的关键是使用2.6.1,不积极,虽然... – StanfordNLPHelp