(self, graph_def)
| 332 | return self |
| 333 | |
| 334 | def _from_vineyard(self, graph_def): |
| 335 | self.clear() |
| 336 | vy_info = graph_def_pb2.VineyardInfoPb() |
| 337 | graph_def.extension.Unpack(vy_info) |
| 338 | self._oid_type = vy_info.oid_type |
| 339 | self._vid_type = vy_info.vid_type |
| 340 | # simple graph schema. |
| 341 | if vy_info.vdata_type: |
| 342 | self._vdata_type = unify_type(vy_info.vdata_type) |
| 343 | if vy_info.edata_type: |
| 344 | self._edata_type = unify_type(vy_info.edata_type) |
| 345 | |
| 346 | # property graph schema |
| 347 | if vy_info.property_schema_json: |
| 348 | try: |
| 349 | schema = json.loads(vy_info.property_schema_json) |
| 350 | if schema: |
| 351 | for item in schema["types"]: |
| 352 | |
| 353 | def add_common_attributes(entry, item): |
| 354 | for prop in item["propertyDefList"]: |
| 355 | entry.add_property( |
| 356 | prop["name"], unify_type(prop["data_type"]) |
| 357 | ) |
| 358 | entry._valid_props = item["valid_properties"] |
| 359 | |
| 360 | if item["type"] == "VERTEX": |
| 361 | entry = VertexLabel(item["label"], item["id"]) |
| 362 | assert entry.id == len(self._vertex_labels) |
| 363 | add_common_attributes(entry, item) |
| 364 | self._vertex_labels.append(entry) |
| 365 | self._v_label_index[entry.label] = entry.id |
| 366 | elif item["type"] == "EDGE": |
| 367 | entry = EdgeLabel(item["label"], item["id"]) |
| 368 | assert entry.id == len(self._edge_labels) |
| 369 | for rel in item["rawRelationShips"]: |
| 370 | entry.source(rel["srcVertexLabel"]).destination( |
| 371 | rel["dstVertexLabel"] |
| 372 | ) |
| 373 | add_common_attributes(entry, item) |
| 374 | self._edge_labels.append(entry) |
| 375 | self._e_label_index[entry.label] = entry.id |
| 376 | self._valid_vertices = schema["valid_vertices"] |
| 377 | self._valid_edges = schema["valid_edges"] |
| 378 | except Exception as e: |
| 379 | raise ValueError("Invalid property graph schema") from e |
| 380 | return self |
| 381 | |
| 382 | def _from_mutable_graph(self, graph_def): |
| 383 | graph_info = graph_def_pb2.MutableGraphInfoPb() |
no test coverage detected