1

我尝试使用如下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);

这个bug出来了:

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 主页下载的 3.9.1 版本,我什至尝试了一些替代解决方案,但它们都不起作用。我试过:

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

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

4

1 回答 1

0

糟糕,我的错误...我的依赖项之一包括导致与 corenlp 发生冲突的 protobuf-lite ...非常感谢@GaborAngeli

于 2018-06-22T12:23:17.200 回答