ProtobufAnnotationSerializer的问题-Stanford CoreNLP

时间:2018-06-21 13:19:46

标签: java stanford-nlp protobuf-java

我尝试使用ProtobufAnnotationSerializer来序列化Annotation对象,如下所示:

String text = "Stanford University is located in California. It is a great university, founded in 1891.";
Annotation document = new Annotation(text);
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse,depparse");    
StanfordCoreNLP pip = new StanfordCoreNLP(props);
pip.annotate(document);

ProtobufAnnotationSerializer serializer = new ProtobufAnnotationSerializer();
FileOutputStream fileOut = new FileOutputStream("path/to/anno.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
serializer.write(document, out);

此错误出来了:

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    com/google/protobuf/GeneratedMessageV3$ExtendableMessage.getExtension(Lcom/google/protobuf/Extension;I)Ljava/lang/Object; @3: invokevirtual
  Reason:
    Type 'com/google/protobuf/Extension' (current frame, stack[1]) is not assignable to 'com/google/protobuf/ExtensionLite'
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'com/google/protobuf/GeneratedMessageV3$ExtendableMessage', 'com/google/protobuf/Extension', integer }
    stack: { 'com/google/protobuf/GeneratedMessageV3$ExtendableMessage', 'com/google/protobuf/Extension', integer }
  Bytecode:
    0x0000000: 2a2b 1cb6 0024 b0                      

    at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.toProtoBuilder(ProtobufAnnotationSerializer.java:611)
    at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.toProto(ProtobufAnnotationSerializer.java:579)
    at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.write(ProtobufAnnotationSerializer.java:184)
at xxxxxxxxxxxxxx.main(xxxxxxx.java:303)  \\ line: serializer.write(document, out);

我认为CoreNLP ProtobufAnnotationSerializer和protobuf软件包之间存在不一致。我使用的是直接从CoreNLP home page下载的3.9.1版本,我什至尝试了一些替代解决方案,但没有一个起作用。我尝试过:

  • 版本3.9 3.8
  • 直接从maven下载软件包及其依赖项
  • 在github上下载并构建(使用ant)源代码。

其他语言(我使用法语测试)也发生错误,甚至在调用服务器时也会发生错误。

1 个答案:

答案 0 :(得分:0)

糟糕!我的依赖项之一包括protobuf-lite,它引起与corenlp的冲突……非常感谢@GaborAngeli