我只是想運行一個簡單的例子來開始使用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