visgraph Package

visgraph Package

The new visgraph package...

Sigh... If you want something done right...

cli Module

dbcore Module

exc Module

exception visgraph.exc.DuplicateNode(node)[source]

Bases: visgraph.exc.VisGraphException

exception visgraph.exc.EdgeNonExistant(nodeid)[source]

Bases: visgraph.exc.VisGraphException

exception visgraph.exc.NodeNonExistant(nodeid)[source]

Bases: visgraph.exc.VisGraphException

exception visgraph.exc.VisGraphException[source]

Bases: exceptions.Exception

graphcore Module

Graphcore contains all the base graph manipulation objects.

class visgraph.graphcore.Graph[source]

The base Graph object implements a simple nodes and edges graph.

Nodes -
Nodes consist of a dicionary of properties about that node and a unique id which identifies the node in the current graph. From API perspective a node is a tuple of (nodeid, nodeprops).
Edges -
Edges are directional sets of a from node-id and to node-id and a piece of arbitrary edge information.
addEdge(fromid, toid, eid=None, einfo=None, **kwargs)[source]

Add an edge to the graph. Edges are directional.

Example: g.addEdge(node_1, node_2, einfo={‘name’:’Woot Edge’})

addNode(nodeid=None, ninfo=None, **kwargs)[source]

Add a Node object to the graph. Returns the nodeid.

Example: nid = g.addNode()
g.addNode(‘woot’, {‘height’:20, ‘width’:20})
NOTE: If nodeid is unspecified, it is considered an ‘anonymous’
node and will have an ID automagically assigned.
delEdge(eid)[source]

Delete an edge from the graph (by eid).

Example: g.delEdge(eid)

delNode(nid)[source]
getClusterGraphs()[source]

Return a list of the subgraph clusters (as graphs) contained within this graph. A subgraph “cluster” is defined as a group of interconnected nodes. This can be used to split out grouped subgraphs from within a larger graph.

getEdge(eid)[source]

Get the (eid, fromid, toid, einfo) tuple for the specified edge.

Example: e = g.getEdge(eid)

getEdgeInfo(eid, key, default=None)[source]

Get a property about an edge specified by from/to id.

Example: n = g.getEdgeInfo(eid ‘name’, ‘Default Name’)

getEdges()[source]

Get the list of edges in the graph. Edges are defined as (eid, fromid, toid, einfo) tuples.

Example: for eid, fromid, toid, einfo in g.getEdges():

getMeta(mprop, default=None)[source]
getNode(nodeid)[source]

Return the dictionary of properties for the specified node id.

getNodeInfo(nodeid, key, default=None)[source]

Retrieve a piece of information about a given node by key.

Example: descr = g.getNodeInfo(nid, ‘Description’, default=’OH HAI’)

getNodeProps(nodeid)[source]

Get the node info dictionary for the specified node.

Example: d = g.getNodeProps(nid)

getNodes()[source]

Return a list of (nodeid, nodeinfo) tuples.

getRefsFrom(nodeid)[source]

Return a list of edges which originate with us.

Example: for eid, fromid, toid, einfo in g.getRefsFrom(id)

getRefsTo(nodeid)[source]

Return a list of edges which terminate at us.

Example: for eid, fromid, toid, einfo in g.getRefsFrom(id)

hasNode(nodeid)[source]

Check if a given node is present within the graph.

Example: if g.hasNode(‘yermom’): print ‘woot’

pathSearch(fromid, toid=None, edgecb=None, tocb=None)[source]

Search for the shortest path from one node to another with the option to filter based on edges using edgecb. edgecb should be a function:

def myedgecb(graph, eid, fromid, toid, depth)

which returns True if it’s OK to traverse this node in the search.

Additionally, toid may be None and the caller may specify tocb with a function such as:

def mytocb(graph, nid)

which must return True on finding the target node

Returns a list of edge ids...

pathSearchFrom(fromid, nodecb, edgecb=None)[source]

Search from the specified node (breadth first) until you find a node where nodecb(graph, nid) == True. See pathSearchFromTo for docs on edgecb...

