[英]Issue with ProtobufAnnotationSerializer - Stanford CoreNLP
I tried to use ProtobufAnnotationSerializer
to serialize an Annotation
object as follow: 我尝试使用
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);
This bug came 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);
I think that there is an inconsistency between CoreNLP ProtobufAnnotationSerializer and protobuf package. 我认为CoreNLP ProtobufAnnotationSerializer与protobuf软件包之间存在不一致。 I am using version 3.9.1 downloaded directly from CoreNLP home page , and I even tried some alternative solutions but none of them work.
我正在使用直接从CoreNLP主页下载的3.9.1版本,我什至尝试了一些替代解决方案,但没有一个起作用。 I tried:
我试过了:
The error occurs with other languages (i tested with French) and even when calling the server. 其他语言(我使用法语测试)甚至在调用服务器时也会发生错误。
糟糕!我的依赖...我的依赖项之一包括protobuf-lite,它与corenlp发生冲突...非常感谢@GaborAngeli
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.