sketchgraphs.data.sequence

This module contains the implementation for the “sequence” projection of SketchGraphs.

The sequence projection (consisting of NodeOp representing entities, and EdgeOp representing constraints), is a streamlined representation of sketches, adapted for machine learning applications.

Classes

EdgeOp(label, references, …], parameters)

This class represents an edge (or constraint) operation in a construction sequence.

NodeOp(label, parameters)

This class represents a node (or entity) operation in a construction sequence.

Functions

sketchgraphs.data.sequence.pgvgraph_from_sequence(seq)

Builds a pgv.AGraph from the sequence.

Hyperedges are not supported in the resulting graph.

Parameters

seq (List[Union[NodeOp, EdgeOp]]) – A construction sequence representing a sketch.

Returns

A pygraphviz AGraph corresponding to the given sequence.

Return type

pgv.AGraph

sketchgraphs.data.sequence.sketch_from_sequence(seq)sketchgraphs.data.sketch.Sketch

Builds a Sketch object from the given sequence.

Parameters

seq (List[Union[NodeOp, EdgeOp]]) – A construction sequence representing a sketch.

Returns

A sketch object representing the given construction sequence.

Return type

Sketch

sketchgraphs.data.sequence.sketch_to_sequence(sketch, ignore_invalid_constraints=True)List[Union[sketchgraphs.data.sequence.NodeOp, sketchgraphs.data.sequence.EdgeOp]]

Creates a sequence representation in terms of NodeOp and EdgeOp from the given sketch.

All the entities in the sketch are converted, along with the respective constraints. Constraints are expressed in terms of entity indices (instead of original string identifiers). The sequence is ordered such that the nodes are in original insertion order, and the edges are placed such that they directly follow the last node they reference.

Parameters
  • sketch (Sketch) – The sketch object to convert to sequence.

  • ignore_invalid_constraints (bool) – If True, indicates that invalid constraints should be ignored. Otherwise, raises a ValueError on encountering an invalid constraint.

Returns

A list of construction operations

Return type

list

Raises

ValueError – If ignore_invalid_constraints is set to False, a ValueError will be raised upon encountering invalid constraints (e.g. constraints which refer to non-existing nodes, or whose parameters cannot be processed according to the specified schema).