pathSearchOne(*args, **kwargs)[source]
setEdgeInfo(eid, key, value)[source]

Set a key/value pair about a given edge by it’s from/to id.

Example: g.setEdgeInfo(eid, ‘awesomeness’, 99)

setMeta(mprop, mval)[source]
setNodeInfo(nodeid, key, value)[source]

Store a piece of information (by key:value) about a given node.

Example g.setNodeInfo(nid, ‘Description’, ‘My Node Is Awesome!’)

wipeGraph()[source]

Re-initialize the graph structures and start clean again.

class visgraph.graphcore.HierarchicalGraph[source]

Bases: visgraph.graphcore.Graph

An extension to the graph base which implements the idea of hierarchy keeping a weight relationship based on the added edges. Edges are directional from X to y.

You must add nodes with the property “rootnode” to know where the hierarchy begins!

getNodeWeights()[source]

Calculate the node weights for the given nodes in the hierarchical graph based on the added “rootnode” nodes. This will return a dict of { nodeid: weight, } key-pairs.

# NOTE: This will also set the ‘weight’ property on the nodes

getPathCount()[source]

Return the number of non-looped paths through this function.

NOTE: one small issue, “spiral” functions where the leaf node
has a lower weight than a block which must reach it by a looped path will be a few total paths short...
getRootNodes()[source]

Get all the node id’s in this graph which are weight 0 (meaning they have no parents)...

pathcore Module

Paths are enumerated threads through a particular graph. They are implemented as an optimized hierarchical graph using python primitives to save memory and processing time...

Each “leaf” node may be tracked back for it’s entire path by tracking back to parents.

visgraph.pathcore.delPathNode(pnode)[source]

Prune (remove) this node from the parent...

visgraph.pathcore.getAllPaths(pnode)[source]

Get a list of lists which has each path flattened out.

Example: for path in getAllPaths(pnode):

print ‘Found A Path:’ for node in path:

doStuff()
visgraph.pathcore.getLeafNodes(pnode)[source]

Get all the leaf nodes for the path tree which contains the pnode.

Example: for leaf in getLeafNodes(root):

visgraph.pathcore.getNodeIndex(pnode)[source]
visgraph.pathcore.getNodeKids(pnode)[source]

Return the list of children nodes for the specified node.

Example: for knode in getNodeKids(pnode):

visgraph.pathcore.getNodeParent(pnode)[source]
visgraph.pathcore.getNodeProp(pnode, key, default=None)[source]

Get a property from the given node, returning default in the case that the specified property is not present.

Example:
name = getNodeProp(pnode, ‘name’, ‘Unknown’)
visgraph.pathcore.getPathLoopCount(pnode, key, value)[source]

Assuming that the key is unique, walk the current path and see how many times “key” has the specified value. This will be how many instances of a loop have been encountered.

visgraph.pathcore.getPathProp(pnode, key, default=None)[source]

Retrieve the specified property by walking the give path backward until the property is found. Returns the specified default if the specified key is not found as a property of any node in the given path.

Example:
name = getPathProp(pnode, ‘name’, ‘Unknown’)
visgraph.pathcore.getPathToNode(pnode)[source]

Return a list of the path nodes which lead from the root node to the specified path node.

visgraph.pathcore.getRootNode(pnode)[source]

Get the root node for the path tree which contains pnode.

Example: root = getRootNode(branchnode)

visgraph.pathcore.isPathLoop(pnode, key, value)[source]

Assuming you have some identifier property (such as graph node id) being set on the path nodes, you may use this API to determine if the current path has a node with the specified key/value property.

Example:
if searchPathLoop(pnode, ‘nid’, 5):
continue
visgraph.pathcore.newPathNode(parent=None, **kwargs)[source]

Create a new path node with the given properties

visgraph.pathcore.setNodeProp(pnode, key, value)[source]

Set a spcified property on the given path node.

Example:
setNodeProp(pnode, ‘name’, ‘woot’)

Table Of Contents

This Page