graphtage.multiset¶
A module for representing an edit on a multiset.
This is used by graphtage.MultiSetNode
and graphtage.DictNode
, since the latter is a multiset containg
graphtage.KeyValuePairNode
objects.
multiset classes¶
MultiSetEdit¶
-
class
graphtage.multiset.
MultiSetEdit
(from_node: graphtage.sequences.SequenceNode, to_node: graphtage.sequences.SequenceNode, from_set: graphtage.utils.HashableCounter[graphtage.TreeNode][graphtage.TreeNode], to_set: graphtage.utils.HashableCounter[graphtage.TreeNode][graphtage.TreeNode])¶ Bases:
graphtage.sequences.SequenceEdit
An edit matching one unordered collection of items to another.
It works by using a
graphtage.matching.WeightedBipartiteMatcher
to find the minimum cost matching from the elements of one collection to the elements of the other.-
__init__
(from_node: graphtage.sequences.SequenceNode, to_node: graphtage.sequences.SequenceNode, from_set: graphtage.utils.HashableCounter[graphtage.TreeNode][graphtage.TreeNode], to_set: graphtage.utils.HashableCounter[graphtage.TreeNode][graphtage.TreeNode])¶ Initializes the edit.
- Parameters
from_node – Any sequence node from which to match.
to_node – Any sequence node to which to match.
from_set – The set of nodes from which to match. These should typically be children of
from_node
, but this is neither checked nor enforced.to_set – The set of nodes to which to match. These should typically be children of
to_node
, but this is neither checked nor enforced.
-
__iter__
() → Iterator[graphtage.Edit]¶ Returns an iterator over this edit’s sub-edits.
- Returns
The result of
AbstractCompoundEdit.edits()
- Return type
Iterator[Edit]
-
__lt__
(other)¶ Tests whether the bounds of this edit are less than the bounds of
other
.
-
bounds
() → graphtage.bounds.Range¶ Returns the bounds of this edit.
This defaults to the bounds provided when this
AbstractEdit
was constructed. If an upper bound was not provided to the constructor, the upper bound defaults to:self.from_node.total_size + self.to_node.total_size + 1
- Returns
A range bounding the cost of this edit.
- Return type
-
edits
() → Iterator[graphtage.Edit]¶ Returns an iterator over this edit’s sub-edits
-
has_non_zero_cost
() → bool¶ Returns whether this edit has a non-zero cost.
This will tighten the edit’s bounds until either its lower bound is greater than zero or its bounds are definitive.
-
is_complete
() → bool¶ A
MultiSetEdit
is complete after the first call toMultiSetEdit.tighten_bounds()
.
-
on_diff
(from_node: graphtage.EditedTreeNode)¶ A callback for when an edit is assigned to an
EditedTreeNode
inTreeNode.diff()
.This default implementation adds the edit to the node, and recursively calls
Edit.on_diff()
on all of the sub-edits:from_node.edit = self from_node.edit_list.append(self) for edit in self.edits(): edit.on_diff(edit.from_node)
- Parameters
from_node – The edited node that was added to the diff
-
print
(formatter: graphtage.GraphtageFormatter, printer: graphtage.printer.Printer)¶ Prints this edit.
This is equivalent to:
formatter.get_formatter(self.sequence)(printer, self.sequence)
-
property
sequence
¶ Returns the sequence being edited.
This is a convenience function solely to aid in automated type checking. It is equivalent to:
typing.cast(SequenceNode, self.from_node)
-
tighten_bounds
() → bool¶ Delegates to
WeightedBipartiteMatcher.tighten_bounds()
.The matching is complete after the first call to this function, so it also sets
self.is_complete
toTrue
.
-
to_insert
= None¶ The set of nodes in
to_set
that do not exist infrom_set
.
-
to_remove
= None¶ The set of nodes in
from_set
that do not exist into_set
.
-
property
valid
¶ Returns whether this edit is valid
-