3.1.7.1. dg/DG¶
3.1.7.1.1. Class DG
¶

class
mod.
DG
¶ The main derivation graph class. A derivation graph is a directed hypergraph \(H = (V, E)\). Each vertex is annotated with a graph, and each hyperedge is annotated with a transformation rule. A derivation graph can either be calculated from a strategy or loaded from external data.

numVertices
¶ (Readonly) The number of vertices in the derivation graph.
Type: int Raises: LogicError
if the DG has not been calculated.

vertices
¶ (Readonly) An iterable of all vertices in the derivation graph.
Type: DGVertexRange Raises: LogicError
if the DG has not been calculated.

numEdges
¶ (Readonly) The number of hyperedges in the derivation graph.
Type: int Raises: LogicError
if the DG has not been calculated.

edges
¶ (Readonly) An iterable of all hyperedges in the derivation graph.
Type: DGEdgeRange Raises: LogicError
if the DG has not been calculated.

findVertex
(g)¶ Parameters: g ( Graph
) – the graph to find a vertex which has it associated.Returns: a vertex descriptor for which the given graph is associated, or a null descriptor if no such vertex exists. Return type: DGVertex

findEdge
(sources, targets)¶ 
findEdge
(sourceGraphs, targetGraphs) Parameters:  sources (list of
DGVertex
) – the list of source vertices the resulting hyperedge must have.  targets (list of
DGVertex
) – the list of targets vertices the resulting hyperedge must have.  sourceGraphs (list of
Graph
) – the list of graphs that must be associated with the source vertices the resulting hyperedge must have.  targetGraphs (list of
Graph
) – the list of graphs that must be associated with the targets vertices the resulting hyperedge must have.
Returns: a hyperedge with the given sources and targets. If no such hyperedge exists in the derivation graph then a null edge is returned. In the second version, the graphs are put through
findVertex()
first.Raises: LogicError
if a vertex descriptor is null, or does not belong to the derivation graph. sources (list of

calc
()¶ Create the actual derivation graph.
Raises: LogicError
if created fromdgRuleComp
and a dynamic add strategy adds a graph isomorphic to an already known graph, but represented by a different object.

graphDatabase
¶ All graphs known to the derivation graph.
Type: list of

products
¶ The subset of the vertex graphs which were discovered by the calculation.
Type: list of

print
(printer=DGPrinter(), data=None)¶ Print the derivation graph in style of a hypergraph. The appearance and structure of the visualisation can optionally be configured by giving a DG printer and/or data object.
Parameters:  printer (
DGPrinter
) – the printer to use governing the appearance.  data (
DGPrintData
) – the extra data to use encoding the structure of the graph.
Returns: the name of the PDFfile that will be compiled in postprocessing.
Return type: string
 printer (

dump
()¶ Export the derivation graph to an external file. The vertex graphs are exported as well.
Returns: the filename of the exported derivation graph. Return type: string Raises: LogicError
if the DG has not been calculated.

list
()¶ List information about the calculation.

listStats
()¶ Lists various statistics for the derivation graph.
Raises: LogicError
if the DG has not been calculated.


mod.
dgDerivations
(ders)¶ Parameters: ders (list of Derivation
) – the list of derivations to include in the derivation graph.Returns: a derivation graph from a list of Derivation
.Return type: DG

mod.
dgAbstract
(s)¶ Parameters: s (string) – the abstract specification of a derivation graph. Returns: Construct a derivation graph from an abstract set of derivations. See dg::DG::abstract()
for the specification format.Return type: DG

mod.
dgRuleComp
(graphs, strat, labelSettings=LabelSettings(LabelType.String, LabelRelation.Isomorphism), ignoreRuleLabelTypes=False)¶ Initialize a derivation graph defined by a strategy.
Parameters:  graphs (list of
Graph
) – an initial graph database. Any derived graph isomorphic to one of these graphs will be replaced by the given graph.  strat (
DGStrat
) – the strategy which will be used for calculating the actual derivation graph.  labelSettings (
LabelSettings
) – the settings to use for monomorphism enumeration and isomorphism checked.  ignoreRuleLabelTypes (bool) – whether the rules in the given strategy should be checked to be in line with the given label type.
Returns: the derivation graph object. The calculation method must be called to create the actual derivation graph.
Return type: Raises: LogicError
if two graphs ingraphs
are different by isomorphic objects, or similarly if a static add strategy adds an isomorphic graph.Raises: LogicError
ifignoreRuleLabelTypes
is False and a rule in the given strategy has an intended label type different from the given type inlabelSettings
. graphs (list of

mod.
dgDump
(graphs, rules, file)¶ Load a derivation graph dump.
Parameters: Returns: the loaded derivation graph.
Return type:

mod.
diffDGs
(dg1, dg2)¶ Compare two derivation graphs and lists the difference. This is not a general isomorphism check; two vertices are equal if they have the same graph attached. Edges are equal if the head and tail sets are equal and if the attached rule is the same.
Parameters: