Package s3 :: Module s3utils :: Class S3MultiPath
[frames] | no frames]

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|]

Nested Classes
  Path
Instance Methods
 
__init__(self, paths=None)
Constructor
source code
 
append(self, path)
Append a new ancestor path to this multi-path
source code
 
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
 
__repr__(self)
Serialize this multi-path as string
source code
 
as_list(self)
Return this multi-path as list of node lists
source code
 
__len__(self)
The number of paths in 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
 
nodes(self)
Get all nodes from this path
source code
Static Methods
 
all_nodes(paths)
Get all nodes from all paths
source code
Method Details

__init__(self, paths=None)
(Constructor)

source code 

Constructor

append(self, path)

source code 

Append a new ancestor path to this multi-path

Parameters:
  • path - the ancestor path

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(self, head, ancestor=None)

source code 

Cut off the vertex ancestor<-head in this multi-path

Parameters:
  • head - the head node
  • ancestor - the ancestor node to cut off

clean(self)

source code 

Remove any duplicate and empty paths from this multi-path

__repr__(self)
(Representation operator)

source code 

Serialize this multi-path as string

as_list(self)

source code 

Return this multi-path as list of node lists

__len__(self)
(Length operator)

source code 

The number of paths in this multi-path

__and__(self, sequence)
(And operator)

source code 

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)

__contains__(self, sequence)
(In operator)

source code 

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)

nodes(self)

source code 

Get all nodes from this path

all_nodes(paths)
Static Method

source code 

Get all nodes from all paths

Parameters:
  • paths - list of multi-paths