graphrecords.schema#

Schema classes describing the attributes a GraphRecord may hold.

Classes

AttributeDataType(data_type[, attribute_type])

The data type of an attribute together with its statistical type.

AttributeType(value[, names, module, ...])

Enumeration of attribute types.

GroupSchema(*[, nodes, edges])

The node and edge attributes of a single group.

Schema(*[, groups, ungrouped, schema_type])

The attributes of every group of a GraphRecord, and of its ungrouped part.

SchemaType(value[, names, module, qualname, ...])

Enumeration of schema types.

class AttributeDataType(data_type, attribute_type=None)[source]#

Bases: object

The data type of an attribute together with its statistical type.

__eq__(value)[source]#

Checks whether the AttributeDataType is equal to another one.

Parameters:

value (object) – The value to compare.

Return type:

bool

Returns:

bool – True if both describe the same attribute, otherwise False.

__repr__()[source]#

Returns the string representation of the AttributeDataType.

Return type:

str

Returns:

str – The string representation of the AttributeDataType.

property attribute_type: AttributeType#

The statistical type of the attribute.

Returns:

AttributeType – The statistical type of the attribute.

property data_type: DataType#

The data type of the attribute.

Returns:

DataType – The data type of the attribute.

class AttributeType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Enumeration of attribute types.

Categorical = 1#
Continuous = 2#
Temporal = 3#
Unstructured = 4#
classmethod __contains__(value)#

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members. 3) value is a pseudo-member (flags)

classmethod __getitem__(name)#

Return the member matching name.

classmethod __iter__()#

Return members in definition order.

classmethod __len__()#

Return the number of members (no aliases)

__repr__()[source]#

Returns the string representation of the attribute type.

Return type:

str

Returns:

str – The string representation of the attribute type.

__str__()[source]#

Returns a user-friendly string representation of the attribute type.

Return type:

str

Returns:

str – The user-friendly string representation of the attribute type.

static infer(data_type)[source]#

Infers the attribute type from the data type.

Parameters:

data_type (DataType) – The data type to infer the attribute type from.

Return type:

AttributeType

Returns:

AttributeType – The inferred attribute type.

class GroupSchema(*, nodes=None, edges=None)[source]#

Bases: object

The node and edge attributes of a single group.

__eq__(value)[source]#

Checks whether the GroupSchema is equal to another one.

Parameters:

value (object) – The value to compare.

Return type:

bool

Returns:

bool – True if both describe the same attributes, otherwise False.

__repr__()[source]#

Returns the string representation of the GroupSchema.

Return type:

str

Returns:

str – The string representation of the GroupSchema.

property edges: Dict[str | int, AttributeDataType]#

The attributes the edges of the group hold.

Returns:

Dict[AttributeName, AttributeDataType]

The data type of every edge

attribute.

property nodes: Dict[str | int, AttributeDataType]#

The attributes the nodes of the group hold.

Returns:

Dict[AttributeName, AttributeDataType]

The data type of every node

attribute.

validate_edge(edge_index, attributes)[source]#

Validates the attributes of an edge against the group schema.

Parameters:
  • edge_index (EdgeIndex) – The index of the edge.

  • attributes (Attributes) – The attributes of the edge.

Return type:

None

validate_node(node_index, attributes)[source]#

Validates the attributes of a node against the group schema.

Parameters:
  • node_index (NodeIndex) – The index of the node.

  • attributes (Attributes) – The attributes of the node.

Return type:

None

class Schema(*, groups=None, ungrouped=None, schema_type=SchemaType.Provided)[source]#

Bases: object

The attributes of every group of a GraphRecord, and of its ungrouped part.

__eq__(value)[source]#

Checks whether the Schema is equal to another one.

Parameters:

value (object) – The value to compare.

Return type:

bool

Returns:

bool

True if both describe the same groups and attributes, otherwise

False.

__repr__()[source]#

Returns the string representation of the Schema.

Return type:

str

Returns:

str – The string representation of the Schema.

add_group(group_index, group_schema)[source]#

Adds the schema of a group.

Parameters:
  • group_index (GroupIndex) – The group to describe.

  • group_schema (GroupSchema) – The schema of the group.

Return type:

Schema

Returns:

Schema – A Schema describing that group.

freeze()[source]#

Stops the schema from growing with the data written to a GraphRecord.

Return type:

Schema

Returns:

Schema – A frozen Schema.

group(group_index)[source]#

Returns the schema of a single group.

Parameters:

group_index (GroupIndex) – The group to return the schema of.

Return type:

GroupSchema

Returns:

GroupSchema – The schema of the group.

property groups: Dict[str | int, GroupSchema]#

The groups the schema describes.

Returns:

Dict[GroupIndex, GroupSchema] – The schema of every described group.

classmethod infer(graphrecord)[source]#

Infers the schema of a GraphRecord from the data it holds.

Parameters:

