Module gml :: Class gml_graph
[show private | hide private]
[frames | no frames]

Class gml_graph


This class ties together the node, edge and cluster classes into an abstracted graph object. The class is also capable of parsing a GML file into the relevant components and storing them within internal lists. The render() routine should be used for returning a graph description suitable for writing into a GML file. The render_to_file(), routine is a convenience function that should be used for saving a graph description rendering to disk.
Method Summary
  __init__(self, uid_start)
Initialize internal member variables.
  __module_test__(self)
Run a few basic tests to ensure the class is working.
Bool add_cluster(self, cluster)
Adds a cluster object to internal cluster list.
Bool add_edge(self, edge)
Adds an edge object to internal edges list.
Bool add_node(self, node)
Adds a node object to internal nodes list.
  del_cluster(self, index)
Delete a cluster from the internal list by it's index.
  del_edge(self, index)
Delete an edge from the internal list by it's index.
  del_node(self, index)
Delete a node from the internal list by it's index.
gml_cluster find_cluster_by_node_id(self, node_id)
Locate the cluster that contains the specified node ID.
gml_node find_node_by_address(self, node_address)
Locate the node with the specified node address within in the internal list.
gml_node find_node_by_id(self, node_id)
Locate the node with the specified node ID within in the internal list.
gml_cluster get_cluster(self, index)
Return the cluster at the specified index.
gml_edge get_edge(self, index)
Return the edge at the specified index.
gml_node get_node(self, index)
Return the node at the specified index.
Integer num_clusters(self)
Return the cluster count for the graph.
Integer num_edges(self)
Return the edge count for the graph.
Integer num_nodes(self)
Return the node count for the graph.
  parse(self, gml_definition)
Open the specified GML file and parse out the node, edge and cluster components.
  parse_file(self, filename)
Open the specified GML file and parse out the node, edge and cluster components.
  parser_define(self)
Define the pyparsing GML parser definition.
  parser_strip_quotes(self, original_string, location, tokens)
This routine is used to strip quotes from matched GML element strings.
  process_cluster(self, original_string, location, tokens)
This routine is called upon successful matching of cluster elements and is protyped as per the pyparsing specification.
  process_edge(self, original_string, location, tokens)
This routine is called upon successful matching of edge elements and is protyped as per the pyparsing specification.
  process_node(self, original_string, location, tokens)
This routine is called upon successful matching of node elements and is protyped as per the pyparsing specification.
String render(self)
Render the GML graph description.
  render_to_file(self, filename)
Render the entire GML graph description.
Bool replace_node(self, index, node)
Adds a node object to internal nodes list.

Method Details

__init__(self, uid_start=0)
(Constructor)

Initialize internal member variables.
Parameters:
uid_start - Optional number to start generating unique node ID's from.
           (type=Integer)

__module_test__(self)

Run a few basic tests to ensure the class is working.

add_cluster(self, cluster)

Adds a cluster object to internal cluster list.
Parameters:
cluster - Cluster object
           (type=gml_cluster)
Returns:
True on success, False otherwise.
           (type=Bool)

add_edge(self, edge)

Adds an edge object to internal edges list.
Parameters:
edge - Edge object
           (type=gml_edge)
Returns:
True on success, False otherwise.
           (type=Bool)

add_node(self, node)

Adds a node object to internal nodes list.
Parameters:
node - Node object
           (type=gml_node)
Returns:
True on success, False otherwise.
           (type=Bool)

del_cluster(self, index)

Delete a cluster from the internal list by it's index.
Parameters:
index - Cluster index
           (type=Integer)

del_edge(self, index)

Delete an edge from the internal list by it's index.
Parameters:
index - Edge index
           (type=Integer)

del_node(self, index)

Delete a node from the internal list by it's index.
Parameters:
index - Node index
           (type=Integer)

find_cluster_by_node_id(self, node_id)

Locate the cluster that contains the specified node ID.
Parameters:
node_id - Node ID to search the cluster list for.
           (type=Integer)
