MCPcopy
hub / github.com/dmlc/dgl / __getitem__

Method __getitem__

python/dgl/heterograph.py:2316–2483  ·  view source on GitHub ↗

Return the relation slice of this graph. You can get a relation slice with ``self[srctype, etype, dsttype]``, where ``srctype``, ``etype``, and ``dsttype`` can be either a string or a full slice (``:``) representing wildcard (i.e. any source/edge/destination type).

(self, key)

Source from the content-addressed store, hash-verified

2314 return etypes
2315
2316 def __getitem__(self, key):
2317 """Return the relation slice of this graph.
2318
2319 You can get a relation slice with ``self[srctype, etype, dsttype]``, where
2320 ``srctype``, ``etype``, and ``dsttype`` can be either a string or a full
2321 slice (``:``) representing wildcard (i.e. any source/edge/destination type).
2322
2323 A relation slice is a homogeneous (with one node type and one edge type) or
2324 bipartite (with two node types and one edge type) graph, transformed from
2325 the original heterogeneous graph.
2326
2327 If there is only one canonical edge type found, then the returned relation
2328 slice would be a subgraph induced from the original graph. That is, it is
2329 equivalent to ``self.edge_type_subgraph(etype)``. The node and edge features
2330 of the returned graph would be shared with thew original graph.
2331
2332 If there are multiple canonical edge types found, then the source/edge/destination
2333 node types would be a *concatenation* of original node/edge types. The
2334 new source/destination node type would have the concatenation determined by
2335 :func:`dgl.combine_names() <dgl.combine_names>` called on original source/destination
2336 types as its name. The source/destination node would be formed by concatenating the
2337 common features of the original source/destination types. Therefore they are not
2338 shared with the original graph. Edge type is similar.
2339
2340 Parameters
2341 ----------
2342 key : str or tuple
2343 Either a string representing the edge type name, or a tuple in the form of
2344 ``(srctype, etype, dsttype)`` where ``srctype``, ``etype``, ``dsttype`` can be either
2345 strings representing type names or a full slice object (`:`).
2346
2347 Returns
2348 -------
2349 DGLGraph
2350 The relation slice.
2351
2352 Notes
2353 -----
2354 This function returns a new graph. Changing the content of this graph does not reflect
2355 onto the original graph.
2356
2357 If the graph combines multiple node types or edge types together, it will have the
2358 mapping of node/edge types and IDs from the new graph to the original graph.
2359 The mappings have the name ``dgl.NTYPE``, ``dgl.NID``, ``dgl.ETYPE`` and ``dgl.EID``,
2360 similar to the function :func:`dgl.to_homogenenous`.
2361
2362 Examples
2363 --------
2364 >>> g = dgl.heterograph({
2365 ... ('A1', 'AB1', 'B'): ([0, 1, 2], [1, 2, 3]),
2366 ... ('A1', 'AB2', 'B'): ([1, 2, 3], [3, 4, 5]),
2367 ... ('A2', 'AB2', 'B'): ([1, 3, 5], [2, 4, 6])})
2368 >>> new_g = g['A1', :, 'B'] # combines all edge types between A1 and B
2369 >>> new_g
2370 Graph(num_nodes={'A1': 4, 'B': 7},
2371 num_edges={('A1', 'AB1+AB2', 'B'): 6},
2372 metagraph=[('A1', 'B', 'AB1+AB2')])
2373 >>> new_g.edges()

Callers

nothing calls this directly

Calls 13

_find_etypesMethod · 0.95
get_ntype_id_from_srcMethod · 0.95
get_etype_idMethod · 0.95
get_ntype_id_from_dstMethod · 0.95
DGLErrorClass · 0.85
combine_namesFunction · 0.85
combine_framesFunction · 0.85
formatMethod · 0.80
get_relation_graphMethod · 0.80
flatten_relationsMethod · 0.80
asnumpyMethod · 0.80
number_of_ntypesMethod · 0.80

Tested by

no test coverage detected