README
Rewrite
Tools for replacing parts of a graph.
Usage
The generic replacement method is
g1 = API.apply(g, set, matcher, generator)
g
is a graphset
is an arbitrary set of candidates for the matchermatcher
takes a candidate and the graph and returns false iff there is no match, otherwise the return value is arbitrarygenerator
takes the return value of the matcher and the graph and returns a new graph
A few candidate sets are provided:
g1 = API.applyNode(matcher, generator)(g)
g2 = API.applyEdge(matcher, generator)(g)
g3 = API.applyPort(matcher, generator)(g)
g4 = API.applyComponent(matcher, generator)(g)
These replacement rules can be iterated like this:
// matches nothing
const rule1 = API.applyNode((node, g) => false, (match, g) => null)
// matches everything, does nothing
const ruleTrivial = API.applyNode((node, g) => true, (match, g) => g)
const rewriter = API.rewrite([rule1, rule2], maxIterations)
g1 = rewriter(g)
where maxIterations
is optional (default: Infinity
)
Written with StackEdit.