Returns:
Found cluster or 'False' if not found
           (type=gml_cluster)

find_node_by_address(self, node_address)

Locate the node with the specified node address within in the internal list.
Returns:
Found node or 'False' if not found
           (type=gml_node)

find_node_by_id(self, node_id)

Locate the node with the specified node ID within in the internal list.
Parameters:
node_id - Node ID to search for
           (type=Integer)
Returns:
Found node or 'False' if not found
           (type=gml_node)

get_cluster(self, index)

Return the cluster at the specified index.
Parameters:
index - Index of cluster to return.
           (type=Integer)
Returns:
Cluster at specified index.
           (type=gml_cluster)
Raises:
psx - An exception is raisd if the requested index is out of range.

get_edge(self, index)

Return the edge at the specified index.
Parameters:
index - Index of edge to return.
           (type=Integer)
Returns:
Edge at specified index.
           (type=gml_edge)
Raises:
psx - An exception is raisd if the requested index is out of range.

get_node(self, index)

Return the node at the specified index.
Parameters:
index - Index of node to return.
           (type=Integer)
Returns:
Node at specified index.
           (type=gml_node)
Raises:
psx - An exception is raisd if the requested index is out of range.

num_clusters(self)

Return the cluster count for the graph.
Returns:
Number of defined clusters in this graph.
           (type=Integer)

num_edges(self)

Return the edge count for the graph.
Returns:
Number of defined edges in this graph.
           (type=Integer)

num_nodes(self)

Return the node count for the graph.
Returns:
Number of defined nodes in this graph.
           (type=Integer)

parse(self, gml_definition)

Open the specified GML file and parse out the node, edge and cluster components.
Parameters:
gml_definition - GML description to parse
           (type=String)
Raises:
psx - An exception is raised if parsing fails for any reason.

parse_file(self, filename)

Open the specified GML file and parse out the node, edge and cluster components.
Parameters:
filename - GML file to parse
           (type=String)
Raises:
psx - An exception is raised if parsing fails for any reason.

parser_define(self)

Define the pyparsing GML parser definition. This is my first experience with the pyparsing module, improvements are welcome.

To Do: Modify parser definition such that attribute order is not important.

parser_strip_quotes(self, original_string, location, tokens)

This routine is used to strip quotes from matched GML element strings.
Parameters:
original_string - The original parse string
           (type=String)
location - The location in the string where matching started
           (type=Integer)
tokens - The list of matched tokens
           (type=ParseResults Object)

process_cluster(self, original_string, location, tokens)

This routine is called upon successful matching of cluster elements and is protyped as per the pyparsing specification.
Parameters:
original_string - The original parse string
           (type=String)
location - The location in the string where matching started
           (type=Integer)
tokens - The list of matched tokens
           (type=ParseResults Object)

process_edge(self, original_string, location, tokens)

This routine is called upon successful matching of edge elements and is protyped as per the pyparsing specification.
Parameters:
original_string - The original parse string
           (type=String)
location - The location in the string where matching started
           (type=Integer)
tokens - The list of matched tokens
           (type=ParseResults Object)

process_node(self, original_string, location, tokens)

This routine is called upon successful matching of node elements and is protyped as per the pyparsing specification.
Parameters:
original_string - The original parse string
           (type=String)
location - The location in the string where matching started
           (type=Integer)
tokens - The list of matched tokens
           (type=ParseResults Object)

render(self)

Render the GML graph description.
Returns:
GML graph description
           (type=String)

render_to_file(self, filename)

Render the entire GML graph description.
Parameters:
filename - Filename to stored rendered GML definition to.
           (type=String)
Raises:
psx - An exception is raised if the specified file can not be opened for writing.

replace_node(self, index, node)

Adds a node object to internal nodes list.
Parameters:
index - Node index
           (type=Integer)
node - Node object
           (type=gml_node)
Returns:
True on success, False otherwise.
           (type=Bool)

Generated by Epydoc 2.1 on Tue Jul 05 12:05:31 2005 http://epydoc.sf.net