7.4.9. Type Classes: NodeType and EdgeTypeΒΆ

The two type classes for node and edge types have the same interface:

class NodeType (graph, type_name)
class EdgeType (graph, type_name)

The constructor takes a graph and a type name. The name must refer to an existing type of the respective kind in the graph. Node and edge type names are case-sensitive.

Note

Refer to Language Schema for a complete reference of all valid node and edge type names. Node and edge types are case-sensitive.

Adding new types, as well as removing or querying existing ones, must be performed using the instance methods of the Graph class.

__eq__(other)
__ne__(other)

The instance methods __eq__ and __ne__ check for the equality and inequality of node or edge types. A type can also be compared with a string, in which case the name of the type is compared with the string. Types are not hashable; therefore, use their names as dictionary keys.

is_of_type(element)
is_of_subtype(element)

The instance method is_of_type takes a node (for NodeType) or an edge (for EdgeType) as an argument and checks whether the element is of this type (and not a subtype). The instance method is_of_subtype includes subtypes (children) of this type in the check.

is_subtype_of(descriptor)

The instance method is_subtype_of takes a type descriptor or a type name as an argument and checks whether the type itself is the specified type or one of its subtypes (children). Unlike the two methods above, it compares two types, so no element is required.

graph()

The instance method graph returns the graph to which the type belongs.

name()

The instance method name returns the name of the type.

parent()

The instance method parent returns the parent type, or None if the type has no parent type.

__str__()

The instance method __str__ returns a textual representation of the type (for debugging purposes only).