Public Functions
__init__(self, compositions)
Initialize an empty graph, with empty queue, nodes dictionary and
edges dictionary.
add_nodes(self, sources, source_type)
Creates Nodes for each source and add them to the nodes table. Also
initializes the edges table now that all nodes are known. A source is
either an event or timex tag or simply an identifier.
get_edges(self)
Return all edges that have a constraint on them.
pp_html(self, filename=None, filehandle=None, standalone=False)
Print the graph to an HTML table in filename.
pp_nodes(self)
Print all nodes with their edges_in and edges_out attributes to
standard output.
propagate(self, constraint)
Propagate the constraint through the graph, using Allen's
constraint propagation algorithm.
reduce(self)
Reduce the grap to one that does not contain any relations derived by
closure. This does not get you a graph with the original annotations
because some might have been removed due to inconsistencies.
remove_node(self, node_id)
Remove a node from the graph. Involves removing the node from the
nodes hash, removing the node's column and row in the edges array and
removing the node from edges_in and edges_out attributes of other
nodes. This is not being used right now.
Private Functions
_add_constraint_to_edge(self, constraint, edge)
This method links a constraints to its edge by retrieving the edge
from the graph, adding the constraint to this edge, and setting the edge
attribute on the constraint.
_add_constraint_to_queue(self, edge, relset, c1, c2)
_check_all_i_j_k(self, node_i, node_j, edge_i_j)
Check the constriants on [node_i --> node_j --> node_k].
_check_all_k_i_j(self, node_i, node_j, edge_i_j)
Check the constraints on [node_k --> node_i --> node_j].
_check_i_j_k(self, edge_i_j, edge_j_k, node_i, node_j)
Look at the i->j->k subgraph and check whether the new constraint in
Edge(i,j) allows you to derive something new by composition. The nodes
node_i and node_j could be derived from edge_i_j but are handed to this
function because they were already available and it saves a bit of time
this way.
_check_k_i_j(self, edge_k_i, edge_i_j, node_i, node_j)
Look at the k->i->j subgraph and check whether the new constraint in
Edge(i,j) allows you to derive something new by composition. The nodes
node_i and node_j could be derived from edge_i_j but are handed to this
function because they were already available and it saves a bit of time
this way.
_combine(self, edge, relset, c1, c2)
Compare the relation set on the edge to the relation set created by
composition. Creates the intersection of the relation sets and checks
the result: (i) inconsistency, (ii) more specific than relation set on
edge, or (iii) something else. The alrgument c1 and c2 are the
constraints that were composed to create relset and will be used to set
the history on a new constraint if it is created.
_compose(self, object1, object2)
Return the composition of the relation sets on the two objects. One
object is an edge, the other a Constraint. Once the relations
are retrieved from the objects all that's needed is a simple
lookup in the compositions table.
_get_edge(self, node1, node2)
Return the edge from node1 to node2.
_html_added_table(self, fh)
_html_nodes_table(self, fh, nodes)
_intersect_constraints(self, edge, constraint)
Intersect the constraint that was just derived with the one already
on the edge. There are three cases: (1) the new constraint, if it is the
one originally handed to the propagate() function, introduces an
inconsistency; (2) the new constraint is identical to the one already
there and can be ignored; (3) the intersection of the new constraint
with the old constraint is the same as the old constraint; and (4) the
new constraint is more specific than the already existing
constraint. The method returns False in the first two cases and the
intersection in the last case.
_normalize_relations(self)
Remove all relations that are not in the set of normalized relations,
not used now but may come in handy later.
_remove_derived_relations(self)
Remove all derived relations from the graph.
_remove_disjunctions(self)
Remove all disjunctions from the graph, not used now but may come in
handy later.
_update_constraint(self, edge_i_j, constraint_i_j, intersection)
Update a constraint by setting its relation set to the intersection
and then add it to the edge. Once you have done that you need to check
whether this constraint then puts further constraints on incoming edges
to node i and outgoing edges from node j.