Class S3MultiPath
source code
Simplified path toolkit for managing multi-ancestor-hypergraphs
in a relational database.
MultiPaths allow single-query searches for all ancestors and
descendants of a node, as well as single-query affiliation
testing - whereas they require multiple writes on update (one
per each descendant node), so they should only be used for
hypergraphs which rarely change.
Every node of the hypergraph contains a path attribute, with the
following MultiPath-syntax:
MultiPath: <SimplePath>,<SimplePath>,...
SimplePath: [|<Node>|<Node>|...|]
Node: ID of the ancestor node
SimplePaths contain only ancestors, not the node itself.
SimplePaths contain the ancestors in reverse order, i.e. the nearest
ancestor first (this is important because removing a vertex from the
path will cut off the tail, not the head)
A path like A<-B<-C can be constructed like:
path = S3MultiPath([["C", "B", "A"]])
[|C|B|A|]
Extending this path by a vertex E<-B will result in a multipath like:
path.extend("B", "E")
[|C|B|A|],[|C|B|E|]
Cutting the vertex A<-B reduces the multipath to:
path.cut("B", "A")
[|C|B|E|]
Note the reverse notation (nearest ancestor first)!
MultiPaths will be normalized automatically, i.e.:
path = S3MultiPath([["C", "B", "A", "D", "F", "B", "E", "G"]])
[|C|B|A|D|F|],[|C|B|E|G|]
|
|
|
|
|
|
|
|
extend(self,
head,
ancestors=None,
cut=None)
Extend this multi-path with a new vertex ancestors<-head |
source code
|
|
|
|
cut(self,
head,
ancestor=None)
Cut off the vertex ancestor<-head in this multi-path |
source code
|
|
|
|
clean(self)
Remove any duplicate and empty paths from this multi-path |
source code
|
|
|
|
|
|
|
|
|
|
|
|
|
__and__(self,
sequence)
Check whether sequence is the start sequence of any of the paths in
this multi-path (for de-duplication) |
source code
|
|
|
|
__contains__(self,
sequence)
Check whether sequence is contained in any of the paths (can also be
used to check whether this multi-path contains a path to a particular
node) |
source code
|
|
|
|
|
|
Append a new ancestor path to this multi-path
- Parameters:
|
extend(self,
head,
ancestors=None,
cut=None)
| source code
|
Extend this multi-path with a new vertex ancestors<-head
- Parameters:
head - the head node
ancestors - the ancestor (multi-)path of the head node
|
|
Cut off the vertex ancestor<-head in this multi-path
- Parameters:
head - the head node
ancestor - the ancestor node to cut off
|
|
Remove any duplicate and empty paths from this multi-path
|
|
Serialize this multi-path as string
|
|
Return this multi-path as list of node lists
|
|
The number of paths in this multi-path
|
|
Check whether sequence is the start sequence of any of the paths in
this multi-path (for de-duplication)
- Parameters:
sequence - sequence of node IDs (or path)
|
|
Check whether sequence is contained in any of the paths (can also be
used to check whether this multi-path contains a path to a particular
node)
- Parameters:
sequence - the sequence (or node ID)
|
|
Get all nodes from this path
|
|
Get all nodes from all paths
- Parameters:
paths - list of multi-paths
|