ccg_nlpy.protobuf.TextAnnotation_pb2 module
# Generated by the protocol buffer compiler. DO NOT EDIT! # source: protobuf/TextAnnotation.proto import sys _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database from google.protobuf import descriptor_pb2 # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() DESCRIPTOR = _descriptor.FileDescriptor( name='protobuf/TextAnnotation.proto', package='textannotation', syntax='proto2', serialized_pb=_b('\n\x1dprotobuf/TextAnnotation.proto\x12\x0etextannotation\"\xe2\x02\n\x13TextAnnotationProto\x12\x10\n\x08\x63orpusId\x18\x01 \x02(\t\x12\n\n\x02id\x18\x02 \x02(\t\x12\x0c\n\x04text\x18\x03 \x02(\t\x12\x0e\n\x06tokens\x18\x04 \x03(\t\x12\x37\n\x0ctokenOffsets\x18\x05 \x03(\x0b\x32!.textannotation.TokenOffsetsProto\x12\x30\n\tsentences\x18\x06 \x02(\x0b\x32\x1d.textannotation.SentenceProto\x12(\n\x05views\x18\x07 \x03(\x0b\x32\x19.textannotation.ViewProto\x12G\n\nproperties\x18\x08 \x03(\x0b\x32\x33.textannotation.TextAnnotationProto.PropertiesEntry\x1a\x31\n\x0fPropertiesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"Q\n\x11TokenOffsetsProto\x12\x0c\n\x04\x66orm\x18\x01 \x02(\t\x12\x17\n\x0fstartCharOffset\x18\x02 \x02(\x05\x12\x15\n\rendCharOffset\x18\x03 \x02(\x05\"R\n\rSentenceProto\x12\x11\n\tgenerator\x18\x01 \x02(\t\x12\x10\n\x05score\x18\x02 \x01(\x01:\x01\x30\x12\x1c\n\x14sentenceEndPositions\x18\x03 \x03(\x05\"N\n\tViewProto\x12\x10\n\x08viewName\x18\x01 \x02(\t\x12/\n\x08viewData\x18\x02 \x03(\x0b\x32\x1d.textannotation.ViewDataProto\"\xc2\x01\n\rViewDataProto\x12\x10\n\x08viewType\x18\x01 \x02(\t\x12\x10\n\x08viewName\x18\x02 \x02(\t\x12\x11\n\tgenerator\x18\x03 \x02(\t\x12\x10\n\x05score\x18\x04 \x01(\x01:\x01\x30\x12\x36\n\x0c\x63onstituents\x18\x05 \x03(\x0b\x32 .textannotation.ConstituentProto\x12\x30\n\trelations\x18\x06 \x03(\x0b\x32\x1d.textannotation.RelationProto\"\xca\x02\n\x10\x43onstituentProto\x12\r\n\x05label\x18\x01 \x02(\t\x12\x10\n\x05score\x18\x02 \x01(\x01:\x01\x30\x12\r\n\x05start\x18\x03 \x02(\x05\x12\x0b\n\x03\x65nd\x18\x04 \x02(\x05\x12\x44\n\nproperties\x18\x05 \x03(\x0b\x32\x30.textannotation.ConstituentProto.PropertiesEntry\x12J\n\rlabelScoreMap\x18\x06 \x03(\x0b\x32\x33.textannotation.ConstituentProto.LabelScoreMapEntry\x1a\x31\n\x0fPropertiesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x34\n\x12LabelScoreMapEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x01:\x02\x38\x01\"\xdf\x02\n\rRelationProto\x12\x14\n\x0crelationName\x18\x01 \x02(\t\x12\x10\n\x05score\x18\x02 \x01(\x01:\x01\x30\x12\x16\n\x0esrcConstituent\x18\x03 \x02(\x05\x12\x19\n\x11targetConstituent\x18\x04 \x02(\x05\x12\x41\n\nproperties\x18\x05 \x03(\x0b\x32-.textannotation.RelationProto.PropertiesEntry\x12G\n\rlabelScoreMap\x18\x06 \x03(\x0b\x32\x30.textannotation.RelationProto.LabelScoreMapEntry\x1a\x31\n\x0fPropertiesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x34\n\x12LabelScoreMapEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x01:\x02\x38\x01\x42G\n/edu.illinois.cs.cogcomp.core.utilities.protobufB\x12TextAnnotationImplP\x00') ) _sym_db.RegisterFileDescriptor(DESCRIPTOR) _TEXTANNOTATIONPROTO_PROPERTIESENTRY = _descriptor.Descriptor( name='PropertiesEntry', full_name='textannotation.TextAnnotationProto.PropertiesEntry', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='key', full_name='textannotation.TextAnnotationProto.PropertiesEntry.key', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='value', full_name='textannotation.TextAnnotationProto.PropertiesEntry.value', index=1, number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=355, serialized_end=404, ) _TEXTANNOTATIONPROTO = _descriptor.Descriptor( name='TextAnnotationProto', full_name='textannotation.TextAnnotationProto', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='corpusId', full_name='textannotation.TextAnnotationProto.corpusId', index=0, number=1, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='id', full_name='textannotation.TextAnnotationProto.id', index=1, number=2, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='text', full_name='textannotation.TextAnnotationProto.text', index=2, number=3, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='tokens', full_name='textannotation.TextAnnotationProto.tokens', index=3, number=4, type=9, cpp_type=9, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='tokenOffsets', full_name='textannotation.TextAnnotationProto.tokenOffsets', index=4, number=5, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='sentences', full_name='textannotation.TextAnnotationProto.sentences', index=5, number=6, type=11, cpp_type=10, label=2, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='views', full_name='textannotation.TextAnnotationProto.views', index=6, number=7, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='properties', full_name='textannotation.TextAnnotationProto.properties', index=7, number=8, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[_TEXTANNOTATIONPROTO_PROPERTIESENTRY, ], enum_types=[ ], options=None, is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=50, serialized_end=404, ) _TOKENOFFSETSPROTO = _descriptor.Descriptor( name='TokenOffsetsProto', full_name='textannotation.TokenOffsetsProto', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='form', full_name='textannotation.TokenOffsetsProto.form', index=0, number=1, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='startCharOffset', full_name='textannotation.TokenOffsetsProto.startCharOffset', index=1, number=2, type=5, cpp_type=1, label=2, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='endCharOffset', full_name='textannotation.TokenOffsetsProto.endCharOffset', index=2, number=3, type=5, cpp_type=1, label=2, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=None, is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=406, serialized_end=487, ) _SENTENCEPROTO = _descriptor.Descriptor( name='SentenceProto', full_name='textannotation.SentenceProto', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='generator', full_name='textannotation.SentenceProto.generator', index=0, number=1, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='score', full_name='textannotation.SentenceProto.score', index=1, number=2, type=1, cpp_type=5, label=1, has_default_value=True, default_value=float(0), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='sentenceEndPositions', full_name='textannotation.SentenceProto.sentenceEndPositions', index=2, number=3, type=5, cpp_type=1, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=None, is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=489, serialized_end=571, ) _VIEWPROTO = _descriptor.Descriptor( name='ViewProto', full_name='textannotation.ViewProto', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='viewName', full_name='textannotation.ViewProto.viewName', index=0, number=1, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='viewData', full_name='textannotation.ViewProto.viewData', index=1, number=2, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=None, is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=573, serialized_end=651, ) _VIEWDATAPROTO = _descriptor.Descriptor( name='ViewDataProto', full_name='textannotation.ViewDataProto', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='viewType', full_name='textannotation.ViewDataProto.viewType', index=0, number=1, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='viewName', full_name='textannotation.ViewDataProto.viewName', index=1, number=2, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='generator', full_name='textannotation.ViewDataProto.generator', index=2, number=3, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='score', full_name='textannotation.ViewDataProto.score', index=3, number=4, type=1, cpp_type=5, label=1, has_default_value=True, default_value=float(0), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='constituents', full_name='textannotation.ViewDataProto.constituents', index=4, number=5, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='relations', full_name='textannotation.ViewDataProto.relations', index=5, number=6, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=None, is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=654, serialized_end=848, ) _CONSTITUENTPROTO_PROPERTIESENTRY = _descriptor.Descriptor( name='PropertiesEntry', full_name='textannotation.ConstituentProto.PropertiesEntry', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='key', full_name='textannotation.ConstituentProto.PropertiesEntry.key', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='value', full_name='textannotation.ConstituentProto.PropertiesEntry.value', index=1, number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=355, serialized_end=404, ) _CONSTITUENTPROTO_LABELSCOREMAPENTRY = _descriptor.Descriptor( name='LabelScoreMapEntry', full_name='textannotation.ConstituentProto.LabelScoreMapEntry', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='key', full_name='textannotation.ConstituentProto.LabelScoreMapEntry.key', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='value', full_name='textannotation.ConstituentProto.LabelScoreMapEntry.value', index=1, number=2, type=1, cpp_type=5, label=1, has_default_value=False, default_value=float(0), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=1129, serialized_end=1181, ) _CONSTITUENTPROTO = _descriptor.Descriptor( name='ConstituentProto', full_name='textannotation.ConstituentProto', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='label', full_name='textannotation.ConstituentProto.label', index=0, number=1, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='score', full_name='textannotation.ConstituentProto.score', index=1, number=2, type=1, cpp_type=5, label=1, has_default_value=True, default_value=float(0), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='start', full_name='textannotation.ConstituentProto.start', index=2, number=3, type=5, cpp_type=1, label=2, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='end', full_name='textannotation.ConstituentProto.end', index=3, number=4, type=5, cpp_type=1, label=2, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='properties', full_name='textannotation.ConstituentProto.properties', index=4, number=5, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='labelScoreMap', full_name='textannotation.ConstituentProto.labelScoreMap', index=5, number=6, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[_CONSTITUENTPROTO_PROPERTIESENTRY, _CONSTITUENTPROTO_LABELSCOREMAPENTRY, ], enum_types=[ ], options=None, is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=851, serialized_end=1181, ) _RELATIONPROTO_PROPERTIESENTRY = _descriptor.Descriptor( name='PropertiesEntry', full_name='textannotation.RelationProto.PropertiesEntry', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='key', full_name='textannotation.RelationProto.PropertiesEntry.key', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='value', full_name='textannotation.RelationProto.PropertiesEntry.value', index=1, number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=355, serialized_end=404, ) _RELATIONPROTO_LABELSCOREMAPENTRY = _descriptor.Descriptor( name='LabelScoreMapEntry', full_name='textannotation.RelationProto.LabelScoreMapEntry', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='key', full_name='textannotation.RelationProto.LabelScoreMapEntry.key', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='value', full_name='textannotation.RelationProto.LabelScoreMapEntry.value', index=1, number=2, type=1, cpp_type=5, label=1, has_default_value=False, default_value=float(0), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=1129, serialized_end=1181, ) _RELATIONPROTO = _descriptor.Descriptor( name='RelationProto', full_name='textannotation.RelationProto', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='relationName', full_name='textannotation.RelationProto.relationName', index=0, number=1, type=9, cpp_type=9, label=2, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='score', full_name='textannotation.RelationProto.score', index=1, number=2, type=1, cpp_type=5, label=1, has_default_value=True, default_value=float(0), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='srcConstituent', full_name='textannotation.RelationProto.srcConstituent', index=2, number=3, type=5, cpp_type=1, label=2, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='targetConstituent', full_name='textannotation.RelationProto.targetConstituent', index=3, number=4, type=5, cpp_type=1, label=2, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='properties', full_name='textannotation.RelationProto.properties', index=4, number=5, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='labelScoreMap', full_name='textannotation.RelationProto.labelScoreMap', index=5, number=6, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[_RELATIONPROTO_PROPERTIESENTRY, _RELATIONPROTO_LABELSCOREMAPENTRY, ], enum_types=[ ], options=None, is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=1184, serialized_end=1535, ) _TEXTANNOTATIONPROTO_PROPERTIESENTRY.containing_type = _TEXTANNOTATIONPROTO _TEXTANNOTATIONPROTO.fields_by_name['tokenOffsets'].message_type = _TOKENOFFSETSPROTO _TEXTANNOTATIONPROTO.fields_by_name['sentences'].message_type = _SENTENCEPROTO _TEXTANNOTATIONPROTO.fields_by_name['views'].message_type = _VIEWPROTO _TEXTANNOTATIONPROTO.fields_by_name['properties'].message_type = _TEXTANNOTATIONPROTO_PROPERTIESENTRY _VIEWPROTO.fields_by_name['viewData'].message_type = _VIEWDATAPROTO _VIEWDATAPROTO.fields_by_name['constituents'].message_type = _CONSTITUENTPROTO _VIEWDATAPROTO.fields_by_name['relations'].message_type = _RELATIONPROTO _CONSTITUENTPROTO_PROPERTIESENTRY.containing_type = _CONSTITUENTPROTO _CONSTITUENTPROTO_LABELSCOREMAPENTRY.containing_type = _CONSTITUENTPROTO _CONSTITUENTPROTO.fields_by_name['properties'].message_type = _CONSTITUENTPROTO_PROPERTIESENTRY _CONSTITUENTPROTO.fields_by_name['labelScoreMap'].message_type = _CONSTITUENTPROTO_LABELSCOREMAPENTRY _RELATIONPROTO_PROPERTIESENTRY.containing_type = _RELATIONPROTO _RELATIONPROTO_LABELSCOREMAPENTRY.containing_type = _RELATIONPROTO _RELATIONPROTO.fields_by_name['properties'].message_type = _RELATIONPROTO_PROPERTIESENTRY _RELATIONPROTO.fields_by_name['labelScoreMap'].message_type = _RELATIONPROTO_LABELSCOREMAPENTRY DESCRIPTOR.message_types_by_name['TextAnnotationProto'] = _TEXTANNOTATIONPROTO DESCRIPTOR.message_types_by_name['TokenOffsetsProto'] = _TOKENOFFSETSPROTO DESCRIPTOR.message_types_by_name['SentenceProto'] = _SENTENCEPROTO DESCRIPTOR.message_types_by_name['ViewProto'] = _VIEWPROTO DESCRIPTOR.message_types_by_name['ViewDataProto'] = _VIEWDATAPROTO DESCRIPTOR.message_types_by_name['ConstituentProto'] = _CONSTITUENTPROTO DESCRIPTOR.message_types_by_name['RelationProto'] = _RELATIONPROTO TextAnnotationProto = _reflection.GeneratedProtocolMessageType('TextAnnotationProto', (_message.Message,), dict( PropertiesEntry = _reflection.GeneratedProtocolMessageType('PropertiesEntry', (_message.Message,), dict( DESCRIPTOR = _TEXTANNOTATIONPROTO_PROPERTIESENTRY, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.TextAnnotationProto.PropertiesEntry) )) , DESCRIPTOR = _TEXTANNOTATIONPROTO, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.TextAnnotationProto) )) _sym_db.RegisterMessage(TextAnnotationProto) _sym_db.RegisterMessage(TextAnnotationProto.PropertiesEntry) TokenOffsetsProto = _reflection.GeneratedProtocolMessageType('TokenOffsetsProto', (_message.Message,), dict( DESCRIPTOR = _TOKENOFFSETSPROTO, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.TokenOffsetsProto) )) _sym_db.RegisterMessage(TokenOffsetsProto) SentenceProto = _reflection.GeneratedProtocolMessageType('SentenceProto', (_message.Message,), dict( DESCRIPTOR = _SENTENCEPROTO, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.SentenceProto) )) _sym_db.RegisterMessage(SentenceProto) ViewProto = _reflection.GeneratedProtocolMessageType('ViewProto', (_message.Message,), dict( DESCRIPTOR = _VIEWPROTO, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.ViewProto) )) _sym_db.RegisterMessage(ViewProto) ViewDataProto = _reflection.GeneratedProtocolMessageType('ViewDataProto', (_message.Message,), dict( DESCRIPTOR = _VIEWDATAPROTO, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.ViewDataProto) )) _sym_db.RegisterMessage(ViewDataProto) ConstituentProto = _reflection.GeneratedProtocolMessageType('ConstituentProto', (_message.Message,), dict( PropertiesEntry = _reflection.GeneratedProtocolMessageType('PropertiesEntry', (_message.Message,), dict( DESCRIPTOR = _CONSTITUENTPROTO_PROPERTIESENTRY, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.ConstituentProto.PropertiesEntry) )) , LabelScoreMapEntry = _reflection.GeneratedProtocolMessageType('LabelScoreMapEntry', (_message.Message,), dict( DESCRIPTOR = _CONSTITUENTPROTO_LABELSCOREMAPENTRY, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.ConstituentProto.LabelScoreMapEntry) )) , DESCRIPTOR = _CONSTITUENTPROTO, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.ConstituentProto) )) _sym_db.RegisterMessage(ConstituentProto) _sym_db.RegisterMessage(ConstituentProto.PropertiesEntry) _sym_db.RegisterMessage(ConstituentProto.LabelScoreMapEntry) RelationProto = _reflection.GeneratedProtocolMessageType('RelationProto', (_message.Message,), dict( PropertiesEntry = _reflection.GeneratedProtocolMessageType('PropertiesEntry', (_message.Message,), dict( DESCRIPTOR = _RELATIONPROTO_PROPERTIESENTRY, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.RelationProto.PropertiesEntry) )) , LabelScoreMapEntry = _reflection.GeneratedProtocolMessageType('LabelScoreMapEntry', (_message.Message,), dict( DESCRIPTOR = _RELATIONPROTO_LABELSCOREMAPENTRY, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.RelationProto.LabelScoreMapEntry) )) , DESCRIPTOR = _RELATIONPROTO, __module__ = 'protobuf.TextAnnotation_pb2' # @@protoc_insertion_point(class_scope:textannotation.RelationProto) )) _sym_db.RegisterMessage(RelationProto) _sym_db.RegisterMessage(RelationProto.PropertiesEntry) _sym_db.RegisterMessage(RelationProto.LabelScoreMapEntry) DESCRIPTOR.has_options = True DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n/edu.illinois.cs.cogcomp.core.utilities.protobufB\022TextAnnotationImplP\000')) _TEXTANNOTATIONPROTO_PROPERTIESENTRY.has_options = True _TEXTANNOTATIONPROTO_PROPERTIESENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) _CONSTITUENTPROTO_PROPERTIESENTRY.has_options = True _CONSTITUENTPROTO_PROPERTIESENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) _CONSTITUENTPROTO_LABELSCOREMAPENTRY.has_options = True _CONSTITUENTPROTO_LABELSCOREMAPENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) _RELATIONPROTO_PROPERTIESENTRY.has_options = True _RELATIONPROTO_PROPERTIESENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) _RELATIONPROTO_LABELSCOREMAPENTRY.has_options = True _RELATIONPROTO_LABELSCOREMAPENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) # @@protoc_insertion_point(module_scope)
Module variables
var DESCRIPTOR
Classes
class ConstituentProto
Abstract base class for protocol messages.
Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.
TODO(robinson): Link to an HTML document here.
TODO(robinson): Document that instances of this class will also have an Extensions attribute with getitem and setitem. Again, not sure how to best convey this.
TODO(robinson): Document that the class must also have a static RegisterExtension(extension_field) method. Not sure how to best express at this point.
Ancestors (in MRO)
- ConstituentProto
- google.protobuf.message.Message
- builtins.object
Class variables
var DESCRIPTOR
var END_FIELD_NUMBER
var LABELSCOREMAP_FIELD_NUMBER
var LABEL_FIELD_NUMBER
var LabelScoreMapEntry
var PROPERTIES_FIELD_NUMBER
var PropertiesEntry
var SCORE_FIELD_NUMBER
var START_FIELD_NUMBER
Static methods
def __init__(
self, **kwargs)
def init(self, **kwargs): self._cached_byte_size = 0 self._cached_byte_size_dirty = len(kwargs) > 0 self._fields = {} # Contains a mapping from oneof field descriptors to the descriptor # of the currently set field in that oneof field. self._oneofs = {} # _unknown_fields is () when empty for efficiency, and will be turned into # a list if fields are added. self._unknown_fields = () self._is_present_in_parent = False self._listener = message_listener_mod.NullMessageListener() self._listener_for_children = _Listener(self) for field_name, field_value in kwargs.items(): field = _GetFieldByName(message_descriptor, field_name) if field is None: raise TypeError("%s() got an unexpected keyword argument '%s'" % (message_descriptor.name, field_name)) if field_value is None: # field=None is the same as no field at all. continue if field.label == _FieldDescriptor.LABEL_REPEATED: copy = field._default_constructor(self) if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: # Composite if _IsMapField(field): if _IsMessageMapField(field): for key in field_value: copy[key].MergeFrom(field_value[key]) else: copy.update(field_value) else: for val in field_value: if isinstance(val, dict): copy.add(**val) else: copy.add().MergeFrom(val) else: # Scalar if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = [_GetIntegerEnumValue(field.enum_type, val) for val in field_value] copy.extend(field_value) self._fields[field] = copy elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: copy = field._default_constructor(self) new_val = field_value if isinstance(field_value, dict): new_val = field.message_type._concrete_class(**field_value) try: copy.MergeFrom(new_val) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name) self._fields[field] = copy else: if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = _GetIntegerEnumValue(field.enum_type, field_value) try: setattr(self, field_name, field_value) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
def ByteSize(
self)
def ByteSize(self): if not self._cached_byte_size_dirty: return self._cached_byte_size size = 0 for field_descriptor, field_value in self.ListFields(): size += field_descriptor._sizer(field_value) for tag_bytes, value_bytes in self._unknown_fields: size += len(tag_bytes) + len(value_bytes) self._cached_byte_size = size self._cached_byte_size_dirty = False self._listener_for_children.dirty = False return size
def Clear(
self)
def _Clear(self): # Clear fields. self._fields = {} self._unknown_fields = () self._oneofs = {} self._Modified()
def ClearExtension(
self, extension_handle)
def ClearExtension(self, extension_handle): raise NotImplementedError
def ClearField(
self, field_name)
def ClearField(self, field_name): try: field = message_descriptor.fields_by_name[field_name] except KeyError: try: field = message_descriptor.oneofs_by_name[field_name] if field in self._oneofs: field = self._oneofs[field] else: return except KeyError: raise ValueError('Protocol message %s() has no "%s" field.' % (message_descriptor.name, field_name)) if field in self._fields: # To match the C++ implementation, we need to invalidate iterators # for map fields when ClearField() happens. if hasattr(self._fields[field], 'InvalidateIterators'): self._fields[field].InvalidateIterators() # Note: If the field is a sub-message, its listener will still point # at us. That's fine, because the worst than can happen is that it # will call _Modified() and invalidate our byte size. Big deal. del self._fields[field] if self._oneofs.get(field.containing_oneof, None) is field: del self._oneofs[field.containing_oneof] # Always call _Modified() -- even if nothing was changed, this is # a mutating method, and thus calling it should cause the field to become # present in the parent message. self._Modified()
def CopyFrom(
self, other_msg)
Copies the content of the specified message into the current message.
The method clears the current message and then merges the specified message using MergeFrom.
Args: other_msg: Message to copy into the current one.
def CopyFrom(self, other_msg): """Copies the content of the specified message into the current message. The method clears the current message and then merges the specified message using MergeFrom. Args: other_msg: Message to copy into the current one. """ if self is other_msg: return self.Clear() self.MergeFrom(other_msg)
def DiscardUnknownFields(
self)
def _DiscardUnknownFields(self): self._unknown_fields = [] for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: for sub_message in value: sub_message.DiscardUnknownFields() else: value.DiscardUnknownFields()
def FindInitializationErrors(
self)
Finds required fields which are not initialized.
Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz".
def FindInitializationErrors(self): """Finds required fields which are not initialized. Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz". """ errors = [] # simplify things for field in required_fields: if not self.HasField(field.name): errors.append(field.name) for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.is_extension: name = "(%s)" % field.full_name else: name = field.name if _IsMapField(field): if _IsMessageMapField(field): for key in value: element = value[key] prefix = "%s[%s]." % (name, key) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: # ScalarMaps can't have any initialization errors. pass elif field.label == _FieldDescriptor.LABEL_REPEATED: for i in range(len(value)): element = value[i] prefix = "%s[%d]." % (name, i) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: prefix = name + "." sub_errors = value.FindInitializationErrors() errors += [prefix + error for error in sub_errors] return errors
def FromString(
s)
def FromString(s): message = cls() message.MergeFromString(s) return message
def HasExtension(
self, extension_handle)
def HasExtension(self, extension_handle): raise NotImplementedError
def HasField(
self, field_name)
def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields
def IsInitialized(
self, errors=None)
Checks if all required fields of a message are set.
Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields.
Returns: True iff the specified message has all required fields set.
def IsInitialized(self, errors=None): """Checks if all required fields of a message are set. Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields. Returns: True iff the specified message has all required fields set. """ # Performance is critical so we avoid HasField() and ListFields(). for field in required_fields: if (field not in self._fields or (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and not self._fields[field]._is_present_in_parent)): if errors is not None: errors.extend(self.FindInitializationErrors()) return False for field, value in list(self._fields.items()): # dict can change size! if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: if (field.message_type.has_options and field.message_type.GetOptions().map_entry): continue for element in value: if not element.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False elif value._is_present_in_parent and not value.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False return True
def ListFields(
self)
def ListFields(self): all_fields = [item for item in self._fields.items() if _IsPresent(item)] all_fields.sort(key = lambda item: item[0].number) return all_fields
def MergeFrom(
self, msg)
def MergeFrom(self, msg): if not isinstance(msg, cls): raise TypeError( "Parameter to MergeFrom() must be instance of same class: " 'expected %s got %s.' % (cls.__name__, msg.__class__.__name__)) assert msg is not self self._Modified() fields = self._fields for field, value in msg._fields.items(): if field.label == LABEL_REPEATED: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) elif field.cpp_type == CPPTYPE_MESSAGE: if value._is_present_in_parent: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) else: self._fields[field] = value if field.containing_oneof: self._UpdateOneofState(field) if msg._unknown_fields: if not self._unknown_fields: self._unknown_fields = [] self._unknown_fields.extend(msg._unknown_fields)
def MergeFromString(
self, serialized)
def MergeFromString(self, serialized): length = len(serialized) try: if self._InternalParse(serialized, 0, length) != length: # The only reason _InternalParse would return early is if it # encountered an end-group tag. raise message_mod.DecodeError('Unexpected end-group tag.') except (IndexError, TypeError): # Now ord(buf[p:p+1]) == ord('') gets TypeError. raise message_mod.DecodeError('Truncated message.') except struct.error as e: raise message_mod.DecodeError(e) return length # Return this for legacy reasons.
def ParseFromString(
self, serialized)
Parse serialized protocol buffer data into this message.
Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns.
def ParseFromString(self, serialized): """Parse serialized protocol buffer data into this message. Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns. """ self.Clear() self.MergeFromString(serialized)
def RegisterExtension(
extension_handle)
def RegisterExtension(extension_handle): extension_handle.containing_type = cls.DESCRIPTOR # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available. cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle) _AttachFieldHelpers(cls, extension_handle)
def SerializePartialToString(
self)
def SerializePartialToString(self): out = BytesIO() self._InternalSerialize(out.write) return out.getvalue()
def SerializeToString(
self)
def SerializeToString(self): # Check if the message has all of its required fields set. errors = [] if not self.IsInitialized(): raise message_mod.EncodeError( 'Message %s is missing required fields: %s' % ( self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors()))) return self.SerializePartialToString()
def SetInParent(
self)
Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.
def Modified(self): """Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. """ # Note: Some callers check _cached_byte_size_dirty before calling # _Modified() as an extra optimization. So, if this method is ever # changed such that it does stuff even when _cached_byte_size_dirty is # already true, the callers need to be updated. if not self._cached_byte_size_dirty: self._cached_byte_size_dirty = True self._listener_for_children.dirty = True self._is_present_in_parent = True self._listener.Modified()
def WhichOneof(
self, oneof_name)
Returns the name of the currently set field inside a oneof, or None.
def WhichOneof(self, oneof_name): """Returns the name of the currently set field inside a oneof, or None.""" try: field = message_descriptor.oneofs_by_name[oneof_name] except KeyError: raise ValueError( 'Protocol message has no oneof "%s" field.' % oneof_name) nested_field = self._oneofs.get(field, None) if nested_field is not None and self.HasField(nested_field.name): return nested_field.name else: return None
Instance variables
var end
Magic attribute generated for "end" proto field.
var label
Magic attribute generated for "label" proto field.
var labelScoreMap
Magic attribute generated for "labelScoreMap" proto field.
var properties
Magic attribute generated for "properties" proto field.
var score
Magic attribute generated for "score" proto field.
var start
Magic attribute generated for "start" proto field.
class RelationProto
Abstract base class for protocol messages.
Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.
TODO(robinson): Link to an HTML document here.
TODO(robinson): Document that instances of this class will also have an Extensions attribute with getitem and setitem. Again, not sure how to best convey this.
TODO(robinson): Document that the class must also have a static RegisterExtension(extension_field) method. Not sure how to best express at this point.
Ancestors (in MRO)
- RelationProto
- google.protobuf.message.Message
- builtins.object
Class variables
var DESCRIPTOR
var LABELSCOREMAP_FIELD_NUMBER
var LabelScoreMapEntry
var PROPERTIES_FIELD_NUMBER
var PropertiesEntry
var RELATIONNAME_FIELD_NUMBER
var SCORE_FIELD_NUMBER
var SRCCONSTITUENT_FIELD_NUMBER
var TARGETCONSTITUENT_FIELD_NUMBER
Static methods
def __init__(
self, **kwargs)
def init(self, **kwargs): self._cached_byte_size = 0 self._cached_byte_size_dirty = len(kwargs) > 0 self._fields = {} # Contains a mapping from oneof field descriptors to the descriptor # of the currently set field in that oneof field. self._oneofs = {} # _unknown_fields is () when empty for efficiency, and will be turned into # a list if fields are added. self._unknown_fields = () self._is_present_in_parent = False self._listener = message_listener_mod.NullMessageListener() self._listener_for_children = _Listener(self) for field_name, field_value in kwargs.items(): field = _GetFieldByName(message_descriptor, field_name) if field is None: raise TypeError("%s() got an unexpected keyword argument '%s'" % (message_descriptor.name, field_name)) if field_value is None: # field=None is the same as no field at all. continue if field.label == _FieldDescriptor.LABEL_REPEATED: copy = field._default_constructor(self) if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: # Composite if _IsMapField(field): if _IsMessageMapField(field): for key in field_value: copy[key].MergeFrom(field_value[key]) else: copy.update(field_value) else: for val in field_value: if isinstance(val, dict): copy.add(**val) else: copy.add().MergeFrom(val) else: # Scalar if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = [_GetIntegerEnumValue(field.enum_type, val) for val in field_value] copy.extend(field_value) self._fields[field] = copy elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: copy = field._default_constructor(self) new_val = field_value if isinstance(field_value, dict): new_val = field.message_type._concrete_class(**field_value) try: copy.MergeFrom(new_val) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name) self._fields[field] = copy else: if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = _GetIntegerEnumValue(field.enum_type, field_value) try: setattr(self, field_name, field_value) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
def ByteSize(
self)
def ByteSize(self): if not self._cached_byte_size_dirty: return self._cached_byte_size size = 0 for field_descriptor, field_value in self.ListFields(): size += field_descriptor._sizer(field_value) for tag_bytes, value_bytes in self._unknown_fields: size += len(tag_bytes) + len(value_bytes) self._cached_byte_size = size self._cached_byte_size_dirty = False self._listener_for_children.dirty = False return size
def Clear(
self)
def _Clear(self): # Clear fields. self._fields = {} self._unknown_fields = () self._oneofs = {} self._Modified()
def ClearExtension(
self, extension_handle)
def ClearExtension(self, extension_handle): raise NotImplementedError
def ClearField(
self, field_name)
def ClearField(self, field_name): try: field = message_descriptor.fields_by_name[field_name] except KeyError: try: field = message_descriptor.oneofs_by_name[field_name] if field in self._oneofs: field = self._oneofs[field] else: return except KeyError: raise ValueError('Protocol message %s() has no "%s" field.' % (message_descriptor.name, field_name)) if field in self._fields: # To match the C++ implementation, we need to invalidate iterators # for map fields when ClearField() happens. if hasattr(self._fields[field], 'InvalidateIterators'): self._fields[field].InvalidateIterators() # Note: If the field is a sub-message, its listener will still point # at us. That's fine, because the worst than can happen is that it # will call _Modified() and invalidate our byte size. Big deal. del self._fields[field] if self._oneofs.get(field.containing_oneof, None) is field: del self._oneofs[field.containing_oneof] # Always call _Modified() -- even if nothing was changed, this is # a mutating method, and thus calling it should cause the field to become # present in the parent message. self._Modified()
def CopyFrom(
self, other_msg)
Copies the content of the specified message into the current message.
The method clears the current message and then merges the specified message using MergeFrom.
Args: other_msg: Message to copy into the current one.
def CopyFrom(self, other_msg): """Copies the content of the specified message into the current message. The method clears the current message and then merges the specified message using MergeFrom. Args: other_msg: Message to copy into the current one. """ if self is other_msg: return self.Clear() self.MergeFrom(other_msg)
def DiscardUnknownFields(
self)
def _DiscardUnknownFields(self): self._unknown_fields = [] for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: for sub_message in value: sub_message.DiscardUnknownFields() else: value.DiscardUnknownFields()
def FindInitializationErrors(
self)
Finds required fields which are not initialized.
Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz".
def FindInitializationErrors(self): """Finds required fields which are not initialized. Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz". """ errors = [] # simplify things for field in required_fields: if not self.HasField(field.name): errors.append(field.name) for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.is_extension: name = "(%s)" % field.full_name else: name = field.name if _IsMapField(field): if _IsMessageMapField(field): for key in value: element = value[key] prefix = "%s[%s]." % (name, key) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: # ScalarMaps can't have any initialization errors. pass elif field.label == _FieldDescriptor.LABEL_REPEATED: for i in range(len(value)): element = value[i] prefix = "%s[%d]." % (name, i) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: prefix = name + "." sub_errors = value.FindInitializationErrors() errors += [prefix + error for error in sub_errors] return errors
def FromString(
s)
def FromString(s): message = cls() message.MergeFromString(s) return message
def HasExtension(
self, extension_handle)
def HasExtension(self, extension_handle): raise NotImplementedError
def HasField(
self, field_name)
def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields
def IsInitialized(
self, errors=None)
Checks if all required fields of a message are set.
Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields.
Returns: True iff the specified message has all required fields set.
def IsInitialized(self, errors=None): """Checks if all required fields of a message are set. Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields. Returns: True iff the specified message has all required fields set. """ # Performance is critical so we avoid HasField() and ListFields(). for field in required_fields: if (field not in self._fields or (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and not self._fields[field]._is_present_in_parent)): if errors is not None: errors.extend(self.FindInitializationErrors()) return False for field, value in list(self._fields.items()): # dict can change size! if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: if (field.message_type.has_options and field.message_type.GetOptions().map_entry): continue for element in value: if not element.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False elif value._is_present_in_parent and not value.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False return True
def ListFields(
self)
def ListFields(self): all_fields = [item for item in self._fields.items() if _IsPresent(item)] all_fields.sort(key = lambda item: item[0].number) return all_fields
def MergeFrom(
self, msg)
def MergeFrom(self, msg): if not isinstance(msg, cls): raise TypeError( "Parameter to MergeFrom() must be instance of same class: " 'expected %s got %s.' % (cls.__name__, msg.__class__.__name__)) assert msg is not self self._Modified() fields = self._fields for field, value in msg._fields.items(): if field.label == LABEL_REPEATED: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) elif field.cpp_type == CPPTYPE_MESSAGE: if value._is_present_in_parent: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) else: self._fields[field] = value if field.containing_oneof: self._UpdateOneofState(field) if msg._unknown_fields: if not self._unknown_fields: self._unknown_fields = [] self._unknown_fields.extend(msg._unknown_fields)
def MergeFromString(
self, serialized)
def MergeFromString(self, serialized): length = len(serialized) try: if self._InternalParse(serialized, 0, length) != length: # The only reason _InternalParse would return early is if it # encountered an end-group tag. raise message_mod.DecodeError('Unexpected end-group tag.') except (IndexError, TypeError): # Now ord(buf[p:p+1]) == ord('') gets TypeError. raise message_mod.DecodeError('Truncated message.') except struct.error as e: raise message_mod.DecodeError(e) return length # Return this for legacy reasons.
def ParseFromString(
self, serialized)
Parse serialized protocol buffer data into this message.
Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns.
def ParseFromString(self, serialized): """Parse serialized protocol buffer data into this message. Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns. """ self.Clear() self.MergeFromString(serialized)
def RegisterExtension(
extension_handle)
def RegisterExtension(extension_handle): extension_handle.containing_type = cls.DESCRIPTOR # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available. cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle) _AttachFieldHelpers(cls, extension_handle)
def SerializePartialToString(
self)
def SerializePartialToString(self): out = BytesIO() self._InternalSerialize(out.write) return out.getvalue()
def SerializeToString(
self)
def SerializeToString(self): # Check if the message has all of its required fields set. errors = [] if not self.IsInitialized(): raise message_mod.EncodeError( 'Message %s is missing required fields: %s' % ( self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors()))) return self.SerializePartialToString()
def SetInParent(
self)
Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.
def Modified(self): """Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. """ # Note: Some callers check _cached_byte_size_dirty before calling # _Modified() as an extra optimization. So, if this method is ever # changed such that it does stuff even when _cached_byte_size_dirty is # already true, the callers need to be updated. if not self._cached_byte_size_dirty: self._cached_byte_size_dirty = True self._listener_for_children.dirty = True self._is_present_in_parent = True self._listener.Modified()
def WhichOneof(
self, oneof_name)
Returns the name of the currently set field inside a oneof, or None.
def WhichOneof(self, oneof_name): """Returns the name of the currently set field inside a oneof, or None.""" try: field = message_descriptor.oneofs_by_name[oneof_name] except KeyError: raise ValueError( 'Protocol message has no oneof "%s" field.' % oneof_name) nested_field = self._oneofs.get(field, None) if nested_field is not None and self.HasField(nested_field.name): return nested_field.name else: return None
Instance variables
var labelScoreMap
Magic attribute generated for "labelScoreMap" proto field.
var properties
Magic attribute generated for "properties" proto field.
var relationName
Magic attribute generated for "relationName" proto field.
var score
Magic attribute generated for "score" proto field.
var srcConstituent
Magic attribute generated for "srcConstituent" proto field.
var targetConstituent
Magic attribute generated for "targetConstituent" proto field.
class SentenceProto
Abstract base class for protocol messages.
Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.
TODO(robinson): Link to an HTML document here.
TODO(robinson): Document that instances of this class will also have an Extensions attribute with getitem and setitem. Again, not sure how to best convey this.
TODO(robinson): Document that the class must also have a static RegisterExtension(extension_field) method. Not sure how to best express at this point.
Ancestors (in MRO)
- SentenceProto
- google.protobuf.message.Message
- builtins.object
Class variables
var DESCRIPTOR
var GENERATOR_FIELD_NUMBER
var SCORE_FIELD_NUMBER
var SENTENCEENDPOSITIONS_FIELD_NUMBER
Static methods
def __init__(
self, **kwargs)
def init(self, **kwargs): self._cached_byte_size = 0 self._cached_byte_size_dirty = len(kwargs) > 0 self._fields = {} # Contains a mapping from oneof field descriptors to the descriptor # of the currently set field in that oneof field. self._oneofs = {} # _unknown_fields is () when empty for efficiency, and will be turned into # a list if fields are added. self._unknown_fields = () self._is_present_in_parent = False self._listener = message_listener_mod.NullMessageListener() self._listener_for_children = _Listener(self) for field_name, field_value in kwargs.items(): field = _GetFieldByName(message_descriptor, field_name) if field is None: raise TypeError("%s() got an unexpected keyword argument '%s'" % (message_descriptor.name, field_name)) if field_value is None: # field=None is the same as no field at all. continue if field.label == _FieldDescriptor.LABEL_REPEATED: copy = field._default_constructor(self) if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: # Composite if _IsMapField(field): if _IsMessageMapField(field): for key in field_value: copy[key].MergeFrom(field_value[key]) else: copy.update(field_value) else: for val in field_value: if isinstance(val, dict): copy.add(**val) else: copy.add().MergeFrom(val) else: # Scalar if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = [_GetIntegerEnumValue(field.enum_type, val) for val in field_value] copy.extend(field_value) self._fields[field] = copy elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: copy = field._default_constructor(self) new_val = field_value if isinstance(field_value, dict): new_val = field.message_type._concrete_class(**field_value) try: copy.MergeFrom(new_val) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name) self._fields[field] = copy else: if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = _GetIntegerEnumValue(field.enum_type, field_value) try: setattr(self, field_name, field_value) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
def ByteSize(
self)
def ByteSize(self): if not self._cached_byte_size_dirty: return self._cached_byte_size size = 0 for field_descriptor, field_value in self.ListFields(): size += field_descriptor._sizer(field_value) for tag_bytes, value_bytes in self._unknown_fields: size += len(tag_bytes) + len(value_bytes) self._cached_byte_size = size self._cached_byte_size_dirty = False self._listener_for_children.dirty = False return size
def Clear(
self)
def _Clear(self): # Clear fields. self._fields = {} self._unknown_fields = () self._oneofs = {} self._Modified()
def ClearExtension(
self, extension_handle)
def ClearExtension(self, extension_handle): raise NotImplementedError
def ClearField(
self, field_name)
def ClearField(self, field_name): try: field = message_descriptor.fields_by_name[field_name] except KeyError: try: field = message_descriptor.oneofs_by_name[field_name] if field in self._oneofs: field = self._oneofs[field] else: return except KeyError: raise ValueError('Protocol message %s() has no "%s" field.' % (message_descriptor.name, field_name)) if field in self._fields: # To match the C++ implementation, we need to invalidate iterators # for map fields when ClearField() happens. if hasattr(self._fields[field], 'InvalidateIterators'): self._fields[field].InvalidateIterators() # Note: If the field is a sub-message, its listener will still point # at us. That's fine, because the worst than can happen is that it # will call _Modified() and invalidate our byte size. Big deal. del self._fields[field] if self._oneofs.get(field.containing_oneof, None) is field: del self._oneofs[field.containing_oneof] # Always call _Modified() -- even if nothing was changed, this is # a mutating method, and thus calling it should cause the field to become # present in the parent message. self._Modified()
def CopyFrom(
self, other_msg)
Copies the content of the specified message into the current message.
The method clears the current message and then merges the specified message using MergeFrom.
Args: other_msg: Message to copy into the current one.
def CopyFrom(self, other_msg): """Copies the content of the specified message into the current message. The method clears the current message and then merges the specified message using MergeFrom. Args: other_msg: Message to copy into the current one. """ if self is other_msg: return self.Clear() self.MergeFrom(other_msg)
def DiscardUnknownFields(
self)
def _DiscardUnknownFields(self): self._unknown_fields = [] for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: for sub_message in value: sub_message.DiscardUnknownFields() else: value.DiscardUnknownFields()
def FindInitializationErrors(
self)
Finds required fields which are not initialized.
Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz".
def FindInitializationErrors(self): """Finds required fields which are not initialized. Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz". """ errors = [] # simplify things for field in required_fields: if not self.HasField(field.name): errors.append(field.name) for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.is_extension: name = "(%s)" % field.full_name else: name = field.name if _IsMapField(field): if _IsMessageMapField(field): for key in value: element = value[key] prefix = "%s[%s]." % (name, key) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: # ScalarMaps can't have any initialization errors. pass elif field.label == _FieldDescriptor.LABEL_REPEATED: for i in range(len(value)): element = value[i] prefix = "%s[%d]." % (name, i) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: prefix = name + "." sub_errors = value.FindInitializationErrors() errors += [prefix + error for error in sub_errors] return errors
def FromString(
s)
def FromString(s): message = cls() message.MergeFromString(s) return message
def HasExtension(
self, extension_handle)
def HasExtension(self, extension_handle): raise NotImplementedError
def HasField(
self, field_name)
def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields
def IsInitialized(
self, errors=None)
Checks if all required fields of a message are set.
Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields.
Returns: True iff the specified message has all required fields set.
def IsInitialized(self, errors=None): """Checks if all required fields of a message are set. Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields. Returns: True iff the specified message has all required fields set. """ # Performance is critical so we avoid HasField() and ListFields(). for field in required_fields: if (field not in self._fields or (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and not self._fields[field]._is_present_in_parent)): if errors is not None: errors.extend(self.FindInitializationErrors()) return False for field, value in list(self._fields.items()): # dict can change size! if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: if (field.message_type.has_options and field.message_type.GetOptions().map_entry): continue for element in value: if not element.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False elif value._is_present_in_parent and not value.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False return True
def ListFields(
self)
def ListFields(self): all_fields = [item for item in self._fields.items() if _IsPresent(item)] all_fields.sort(key = lambda item: item[0].number) return all_fields
def MergeFrom(
self, msg)
def MergeFrom(self, msg): if not isinstance(msg, cls): raise TypeError( "Parameter to MergeFrom() must be instance of same class: " 'expected %s got %s.' % (cls.__name__, msg.__class__.__name__)) assert msg is not self self._Modified() fields = self._fields for field, value in msg._fields.items(): if field.label == LABEL_REPEATED: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) elif field.cpp_type == CPPTYPE_MESSAGE: if value._is_present_in_parent: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) else: self._fields[field] = value if field.containing_oneof: self._UpdateOneofState(field) if msg._unknown_fields: if not self._unknown_fields: self._unknown_fields = [] self._unknown_fields.extend(msg._unknown_fields)
def MergeFromString(
self, serialized)
def MergeFromString(self, serialized): length = len(serialized) try: if self._InternalParse(serialized, 0, length) != length: # The only reason _InternalParse would return early is if it # encountered an end-group tag. raise message_mod.DecodeError('Unexpected end-group tag.') except (IndexError, TypeError): # Now ord(buf[p:p+1]) == ord('') gets TypeError. raise message_mod.DecodeError('Truncated message.') except struct.error as e: raise message_mod.DecodeError(e) return length # Return this for legacy reasons.
def ParseFromString(
self, serialized)
Parse serialized protocol buffer data into this message.
Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns.
def ParseFromString(self, serialized): """Parse serialized protocol buffer data into this message. Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns. """ self.Clear() self.MergeFromString(serialized)
def RegisterExtension(
extension_handle)
def RegisterExtension(extension_handle): extension_handle.containing_type = cls.DESCRIPTOR # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available. cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle) _AttachFieldHelpers(cls, extension_handle)
def SerializePartialToString(
self)
def SerializePartialToString(self): out = BytesIO() self._InternalSerialize(out.write) return out.getvalue()
def SerializeToString(
self)
def SerializeToString(self): # Check if the message has all of its required fields set. errors = [] if not self.IsInitialized(): raise message_mod.EncodeError( 'Message %s is missing required fields: %s' % ( self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors()))) return self.SerializePartialToString()
def SetInParent(
self)
Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.
def Modified(self): """Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. """ # Note: Some callers check _cached_byte_size_dirty before calling # _Modified() as an extra optimization. So, if this method is ever # changed such that it does stuff even when _cached_byte_size_dirty is # already true, the callers need to be updated. if not self._cached_byte_size_dirty: self._cached_byte_size_dirty = True self._listener_for_children.dirty = True self._is_present_in_parent = True self._listener.Modified()
def WhichOneof(
self, oneof_name)
Returns the name of the currently set field inside a oneof, or None.
def WhichOneof(self, oneof_name): """Returns the name of the currently set field inside a oneof, or None.""" try: field = message_descriptor.oneofs_by_name[oneof_name] except KeyError: raise ValueError( 'Protocol message has no oneof "%s" field.' % oneof_name) nested_field = self._oneofs.get(field, None) if nested_field is not None and self.HasField(nested_field.name): return nested_field.name else: return None
Instance variables
var generator
Magic attribute generated for "generator" proto field.
var score
Magic attribute generated for "score" proto field.
var sentenceEndPositions
Magic attribute generated for "sentenceEndPositions" proto field.
class TextAnnotationProto
Abstract base class for protocol messages.
Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.
TODO(robinson): Link to an HTML document here.
TODO(robinson): Document that instances of this class will also have an Extensions attribute with getitem and setitem. Again, not sure how to best convey this.
TODO(robinson): Document that the class must also have a static RegisterExtension(extension_field) method. Not sure how to best express at this point.
Ancestors (in MRO)
- TextAnnotationProto
- google.protobuf.message.Message
- builtins.object
Class variables
var CORPUSID_FIELD_NUMBER
var DESCRIPTOR
var ID_FIELD_NUMBER
var PROPERTIES_FIELD_NUMBER
var PropertiesEntry
var SENTENCES_FIELD_NUMBER
var TEXT_FIELD_NUMBER
var TOKENOFFSETS_FIELD_NUMBER
var TOKENS_FIELD_NUMBER
var VIEWS_FIELD_NUMBER
Static methods
def __init__(
self, **kwargs)
def init(self, **kwargs): self._cached_byte_size = 0 self._cached_byte_size_dirty = len(kwargs) > 0 self._fields = {} # Contains a mapping from oneof field descriptors to the descriptor # of the currently set field in that oneof field. self._oneofs = {} # _unknown_fields is () when empty for efficiency, and will be turned into # a list if fields are added. self._unknown_fields = () self._is_present_in_parent = False self._listener = message_listener_mod.NullMessageListener() self._listener_for_children = _Listener(self) for field_name, field_value in kwargs.items(): field = _GetFieldByName(message_descriptor, field_name) if field is None: raise TypeError("%s() got an unexpected keyword argument '%s'" % (message_descriptor.name, field_name)) if field_value is None: # field=None is the same as no field at all. continue if field.label == _FieldDescriptor.LABEL_REPEATED: copy = field._default_constructor(self) if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: # Composite if _IsMapField(field): if _IsMessageMapField(field): for key in field_value: copy[key].MergeFrom(field_value[key]) else: copy.update(field_value) else: for val in field_value: if isinstance(val, dict): copy.add(**val) else: copy.add().MergeFrom(val) else: # Scalar if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = [_GetIntegerEnumValue(field.enum_type, val) for val in field_value] copy.extend(field_value) self._fields[field] = copy elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: copy = field._default_constructor(self) new_val = field_value if isinstance(field_value, dict): new_val = field.message_type._concrete_class(**field_value) try: copy.MergeFrom(new_val) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name) self._fields[field] = copy else: if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = _GetIntegerEnumValue(field.enum_type, field_value) try: setattr(self, field_name, field_value) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
def ByteSize(
self)
def ByteSize(self): if not self._cached_byte_size_dirty: return self._cached_byte_size size = 0 for field_descriptor, field_value in self.ListFields(): size += field_descriptor._sizer(field_value) for tag_bytes, value_bytes in self._unknown_fields: size += len(tag_bytes) + len(value_bytes) self._cached_byte_size = size self._cached_byte_size_dirty = False self._listener_for_children.dirty = False return size
def Clear(
self)
def _Clear(self): # Clear fields. self._fields = {} self._unknown_fields = () self._oneofs = {} self._Modified()
def ClearExtension(
self, extension_handle)
def ClearExtension(self, extension_handle): raise NotImplementedError
def ClearField(
self, field_name)
def ClearField(self, field_name): try: field = message_descriptor.fields_by_name[field_name] except KeyError: try: field = message_descriptor.oneofs_by_name[field_name] if field in self._oneofs: field = self._oneofs[field] else: return except KeyError: raise ValueError('Protocol message %s() has no "%s" field.' % (message_descriptor.name, field_name)) if field in self._fields: # To match the C++ implementation, we need to invalidate iterators # for map fields when ClearField() happens. if hasattr(self._fields[field], 'InvalidateIterators'): self._fields[field].InvalidateIterators() # Note: If the field is a sub-message, its listener will still point # at us. That's fine, because the worst than can happen is that it # will call _Modified() and invalidate our byte size. Big deal. del self._fields[field] if self._oneofs.get(field.containing_oneof, None) is field: del self._oneofs[field.containing_oneof] # Always call _Modified() -- even if nothing was changed, this is # a mutating method, and thus calling it should cause the field to become # present in the parent message. self._Modified()
def CopyFrom(
self, other_msg)
Copies the content of the specified message into the current message.
The method clears the current message and then merges the specified message using MergeFrom.
Args: other_msg: Message to copy into the current one.
def CopyFrom(self, other_msg): """Copies the content of the specified message into the current message. The method clears the current message and then merges the specified message using MergeFrom. Args: other_msg: Message to copy into the current one. """ if self is other_msg: return self.Clear() self.MergeFrom(other_msg)
def DiscardUnknownFields(
self)
def _DiscardUnknownFields(self): self._unknown_fields = [] for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: for sub_message in value: sub_message.DiscardUnknownFields() else: value.DiscardUnknownFields()
def FindInitializationErrors(
self)
Finds required fields which are not initialized.
Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz".
def FindInitializationErrors(self): """Finds required fields which are not initialized. Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz". """ errors = [] # simplify things for field in required_fields: if not self.HasField(field.name): errors.append(field.name) for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.is_extension: name = "(%s)" % field.full_name else: name = field.name if _IsMapField(field): if _IsMessageMapField(field): for key in value: element = value[key] prefix = "%s[%s]." % (name, key) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: # ScalarMaps can't have any initialization errors. pass elif field.label == _FieldDescriptor.LABEL_REPEATED: for i in range(len(value)): element = value[i] prefix = "%s[%d]." % (name, i) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: prefix = name + "." sub_errors = value.FindInitializationErrors() errors += [prefix + error for error in sub_errors] return errors
def FromString(
s)
def FromString(s): message = cls() message.MergeFromString(s) return message
def HasExtension(
self, extension_handle)
def HasExtension(self, extension_handle): raise NotImplementedError
def HasField(
self, field_name)
def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields
def IsInitialized(
self, errors=None)
Checks if all required fields of a message are set.
Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields.
Returns: True iff the specified message has all required fields set.
def IsInitialized(self, errors=None): """Checks if all required fields of a message are set. Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields. Returns: True iff the specified message has all required fields set. """ # Performance is critical so we avoid HasField() and ListFields(). for field in required_fields: if (field not in self._fields or (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and not self._fields[field]._is_present_in_parent)): if errors is not None: errors.extend(self.FindInitializationErrors()) return False for field, value in list(self._fields.items()): # dict can change size! if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: if (field.message_type.has_options and field.message_type.GetOptions().map_entry): continue for element in value: if not element.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False elif value._is_present_in_parent and not value.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False return True
def ListFields(
self)
def ListFields(self): all_fields = [item for item in self._fields.items() if _IsPresent(item)] all_fields.sort(key = lambda item: item[0].number) return all_fields
def MergeFrom(
self, msg)
def MergeFrom(self, msg): if not isinstance(msg, cls): raise TypeError( "Parameter to MergeFrom() must be instance of same class: " 'expected %s got %s.' % (cls.__name__, msg.__class__.__name__)) assert msg is not self self._Modified() fields = self._fields for field, value in msg._fields.items(): if field.label == LABEL_REPEATED: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) elif field.cpp_type == CPPTYPE_MESSAGE: if value._is_present_in_parent: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) else: self._fields[field] = value if field.containing_oneof: self._UpdateOneofState(field) if msg._unknown_fields: if not self._unknown_fields: self._unknown_fields = [] self._unknown_fields.extend(msg._unknown_fields)
def MergeFromString(
self, serialized)
def MergeFromString(self, serialized): length = len(serialized) try: if self._InternalParse(serialized, 0, length) != length: # The only reason _InternalParse would return early is if it # encountered an end-group tag. raise message_mod.DecodeError('Unexpected end-group tag.') except (IndexError, TypeError): # Now ord(buf[p:p+1]) == ord('') gets TypeError. raise message_mod.DecodeError('Truncated message.') except struct.error as e: raise message_mod.DecodeError(e) return length # Return this for legacy reasons.
def ParseFromString(
self, serialized)
Parse serialized protocol buffer data into this message.
Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns.
def ParseFromString(self, serialized): """Parse serialized protocol buffer data into this message. Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns. """ self.Clear() self.MergeFromString(serialized)
def RegisterExtension(
extension_handle)
def RegisterExtension(extension_handle): extension_handle.containing_type = cls.DESCRIPTOR # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available. cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle) _AttachFieldHelpers(cls, extension_handle)
def SerializePartialToString(
self)
def SerializePartialToString(self): out = BytesIO() self._InternalSerialize(out.write) return out.getvalue()
def SerializeToString(
self)
def SerializeToString(self): # Check if the message has all of its required fields set. errors = [] if not self.IsInitialized(): raise message_mod.EncodeError( 'Message %s is missing required fields: %s' % ( self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors()))) return self.SerializePartialToString()
def SetInParent(
self)
Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.
def Modified(self): """Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. """ # Note: Some callers check _cached_byte_size_dirty before calling # _Modified() as an extra optimization. So, if this method is ever # changed such that it does stuff even when _cached_byte_size_dirty is # already true, the callers need to be updated. if not self._cached_byte_size_dirty: self._cached_byte_size_dirty = True self._listener_for_children.dirty = True self._is_present_in_parent = True self._listener.Modified()
def WhichOneof(
self, oneof_name)
Returns the name of the currently set field inside a oneof, or None.
def WhichOneof(self, oneof_name): """Returns the name of the currently set field inside a oneof, or None.""" try: field = message_descriptor.oneofs_by_name[oneof_name] except KeyError: raise ValueError( 'Protocol message has no oneof "%s" field.' % oneof_name) nested_field = self._oneofs.get(field, None) if nested_field is not None and self.HasField(nested_field.name): return nested_field.name else: return None
Instance variables
var corpusId
Magic attribute generated for "corpusId" proto field.
var id
Magic attribute generated for "id" proto field.
var properties
Magic attribute generated for "properties" proto field.
var sentences
Magic attribute generated for "sentences" proto field.
var text
Magic attribute generated for "text" proto field.
var tokenOffsets
Magic attribute generated for "tokenOffsets" proto field.
var tokens
Magic attribute generated for "tokens" proto field.
var views
Magic attribute generated for "views" proto field.
class TokenOffsetsProto
Abstract base class for protocol messages.
Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.
TODO(robinson): Link to an HTML document here.
TODO(robinson): Document that instances of this class will also have an Extensions attribute with getitem and setitem. Again, not sure how to best convey this.
TODO(robinson): Document that the class must also have a static RegisterExtension(extension_field) method. Not sure how to best express at this point.
Ancestors (in MRO)
- TokenOffsetsProto
- google.protobuf.message.Message
- builtins.object
Class variables
var DESCRIPTOR
var ENDCHAROFFSET_FIELD_NUMBER
var FORM_FIELD_NUMBER
var STARTCHAROFFSET_FIELD_NUMBER
Static methods
def __init__(
self, **kwargs)
def init(self, **kwargs): self._cached_byte_size = 0 self._cached_byte_size_dirty = len(kwargs) > 0 self._fields = {} # Contains a mapping from oneof field descriptors to the descriptor # of the currently set field in that oneof field. self._oneofs = {} # _unknown_fields is () when empty for efficiency, and will be turned into # a list if fields are added. self._unknown_fields = () self._is_present_in_parent = False self._listener = message_listener_mod.NullMessageListener() self._listener_for_children = _Listener(self) for field_name, field_value in kwargs.items(): field = _GetFieldByName(message_descriptor, field_name) if field is None: raise TypeError("%s() got an unexpected keyword argument '%s'" % (message_descriptor.name, field_name)) if field_value is None: # field=None is the same as no field at all. continue if field.label == _FieldDescriptor.LABEL_REPEATED: copy = field._default_constructor(self) if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: # Composite if _IsMapField(field): if _IsMessageMapField(field): for key in field_value: copy[key].MergeFrom(field_value[key]) else: copy.update(field_value) else: for val in field_value: if isinstance(val, dict): copy.add(**val) else: copy.add().MergeFrom(val) else: # Scalar if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = [_GetIntegerEnumValue(field.enum_type, val) for val in field_value] copy.extend(field_value) self._fields[field] = copy elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: copy = field._default_constructor(self) new_val = field_value if isinstance(field_value, dict): new_val = field.message_type._concrete_class(**field_value) try: copy.MergeFrom(new_val) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name) self._fields[field] = copy else: if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = _GetIntegerEnumValue(field.enum_type, field_value) try: setattr(self, field_name, field_value) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
def ByteSize(
self)
def ByteSize(self): if not self._cached_byte_size_dirty: return self._cached_byte_size size = 0 for field_descriptor, field_value in self.ListFields(): size += field_descriptor._sizer(field_value) for tag_bytes, value_bytes in self._unknown_fields: size += len(tag_bytes) + len(value_bytes) self._cached_byte_size = size self._cached_byte_size_dirty = False self._listener_for_children.dirty = False return size
def Clear(
self)
def _Clear(self): # Clear fields. self._fields = {} self._unknown_fields = () self._oneofs = {} self._Modified()
def ClearExtension(
self, extension_handle)
def ClearExtension(self, extension_handle): raise NotImplementedError
def ClearField(
self, field_name)
def ClearField(self, field_name): try: field = message_descriptor.fields_by_name[field_name] except KeyError: try: field = message_descriptor.oneofs_by_name[field_name] if field in self._oneofs: field = self._oneofs[field] else: return except KeyError: raise ValueError('Protocol message %s() has no "%s" field.' % (message_descriptor.name, field_name)) if field in self._fields: # To match the C++ implementation, we need to invalidate iterators # for map fields when ClearField() happens. if hasattr(self._fields[field], 'InvalidateIterators'): self._fields[field].InvalidateIterators() # Note: If the field is a sub-message, its listener will still point # at us. That's fine, because the worst than can happen is that it # will call _Modified() and invalidate our byte size. Big deal. del self._fields[field] if self._oneofs.get(field.containing_oneof, None) is field: del self._oneofs[field.containing_oneof] # Always call _Modified() -- even if nothing was changed, this is # a mutating method, and thus calling it should cause the field to become # present in the parent message. self._Modified()
def CopyFrom(
self, other_msg)
Copies the content of the specified message into the current message.
The method clears the current message and then merges the specified message using MergeFrom.
Args: other_msg: Message to copy into the current one.
def CopyFrom(self, other_msg): """Copies the content of the specified message into the current message. The method clears the current message and then merges the specified message using MergeFrom. Args: other_msg: Message to copy into the current one. """ if self is other_msg: return self.Clear() self.MergeFrom(other_msg)
def DiscardUnknownFields(
self)
def _DiscardUnknownFields(self): self._unknown_fields = [] for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: for sub_message in value: sub_message.DiscardUnknownFields() else: value.DiscardUnknownFields()
def FindInitializationErrors(
self)
Finds required fields which are not initialized.
Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz".
def FindInitializationErrors(self): """Finds required fields which are not initialized. Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz". """ errors = [] # simplify things for field in required_fields: if not self.HasField(field.name): errors.append(field.name) for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.is_extension: name = "(%s)" % field.full_name else: name = field.name if _IsMapField(field): if _IsMessageMapField(field): for key in value: element = value[key] prefix = "%s[%s]." % (name, key) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: # ScalarMaps can't have any initialization errors. pass elif field.label == _FieldDescriptor.LABEL_REPEATED: for i in range(len(value)): element = value[i] prefix = "%s[%d]." % (name, i) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: prefix = name + "." sub_errors = value.FindInitializationErrors() errors += [prefix + error for error in sub_errors] return errors
def FromString(
s)
def FromString(s): message = cls() message.MergeFromString(s) return message
def HasExtension(
self, extension_handle)
def HasExtension(self, extension_handle): raise NotImplementedError
def HasField(
self, field_name)
def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields
def IsInitialized(
self, errors=None)
Checks if all required fields of a message are set.
Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields.
Returns: True iff the specified message has all required fields set.
def IsInitialized(self, errors=None): """Checks if all required fields of a message are set. Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields. Returns: True iff the specified message has all required fields set. """ # Performance is critical so we avoid HasField() and ListFields(). for field in required_fields: if (field not in self._fields or (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and not self._fields[field]._is_present_in_parent)): if errors is not None: errors.extend(self.FindInitializationErrors()) return False for field, value in list(self._fields.items()): # dict can change size! if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: if (field.message_type.has_options and field.message_type.GetOptions().map_entry): continue for element in value: if not element.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False elif value._is_present_in_parent and not value.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False return True
def ListFields(
self)
def ListFields(self): all_fields = [item for item in self._fields.items() if _IsPresent(item)] all_fields.sort(key = lambda item: item[0].number) return all_fields
def MergeFrom(
self, msg)
def MergeFrom(self, msg): if not isinstance(msg, cls): raise TypeError( "Parameter to MergeFrom() must be instance of same class: " 'expected %s got %s.' % (cls.__name__, msg.__class__.__name__)) assert msg is not self self._Modified() fields = self._fields for field, value in msg._fields.items(): if field.label == LABEL_REPEATED: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) elif field.cpp_type == CPPTYPE_MESSAGE: if value._is_present_in_parent: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) else: self._fields[field] = value if field.containing_oneof: self._UpdateOneofState(field) if msg._unknown_fields: if not self._unknown_fields: self._unknown_fields = [] self._unknown_fields.extend(msg._unknown_fields)
def MergeFromString(
self, serialized)
def MergeFromString(self, serialized): length = len(serialized) try: if self._InternalParse(serialized, 0, length) != length: # The only reason _InternalParse would return early is if it # encountered an end-group tag. raise message_mod.DecodeError('Unexpected end-group tag.') except (IndexError, TypeError): # Now ord(buf[p:p+1]) == ord('') gets TypeError. raise message_mod.DecodeError('Truncated message.') except struct.error as e: raise message_mod.DecodeError(e) return length # Return this for legacy reasons.
def ParseFromString(
self, serialized)
Parse serialized protocol buffer data into this message.
Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns.
def ParseFromString(self, serialized): """Parse serialized protocol buffer data into this message. Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns. """ self.Clear() self.MergeFromString(serialized)
def RegisterExtension(
extension_handle)
def RegisterExtension(extension_handle): extension_handle.containing_type = cls.DESCRIPTOR # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available. cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle) _AttachFieldHelpers(cls, extension_handle)
def SerializePartialToString(
self)
def SerializePartialToString(self): out = BytesIO() self._InternalSerialize(out.write) return out.getvalue()
def SerializeToString(
self)
def SerializeToString(self): # Check if the message has all of its required fields set. errors = [] if not self.IsInitialized(): raise message_mod.EncodeError( 'Message %s is missing required fields: %s' % ( self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors()))) return self.SerializePartialToString()
def SetInParent(
self)
Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.
def Modified(self): """Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. """ # Note: Some callers check _cached_byte_size_dirty before calling # _Modified() as an extra optimization. So, if this method is ever # changed such that it does stuff even when _cached_byte_size_dirty is # already true, the callers need to be updated. if not self._cached_byte_size_dirty: self._cached_byte_size_dirty = True self._listener_for_children.dirty = True self._is_present_in_parent = True self._listener.Modified()
def WhichOneof(
self, oneof_name)
Returns the name of the currently set field inside a oneof, or None.
def WhichOneof(self, oneof_name): """Returns the name of the currently set field inside a oneof, or None.""" try: field = message_descriptor.oneofs_by_name[oneof_name] except KeyError: raise ValueError( 'Protocol message has no oneof "%s" field.' % oneof_name) nested_field = self._oneofs.get(field, None) if nested_field is not None and self.HasField(nested_field.name): return nested_field.name else: return None
Instance variables
var endCharOffset
Magic attribute generated for "endCharOffset" proto field.
var form
Magic attribute generated for "form" proto field.
var startCharOffset
Magic attribute generated for "startCharOffset" proto field.
class ViewDataProto
Abstract base class for protocol messages.
Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.
TODO(robinson): Link to an HTML document here.
TODO(robinson): Document that instances of this class will also have an Extensions attribute with getitem and setitem. Again, not sure how to best convey this.
TODO(robinson): Document that the class must also have a static RegisterExtension(extension_field) method. Not sure how to best express at this point.
Ancestors (in MRO)
- ViewDataProto
- google.protobuf.message.Message
- builtins.object
Class variables
var CONSTITUENTS_FIELD_NUMBER
var DESCRIPTOR
var GENERATOR_FIELD_NUMBER
var RELATIONS_FIELD_NUMBER
var SCORE_FIELD_NUMBER
var VIEWNAME_FIELD_NUMBER
var VIEWTYPE_FIELD_NUMBER
Static methods
def __init__(
self, **kwargs)
def init(self, **kwargs): self._cached_byte_size = 0 self._cached_byte_size_dirty = len(kwargs) > 0 self._fields = {} # Contains a mapping from oneof field descriptors to the descriptor # of the currently set field in that oneof field. self._oneofs = {} # _unknown_fields is () when empty for efficiency, and will be turned into # a list if fields are added. self._unknown_fields = () self._is_present_in_parent = False self._listener = message_listener_mod.NullMessageListener() self._listener_for_children = _Listener(self) for field_name, field_value in kwargs.items(): field = _GetFieldByName(message_descriptor, field_name) if field is None: raise TypeError("%s() got an unexpected keyword argument '%s'" % (message_descriptor.name, field_name)) if field_value is None: # field=None is the same as no field at all. continue if field.label == _FieldDescriptor.LABEL_REPEATED: copy = field._default_constructor(self) if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: # Composite if _IsMapField(field): if _IsMessageMapField(field): for key in field_value: copy[key].MergeFrom(field_value[key]) else: copy.update(field_value) else: for val in field_value: if isinstance(val, dict): copy.add(**val) else: copy.add().MergeFrom(val) else: # Scalar if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = [_GetIntegerEnumValue(field.enum_type, val) for val in field_value] copy.extend(field_value) self._fields[field] = copy elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: copy = field._default_constructor(self) new_val = field_value if isinstance(field_value, dict): new_val = field.message_type._concrete_class(**field_value) try: copy.MergeFrom(new_val) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name) self._fields[field] = copy else: if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = _GetIntegerEnumValue(field.enum_type, field_value) try: setattr(self, field_name, field_value) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
def ByteSize(
self)
def ByteSize(self): if not self._cached_byte_size_dirty: return self._cached_byte_size size = 0 for field_descriptor, field_value in self.ListFields(): size += field_descriptor._sizer(field_value) for tag_bytes, value_bytes in self._unknown_fields: size += len(tag_bytes) + len(value_bytes) self._cached_byte_size = size self._cached_byte_size_dirty = False self._listener_for_children.dirty = False return size
def Clear(
self)
def _Clear(self): # Clear fields. self._fields = {} self._unknown_fields = () self._oneofs = {} self._Modified()
def ClearExtension(
self, extension_handle)
def ClearExtension(self, extension_handle): raise NotImplementedError
def ClearField(
self, field_name)
def ClearField(self, field_name): try: field = message_descriptor.fields_by_name[field_name] except KeyError: try: field = message_descriptor.oneofs_by_name[field_name] if field in self._oneofs: field = self._oneofs[field] else: return except KeyError: raise ValueError('Protocol message %s() has no "%s" field.' % (message_descriptor.name, field_name)) if field in self._fields: # To match the C++ implementation, we need to invalidate iterators # for map fields when ClearField() happens. if hasattr(self._fields[field], 'InvalidateIterators'): self._fields[field].InvalidateIterators() # Note: If the field is a sub-message, its listener will still point # at us. That's fine, because the worst than can happen is that it # will call _Modified() and invalidate our byte size. Big deal. del self._fields[field] if self._oneofs.get(field.containing_oneof, None) is field: del self._oneofs[field.containing_oneof] # Always call _Modified() -- even if nothing was changed, this is # a mutating method, and thus calling it should cause the field to become # present in the parent message. self._Modified()
def CopyFrom(
self, other_msg)
Copies the content of the specified message into the current message.
The method clears the current message and then merges the specified message using MergeFrom.
Args: other_msg: Message to copy into the current one.
def CopyFrom(self, other_msg): """Copies the content of the specified message into the current message. The method clears the current message and then merges the specified message using MergeFrom. Args: other_msg: Message to copy into the current one. """ if self is other_msg: return self.Clear() self.MergeFrom(other_msg)
def DiscardUnknownFields(
self)
def _DiscardUnknownFields(self): self._unknown_fields = [] for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: for sub_message in value: sub_message.DiscardUnknownFields() else: value.DiscardUnknownFields()
def FindInitializationErrors(
self)
Finds required fields which are not initialized.
Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz".
def FindInitializationErrors(self): """Finds required fields which are not initialized. Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz". """ errors = [] # simplify things for field in required_fields: if not self.HasField(field.name): errors.append(field.name) for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.is_extension: name = "(%s)" % field.full_name else: name = field.name if _IsMapField(field): if _IsMessageMapField(field): for key in value: element = value[key] prefix = "%s[%s]." % (name, key) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: # ScalarMaps can't have any initialization errors. pass elif field.label == _FieldDescriptor.LABEL_REPEATED: for i in range(len(value)): element = value[i] prefix = "%s[%d]." % (name, i) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: prefix = name + "." sub_errors = value.FindInitializationErrors() errors += [prefix + error for error in sub_errors] return errors
def FromString(
s)
def FromString(s): message = cls() message.MergeFromString(s) return message
def HasExtension(
self, extension_handle)
def HasExtension(self, extension_handle): raise NotImplementedError
def HasField(
self, field_name)
def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields
def IsInitialized(
self, errors=None)
Checks if all required fields of a message are set.
Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields.
Returns: True iff the specified message has all required fields set.
def IsInitialized(self, errors=None): """Checks if all required fields of a message are set. Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields. Returns: True iff the specified message has all required fields set. """ # Performance is critical so we avoid HasField() and ListFields(). for field in required_fields: if (field not in self._fields or (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and not self._fields[field]._is_present_in_parent)): if errors is not None: errors.extend(self.FindInitializationErrors()) return False for field, value in list(self._fields.items()): # dict can change size! if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: if (field.message_type.has_options and field.message_type.GetOptions().map_entry): continue for element in value: if not element.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False elif value._is_present_in_parent and not value.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False return True
def ListFields(
self)
def ListFields(self): all_fields = [item for item in self._fields.items() if _IsPresent(item)] all_fields.sort(key = lambda item: item[0].number) return all_fields
def MergeFrom(
self, msg)
def MergeFrom(self, msg): if not isinstance(msg, cls): raise TypeError( "Parameter to MergeFrom() must be instance of same class: " 'expected %s got %s.' % (cls.__name__, msg.__class__.__name__)) assert msg is not self self._Modified() fields = self._fields for field, value in msg._fields.items(): if field.label == LABEL_REPEATED: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) elif field.cpp_type == CPPTYPE_MESSAGE: if value._is_present_in_parent: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) else: self._fields[field] = value if field.containing_oneof: self._UpdateOneofState(field) if msg._unknown_fields: if not self._unknown_fields: self._unknown_fields = [] self._unknown_fields.extend(msg._unknown_fields)
def MergeFromString(
self, serialized)
def MergeFromString(self, serialized): length = len(serialized) try: if self._InternalParse(serialized, 0, length) != length: # The only reason _InternalParse would return early is if it # encountered an end-group tag. raise message_mod.DecodeError('Unexpected end-group tag.') except (IndexError, TypeError): # Now ord(buf[p:p+1]) == ord('') gets TypeError. raise message_mod.DecodeError('Truncated message.') except struct.error as e: raise message_mod.DecodeError(e) return length # Return this for legacy reasons.
def ParseFromString(
self, serialized)
Parse serialized protocol buffer data into this message.
Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns.
def ParseFromString(self, serialized): """Parse serialized protocol buffer data into this message. Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns. """ self.Clear() self.MergeFromString(serialized)
def RegisterExtension(
extension_handle)
def RegisterExtension(extension_handle): extension_handle.containing_type = cls.DESCRIPTOR # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available. cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle) _AttachFieldHelpers(cls, extension_handle)
def SerializePartialToString(
self)
def SerializePartialToString(self): out = BytesIO() self._InternalSerialize(out.write) return out.getvalue()
def SerializeToString(
self)
def SerializeToString(self): # Check if the message has all of its required fields set. errors = [] if not self.IsInitialized(): raise message_mod.EncodeError( 'Message %s is missing required fields: %s' % ( self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors()))) return self.SerializePartialToString()
def SetInParent(
self)
Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.
def Modified(self): """Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. """ # Note: Some callers check _cached_byte_size_dirty before calling # _Modified() as an extra optimization. So, if this method is ever # changed such that it does stuff even when _cached_byte_size_dirty is # already true, the callers need to be updated. if not self._cached_byte_size_dirty: self._cached_byte_size_dirty = True self._listener_for_children.dirty = True self._is_present_in_parent = True self._listener.Modified()
def WhichOneof(
self, oneof_name)
Returns the name of the currently set field inside a oneof, or None.
def WhichOneof(self, oneof_name): """Returns the name of the currently set field inside a oneof, or None.""" try: field = message_descriptor.oneofs_by_name[oneof_name] except KeyError: raise ValueError( 'Protocol message has no oneof "%s" field.' % oneof_name) nested_field = self._oneofs.get(field, None) if nested_field is not None and self.HasField(nested_field.name): return nested_field.name else: return None
Instance variables
var constituents
Magic attribute generated for "constituents" proto field.
var generator
Magic attribute generated for "generator" proto field.
var relations
Magic attribute generated for "relations" proto field.
var score
Magic attribute generated for "score" proto field.
var viewName
Magic attribute generated for "viewName" proto field.
var viewType
Magic attribute generated for "viewType" proto field.
class ViewProto
Abstract base class for protocol messages.
Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.
TODO(robinson): Link to an HTML document here.
TODO(robinson): Document that instances of this class will also have an Extensions attribute with getitem and setitem. Again, not sure how to best convey this.
TODO(robinson): Document that the class must also have a static RegisterExtension(extension_field) method. Not sure how to best express at this point.
Ancestors (in MRO)
- ViewProto
- google.protobuf.message.Message
- builtins.object
Class variables
var DESCRIPTOR
var VIEWDATA_FIELD_NUMBER
var VIEWNAME_FIELD_NUMBER
Static methods
def __init__(
self, **kwargs)
def init(self, **kwargs): self._cached_byte_size = 0 self._cached_byte_size_dirty = len(kwargs) > 0 self._fields = {} # Contains a mapping from oneof field descriptors to the descriptor # of the currently set field in that oneof field. self._oneofs = {} # _unknown_fields is () when empty for efficiency, and will be turned into # a list if fields are added. self._unknown_fields = () self._is_present_in_parent = False self._listener = message_listener_mod.NullMessageListener() self._listener_for_children = _Listener(self) for field_name, field_value in kwargs.items(): field = _GetFieldByName(message_descriptor, field_name) if field is None: raise TypeError("%s() got an unexpected keyword argument '%s'" % (message_descriptor.name, field_name)) if field_value is None: # field=None is the same as no field at all. continue if field.label == _FieldDescriptor.LABEL_REPEATED: copy = field._default_constructor(self) if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: # Composite if _IsMapField(field): if _IsMessageMapField(field): for key in field_value: copy[key].MergeFrom(field_value[key]) else: copy.update(field_value) else: for val in field_value: if isinstance(val, dict): copy.add(**val) else: copy.add().MergeFrom(val) else: # Scalar if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = [_GetIntegerEnumValue(field.enum_type, val) for val in field_value] copy.extend(field_value) self._fields[field] = copy elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: copy = field._default_constructor(self) new_val = field_value if isinstance(field_value, dict): new_val = field.message_type._concrete_class(**field_value) try: copy.MergeFrom(new_val) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name) self._fields[field] = copy else: if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: field_value = _GetIntegerEnumValue(field.enum_type, field_value) try: setattr(self, field_name, field_value) except TypeError: _ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
def ByteSize(
self)
def ByteSize(self): if not self._cached_byte_size_dirty: return self._cached_byte_size size = 0 for field_descriptor, field_value in self.ListFields(): size += field_descriptor._sizer(field_value) for tag_bytes, value_bytes in self._unknown_fields: size += len(tag_bytes) + len(value_bytes) self._cached_byte_size = size self._cached_byte_size_dirty = False self._listener_for_children.dirty = False return size
def Clear(
self)
def _Clear(self): # Clear fields. self._fields = {} self._unknown_fields = () self._oneofs = {} self._Modified()
def ClearExtension(
self, extension_handle)
def ClearExtension(self, extension_handle): raise NotImplementedError
def ClearField(
self, field_name)
def ClearField(self, field_name): try: field = message_descriptor.fields_by_name[field_name] except KeyError: try: field = message_descriptor.oneofs_by_name[field_name] if field in self._oneofs: field = self._oneofs[field] else: return except KeyError: raise ValueError('Protocol message %s() has no "%s" field.' % (message_descriptor.name, field_name)) if field in self._fields: # To match the C++ implementation, we need to invalidate iterators # for map fields when ClearField() happens. if hasattr(self._fields[field], 'InvalidateIterators'): self._fields[field].InvalidateIterators() # Note: If the field is a sub-message, its listener will still point # at us. That's fine, because the worst than can happen is that it # will call _Modified() and invalidate our byte size. Big deal. del self._fields[field] if self._oneofs.get(field.containing_oneof, None) is field: del self._oneofs[field.containing_oneof] # Always call _Modified() -- even if nothing was changed, this is # a mutating method, and thus calling it should cause the field to become # present in the parent message. self._Modified()
def CopyFrom(
self, other_msg)
Copies the content of the specified message into the current message.
The method clears the current message and then merges the specified message using MergeFrom.
Args: other_msg: Message to copy into the current one.
def CopyFrom(self, other_msg): """Copies the content of the specified message into the current message. The method clears the current message and then merges the specified message using MergeFrom. Args: other_msg: Message to copy into the current one. """ if self is other_msg: return self.Clear() self.MergeFrom(other_msg)
def DiscardUnknownFields(
self)
def _DiscardUnknownFields(self): self._unknown_fields = [] for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: for sub_message in value: sub_message.DiscardUnknownFields() else: value.DiscardUnknownFields()
def FindInitializationErrors(
self)
Finds required fields which are not initialized.
Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz".
def FindInitializationErrors(self): """Finds required fields which are not initialized. Returns: A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. "foo.bar[5].baz". """ errors = [] # simplify things for field in required_fields: if not self.HasField(field.name): errors.append(field.name) for field, value in self.ListFields(): if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.is_extension: name = "(%s)" % field.full_name else: name = field.name if _IsMapField(field): if _IsMessageMapField(field): for key in value: element = value[key] prefix = "%s[%s]." % (name, key) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: # ScalarMaps can't have any initialization errors. pass elif field.label == _FieldDescriptor.LABEL_REPEATED: for i in range(len(value)): element = value[i] prefix = "%s[%d]." % (name, i) sub_errors = element.FindInitializationErrors() errors += [prefix + error for error in sub_errors] else: prefix = name + "." sub_errors = value.FindInitializationErrors() errors += [prefix + error for error in sub_errors] return errors
def FromString(
s)
def FromString(s): message = cls() message.MergeFromString(s) return message
def HasExtension(
self, extension_handle)
def HasExtension(self, extension_handle): raise NotImplementedError
def HasField(
self, field_name)
def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields
def IsInitialized(
self, errors=None)
Checks if all required fields of a message are set.
Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields.
Returns: True iff the specified message has all required fields set.
def IsInitialized(self, errors=None): """Checks if all required fields of a message are set. Args: errors: A list which, if provided, will be populated with the field paths of all missing required fields. Returns: True iff the specified message has all required fields set. """ # Performance is critical so we avoid HasField() and ListFields(). for field in required_fields: if (field not in self._fields or (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and not self._fields[field]._is_present_in_parent)): if errors is not None: errors.extend(self.FindInitializationErrors()) return False for field, value in list(self._fields.items()): # dict can change size! if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: if field.label == _FieldDescriptor.LABEL_REPEATED: if (field.message_type.has_options and field.message_type.GetOptions().map_entry): continue for element in value: if not element.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False elif value._is_present_in_parent and not value.IsInitialized(): if errors is not None: errors.extend(self.FindInitializationErrors()) return False return True
def ListFields(
self)
def ListFields(self): all_fields = [item for item in self._fields.items() if _IsPresent(item)] all_fields.sort(key = lambda item: item[0].number) return all_fields
def MergeFrom(
self, msg)
def MergeFrom(self, msg): if not isinstance(msg, cls): raise TypeError( "Parameter to MergeFrom() must be instance of same class: " 'expected %s got %s.' % (cls.__name__, msg.__class__.__name__)) assert msg is not self self._Modified() fields = self._fields for field, value in msg._fields.items(): if field.label == LABEL_REPEATED: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) elif field.cpp_type == CPPTYPE_MESSAGE: if value._is_present_in_parent: field_value = fields.get(field) if field_value is None: # Construct a new object to represent this field. field_value = field._default_constructor(self) fields[field] = field_value field_value.MergeFrom(value) else: self._fields[field] = value if field.containing_oneof: self._UpdateOneofState(field) if msg._unknown_fields: if not self._unknown_fields: self._unknown_fields = [] self._unknown_fields.extend(msg._unknown_fields)
def MergeFromString(
self, serialized)
def MergeFromString(self, serialized): length = len(serialized) try: if self._InternalParse(serialized, 0, length) != length: # The only reason _InternalParse would return early is if it # encountered an end-group tag. raise message_mod.DecodeError('Unexpected end-group tag.') except (IndexError, TypeError): # Now ord(buf[p:p+1]) == ord('') gets TypeError. raise message_mod.DecodeError('Truncated message.') except struct.error as e: raise message_mod.DecodeError(e) return length # Return this for legacy reasons.
def ParseFromString(
self, serialized)
Parse serialized protocol buffer data into this message.
Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns.
def ParseFromString(self, serialized): """Parse serialized protocol buffer data into this message. Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns. """ self.Clear() self.MergeFromString(serialized)
def RegisterExtension(
extension_handle)
def RegisterExtension(extension_handle): extension_handle.containing_type = cls.DESCRIPTOR # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available. cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle) _AttachFieldHelpers(cls, extension_handle)
def SerializePartialToString(
self)
def SerializePartialToString(self): out = BytesIO() self._InternalSerialize(out.write) return out.getvalue()
def SerializeToString(
self)
def SerializeToString(self): # Check if the message has all of its required fields set. errors = [] if not self.IsInitialized(): raise message_mod.EncodeError( 'Message %s is missing required fields: %s' % ( self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors()))) return self.SerializePartialToString()
def SetInParent(
self)
Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.
def Modified(self): """Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. """ # Note: Some callers check _cached_byte_size_dirty before calling # _Modified() as an extra optimization. So, if this method is ever # changed such that it does stuff even when _cached_byte_size_dirty is # already true, the callers need to be updated. if not self._cached_byte_size_dirty: self._cached_byte_size_dirty = True self._listener_for_children.dirty = True self._is_present_in_parent = True self._listener.Modified()
def WhichOneof(
self, oneof_name)
Returns the name of the currently set field inside a oneof, or None.
def WhichOneof(self, oneof_name): """Returns the name of the currently set field inside a oneof, or None.""" try: field = message_descriptor.oneofs_by_name[oneof_name] except KeyError: raise ValueError( 'Protocol message has no oneof "%s" field.' % oneof_name) nested_field = self._oneofs.get(field, None) if nested_field is not None and self.HasField(nested_field.name): return nested_field.name else: return None
Instance variables
var viewData
Magic attribute generated for "viewData" proto field.
var viewName
Magic attribute generated for "viewName" proto field.