4.1.9.1. dg/Builder¶
- class mod.DGBuilder¶
An RAII-style object obtained from
DG.build()
. On destruction of an active builder object the owningDG
will be locked for further modifications.The object can be used as a context manager:
dg = DG() with dg.build() as b: # b is a DGBuilder # b has now been destructed and dg is locked.
Otherwise one can manually use
del
on the obtained builder to trigger the destruction.- addDerivation(d, graphPolicy=IsomorphismPolicy.Check)¶
Adds a hyperedge corresponding to the given derivation to the associated
DG
. If it already exists, only add the given rules to the edge.- Parameters
d (Derivations) – a derivation to add a hyperedge for.
graphPolicy (IsomorphismPolicy) – the isomorphism policy for adding the given graphs.
- Returns
the hyperedge corresponding to the given derivation.
- Return type
- Raises
LogicError
ifd.left
ord.right
is empty.- Raises
LogicError
if aNone``is in ``d.left
,d.right
, ord.rules
.- Raises
LogicError
ifgraphPolicy == IsomorphismPolicy.Check
and a given graph object is different but isomorphic to another given graph object or to a graph object already in the internal graph database in the associated derivation graph.
- execute(strategy, *, verbosity=2, ignoreRuleLabelTypes=False)¶
Execute the given strategy (Derivation Graph Strategies) and as a side-effect add vertices and hyperedges to the underlying derivation graph.
- Parameters
strategy (DGStrat) – the strategy to execute.
verbosity (int) – the level of verbosity of printed information during calculation. See
dg::Builder::execute()
for explanations of the levels.ignoreRuleLabelTypes (bool) – whether rules in the strategy should be checked beforehand for whether they have an associated
LabelType
which matches the one in the underlying derivation graph.
- Returns
a proxy object for accessing the result of the exeuction.
- Return type
- Throws
LogicError
if a static “add” strategy hasIsomorphismPolicy.Check
as graph policy, and it tries to add a graph object isomorphic to an already known, but different, graph object in the database. This is checked before execution, so there is strong exception guarantee.- Throws
LogicError
if a dynamic “add” strategy hasIsomorphismPolicy.Check
as graph policy, and it tries to add a graph object isomorphic to an already known, but different, graph object in the database.Warning
This is checked during execution, so while the basic exception guarantee is provided, there may be modifications to the underlying derivation graph.
- Throws
LogicError
if a dynamic “add” strategy is executed where a returned graph isNone
.Warning
This is checked during execution, so while the basic exception guarantee is provided, there may be modifications to the underlying derivation graph.
- Throws
LogicError
: ifignoreRuleLabelTypes
isFalse
, which is the default, and a rule in the given strategy has an associatedLabelType
which is different from the one in the derivation graph.
- apply(graphs, r, onlyProper=True, verbosity=0, graphPolicy=IsomorphismPolicy.Check)¶
Compute direct derivations.
- Parameters
graphs (list[Graph]) – the graphs constituting the left-hand side of the computed direct derivations.
onlyProper (bool) – when
True
, then all ofgraphs
must be used in each direct derivation.r (Rule) – the rule to use for the direct derivations.
verbosity (int) – the level of verbosity of printed information during calculation. See
dg::Builder::apply()
for explanations of the levels.graphPolicy (IsomorphismPolicy) – the isomorphism policy for adding the given graphs.
- Returns
a list of hyper edges representing the found direct derivations. The list may contain duplicates if there are multiple ways of constructing the same direct derivation when ignoring the specific match morphism.
- Return type
- Raises
LogicError
if there is aNone
ingraphs
.- Raises
LogicError
ifr
isNone
.- Raises
LogicError
ifgraphPolicy == IsomorphismPolicy.Check
and a given graph object is different but isomorphic to another given graph object or to a graph object already in the internal graph database in the associated derivation graph.
- addAbstract(description)¶
Add vertices and hyperedges based on the given abstract description. The description must adhere to the grammar described at Abstract Derivation Graphs.
For each vertex named in the description a graph object with no vertices will be created, and its name set to the given identifier.
- Parameters
description (str) – the description to parse into abstract derivations.
- Raises
InputError
if the description could not be parsed.
- load(ruleDatabase, f, verbosity=2)¶
Load and add a derivation graph dump. Use
DG.load()
to load a dump as a locked derivation graph.The label settings of this DG and the ones retrieved from the dump file must match. Vertices with graphs and hyperedges with rules are then added from the dump. Any graph in the dump which is isomorphic to a graph in the internal graph database of the DG is replaced by the given graph. The same procedure is done for the rules, but compared against the given rules. If a graph/rule is not found in the given lists, a new object is instantiated and used.
See
dg::DG::load()
for an explanation of the verbosity levels.- Parameters
- Raises
LogicError
if there is aNone
inruleDatabase
.- Raises
LogicError
if the label settings of the dump does not match those of this DG. :raises:InputError
if the file can not be opened or its content is bad.
- class mod.DGExecuteResult¶
The result from calling
DGBuilder.execute()
.- subset¶
- universe¶
(Read-only) Respectively the subset and the universe computed by the strategy execution (see also Derivation Graph Strategies).