graphrecord (GraphRecord) – The GraphRecord to infer the schema from.

Return type:

Schema

Returns:

Schema – The inferred schema.

remove_edge_attribute(attribute_name, group_index=None)[source]#

Removes an edge attribute from the schema.

Parameters:
  • attribute_name (AttributeName) – The name of the attribute to remove.

  • group_index (Optional[GroupIndex]) – The group holding the attribute. Defaults to the ungrouped part.

Return type:

Schema

Returns:

Schema – A Schema without that attribute.

remove_group(group_index)[source]#

Removes the schema of a group.

Parameters:

group_index (GroupIndex) – The group to stop describing.

Return type:

Schema

Returns:

Schema – A Schema without that group.

remove_node_attribute(attribute_name, group_index=None)[source]#

Removes a node attribute from the schema.

Parameters:
  • attribute_name (AttributeName) – The name of the attribute to remove.

  • group_index (Optional[GroupIndex]) – The group holding the attribute. Defaults to the ungrouped part.

Return type:

Schema

Returns:

Schema – A Schema without that attribute.

property schema_type: SchemaType#

Whether the schema was provided or inferred.

Returns:

SchemaType – The type of the schema.

set_edge_attribute(attribute_name, data_type, attribute_type, group_index=None)[source]#

Adds an edge attribute to the schema, overwriting it if it already exists.

Parameters:
  • attribute_name (AttributeName) – The name of the attribute.

  • data_type (DataType) – The data type of the attribute.

  • attribute_type (AttributeType) – The statistical type of the attribute.

  • group_index (Optional[GroupIndex]) – The group to add the attribute to. Defaults to the ungrouped part.

Return type:

Schema

Returns:

Schema – A Schema describing the attribute.

set_node_attribute(attribute_name, data_type, attribute_type, group_index=None)[source]#

Adds a node attribute to the schema, overwriting it if it already exists.

Parameters:
  • attribute_name (AttributeName) – The name of the attribute.

  • data_type (DataType) – The data type of the attribute.

  • attribute_type (AttributeType) – The statistical type of the attribute.

  • group_index (Optional[GroupIndex]) – The group to add the attribute to. Defaults to the ungrouped part.

Return type:

Schema

Returns:

Schema – A Schema describing the attribute.

unfreeze()[source]#

Lets the schema grow with the data written to a GraphRecord again.

Return type:

Schema

Returns:

Schema – An unfrozen Schema.

property ungrouped: GroupSchema#

The schema of everything outside a group.

Returns:

GroupSchema – The schema of the ungrouped part.

update_edge_attribute(attribute_name, data_type, attribute_type, group_index=None)[source]#

Widens an edge attribute of the schema to also cover the given types.

Parameters:
  • attribute_name (AttributeName) – The name of the attribute.

  • data_type (DataType) – The data type to cover as well.

  • attribute_type (AttributeType) – The statistical type of the attribute.

  • group_index (Optional[GroupIndex]) – The group holding the attribute. Defaults to the ungrouped part.

Return type:

Schema

Returns:

Schema – A Schema describing the widened attribute.

update_node_attribute(attribute_name, data_type, attribute_type, group_index=None)[source]#

Widens a node attribute of the schema to also cover the given types.

Parameters:
  • attribute_name (AttributeName) – The name of the attribute.

  • data_type (DataType) – The data type to cover as well.

  • attribute_type (AttributeType) – The statistical type of the attribute.

  • group_index (Optional[GroupIndex]) – The group holding the attribute. Defaults to the ungrouped part.

Return type:

Schema

Returns:

Schema – A Schema describing the widened attribute.

validate_edge(edge_index, attributes, group_index=None)[source]#

Validates the attributes of an edge against the schema.

Parameters:
  • edge_index (EdgeIndex) – The index of the edge.

  • attributes (Attributes) – The attributes of the edge.

  • group_index (Optional[GroupIndex]) – The group the edge belongs to. Defaults to the ungrouped part.

Return type:

None

validate_node(node_index, attributes, group_index=None)[source]#

Validates the attributes of a node against the schema.

Parameters:
  • node_index (NodeIndex) – The index of the node.

  • attributes (Attributes) – The attributes of the node.

  • group_index (Optional[GroupIndex]) – The group the node belongs to. Defaults to the ungrouped part.

Return type:

None

class SchemaType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Enumeration of schema types.

Inferred = 2#
Provided = 1#
classmethod __contains__(value)#

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members. 3) value is a pseudo-member (flags)

classmethod __getitem__(name)#

Return the member matching name.

classmethod __iter__()#

Return members in definition order.

classmethod __len__()#

Return the number of members (no aliases)

__repr__()[source]#

Returns the string representation of the schema type.

Return type:

str

Returns:

str – The string representation of the schema type.

__str__()[source]#

Returns a user-friendly string representation of the schema type.

Return type:

str

Returns:

str – The user-friendly string representation of the schema type.