Hold schema of a graph. Attributes: oid_type (str): Original ID type vid_type (str): Internal ID representation vdata_type (str): Type of the data that holding by vertex (simple graph only) edata_type (str): Type of the data that holding by edge (simple graph onl
| 247 | |
| 248 | |
| 249 | class GraphSchema: |
| 250 | """Hold schema of a graph. |
| 251 | |
| 252 | Attributes: |
| 253 | oid_type (str): Original ID type |
| 254 | vid_type (str): Internal ID representation |
| 255 | vdata_type (str): Type of the data that holding by vertex (simple graph only) |
| 256 | edata_type (str): Type of the data that holding by edge (simple graph only) |
| 257 | vertex_labels (list): Label names of vertex |
| 258 | edge_labels (list): Label names of edge |
| 259 | edge_relationships (list(list(tuple))): Source label and destination label of each edge label |
| 260 | """ |
| 261 | |
| 262 | def __init__(self): |
| 263 | self._conn = None |
| 264 | |
| 265 | self._oid_type = None |
| 266 | self._vid_type = None |
| 267 | # simple graph only |
| 268 | self._vdata_type = graph_def_pb2.UNKNOWN |
| 269 | self._edata_type = graph_def_pb2.UNKNOWN |
| 270 | |
| 271 | # list of entries |
| 272 | self._vertex_labels: List[VertexLabel] = [] |
| 273 | self._edge_labels: List[EdgeLabel] = [] |
| 274 | |
| 275 | self._vertex_labels_to_add: List[VertexLabel] = [] |
| 276 | self._edge_labels_to_add: List[EdgeLabel] = [] |
| 277 | self._vertex_labels_to_drop: List[VertexLabel] = [] |
| 278 | self._edge_labels_to_drop: List[EdgeLabel] = [] |
| 279 | self._vertex_labels_to_add_property: List[VertexLabel] = [] |
| 280 | self._edge_labels_to_add_property: List[VertexLabel] = [] |
| 281 | # 1 indicate valid, 0 indicate invalid. |
| 282 | self._valid_vertices = [] |
| 283 | self._valid_edges = [] |
| 284 | |
| 285 | self._v_label_index = {} |
| 286 | self._e_label_index = {} |
| 287 | |
| 288 | def from_graph_def(self, graph_def): |
| 289 | if graph_def.extension.Is(graph_def_pb2.VineyardInfoPb.DESCRIPTOR): |
| 290 | return self._from_vineyard(graph_def) |
| 291 | if graph_def.extension.Is(graph_def_pb2.MutableGraphInfoPb.DESCRIPTOR): |
| 292 | return self._from_mutable_graph(graph_def) |
| 293 | return self._from_store_service(graph_def) |
| 294 | |
| 295 | def _from_store_service(self, graph_def): |
| 296 | """Decode information from proto message, generated by engine. |
| 297 | |
| 298 | Args: |
| 299 | schema_def (`GraphSchemaDef`): Proto message defined in `proto/graph_def.proto`. |
| 300 | |
| 301 | Raises: |
| 302 | ValueError: If the schema is not valid. |
| 303 | """ |
| 304 | self.clear() |
| 305 | id_to_label = {} |
| 306 | for type_def_pb in graph_def.type_defs: |
no outgoing calls
no test coverage detected