Add graph edges that will be loaded from a given path. Args: source (string): Data source path where to load the edges. edge_type (tuple): A tuple of (src_type, dst_type, edge_type) that indicates types of the edges. decoder (Decoder): A Decoder object to describe the
(self,
source,
edge_type,
decoder=None,
directed=True,
option=None,
mask=utils.Mask.NONE)
| 274 | return self |
| 275 | |
| 276 | def edge(self, |
| 277 | source, |
| 278 | edge_type, |
| 279 | decoder=None, |
| 280 | directed=True, |
| 281 | option=None, |
| 282 | mask=utils.Mask.NONE): |
| 283 | """ Add graph edges that will be loaded from a given path. |
| 284 | |
| 285 | Args: |
| 286 | source (string): Data source path where to load the edges. |
| 287 | edge_type (tuple): A tuple of (src_type, dst_type, edge_type) that |
| 288 | indicates types of the edges. |
| 289 | decoder (Decoder): A Decoder object to describe the data schema. |
| 290 | directed (boolean): Whether edges are directed. |
| 291 | mask (TRAIN | TEST | VAL): Mark the source as TRAIN data, TEST data |
| 292 | or VAL data for the given edge_type in the graph. |
| 293 | """ |
| 294 | if not isinstance(source, str): |
| 295 | raise ValueError('source for edge() must be a string.') |
| 296 | if not isinstance(edge_type, tuple) or len(edge_type) != 3: |
| 297 | raise ValueError("edge_type for edge() must be a tuple of " |
| 298 | "(src_type, dst_tye, edge_type).") |
| 299 | if not decoder: |
| 300 | decoder = data.Decoder() |
| 301 | if not isinstance(decoder, data.Decoder): |
| 302 | raise ValueError('decoder must be an instance of Decoder, got {}' |
| 303 | .format(type(decoder))) |
| 304 | |
| 305 | masked_edge_type = utils.get_mask_type(edge_type[2], mask) |
| 306 | self._edge_decoders[masked_edge_type] = decoder |
| 307 | |
| 308 | self._topology.add(masked_edge_type, edge_type[0], edge_type[1]) |
| 309 | edge_source = self._construct_edge_source( |
| 310 | source, (edge_type[0], edge_type[1], masked_edge_type), |
| 311 | decoder, |
| 312 | direction=pywrap.Direction.ORIGIN, |
| 313 | option=option) |
| 314 | self._edge_sources.append(edge_source) |
| 315 | |
| 316 | if not directed: |
| 317 | self.add_reverse_edges(edge_type, source, decoder, option) |
| 318 | return self |
| 319 | |
| 320 | def _copy_edge_source(self, edge): |
| 321 | result = pywrap.EdgeSource() |