Hold meta informations of an edge label. An Edge label may be consist of a few `EdgeSubLabel`s. i.e. src_label1 -> edge_label -> dst_label1 src_label2 -> edge_label -> dst_label2 src_label3 -> edge_label -> dst_label3
| 246 | |
| 247 | |
| 248 | class EdgeLabel(object): |
| 249 | """Hold meta informations of an edge label. |
| 250 | An Edge label may be consist of a few `EdgeSubLabel`s. |
| 251 | i.e. src_label1 -> edge_label -> dst_label1 |
| 252 | src_label2 -> edge_label -> dst_label2 |
| 253 | src_label3 -> edge_label -> dst_label3 |
| 254 | """ |
| 255 | |
| 256 | def __init__(self, label: str, id_type: str, session_id=None): |
| 257 | self.label = label |
| 258 | # type of vertex original id |
| 259 | # should be consistent with the original graph |
| 260 | self.id_type = id_type |
| 261 | self.sub_labels = {} |
| 262 | self._session_id = session_id |
| 263 | |
| 264 | def __str__(self): |
| 265 | s = "\ntype: EdgeLabel" |
| 266 | s += "\nlabel: " + self.label |
| 267 | s += "\nsub_labels: " |
| 268 | for sub_label in self.sub_labels.values(): |
| 269 | s += "\n" |
| 270 | s += str(sub_label) |
| 271 | return s |
| 272 | |
| 273 | def __repr__(self): |
| 274 | return self.__str__() |
| 275 | |
| 276 | def add_sub_label(self, sub_label): |
| 277 | src = sub_label.src_label |
| 278 | dst = sub_label.dst_label |
| 279 | if (src, dst) in self.sub_labels: |
| 280 | raise ValueError( |
| 281 | f"The relationship {src} -> {self.label} <- {dst} already existed in graph." |
| 282 | ) |
| 283 | self.sub_labels[(src, dst)] = sub_label |
| 284 | |
| 285 | def attr(self) -> Sequence[attr_value_pb2.Chunk]: |
| 286 | chunk_list = [] |
| 287 | for sub_label in self.sub_labels.values(): |
| 288 | chunk = sub_label.get_attr() |
| 289 | chunk.attr[types_pb2.CHUNK_NAME].CopyFrom(utils.s_to_attr("edge")) |
| 290 | chunk.attr[types_pb2.CHUNK_TYPE].CopyFrom(utils.s_to_attr("loader")) |
| 291 | chunk.attr[types_pb2.LABEL].CopyFrom(utils.s_to_attr(self.label)) |
| 292 | chunk_list.append(chunk) |
| 293 | return chunk_list |
| 294 | |
| 295 | |
| 296 | def _convert_array_to_deprecated_form(items): |
no outgoing calls
no test coverage detected