dgl.DGLHeteroGraph.to_canonical_etype

DGLHeteroGraph.to_canonical_etype(etype)[source]

Convert edge type to canonical etype: (srctype, etype, dsttype).

The input can already be a canonical tuple.

Parameters:etype (str or tuple of str) – Edge type
Returns:
Return type:tuple of str

Examples

Instantiate a heterograph.

>>> g1 = dgl.graph([(0, 1), (1, 2)], 'user', 'follows')
>>> g2 = dgl.bipartite([(0, 0), (1, 0), (1, 1), (2, 1)], 'user', 'plays', 'game')
>>> g3 = dgl.bipartite([(0, 0), (1, 1)], 'developer', 'follows', 'game')
>>> g = dgl.hetero_from_relations([g1, g2, g3])

Get canonical edge types.

>>> g.to_canonical_etype('plays')
('user', 'plays', 'game')
>>> g.to_canonical_etype(('user', 'plays', 'game'))
('user', 'plays', 'game')
>>> g.to_canonical_etype('follows')
DGLError: Edge type "follows" is ambiguous.
Please use canonical etype type in the form of (srctype, etype, dsttype)