Skip to content

Commit

Permalink
SputLink now logs inconsistencies.
Browse files Browse the repository at this point in the history
- Sputlink now writes warnings to the log if there is an inconsistency
  (see issue #20)
- Restored cycle numbering to give added garbage constraints their own number
  • Loading branch information
marcverhagen committed Apr 15, 2016
1 parent 5ca810d commit 72eb1ff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
18 changes: 12 additions & 6 deletions code/components/merging/sputlink/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from mappings import invert_interval_relations
from mappings import abbreviate_convex_relation
from library.timeMLspec import EID, EVENTID
from utilities import logger

DEBUG = True
DEBUG = False
Expand Down Expand Up @@ -52,9 +53,9 @@ def propagate(self, constraint):
constraint propagation algorithm."""
# guard against garbage constraints in the pending queue by simply
# skipping them
self.cycle += 1
if constraint.is_garbage():
return
self.cycle += 1
self.added = [] # to keep track of what is added this cycle
self.queue.append(constraint)
debug(str="\n%d %s\n" % (self.cycle, constraint))
Expand Down Expand Up @@ -140,12 +141,14 @@ def remove_node(self, id):

def _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
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 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."""
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."""
edge = self.edges[constraint.node1][constraint.node2]
new_relset = constraint.relset
existing_relset = edge.relset
Expand All @@ -154,6 +157,9 @@ def _intersect_constraints(self, edge, constraint):
% (constraint.relset, edge.relset, intersection))
if intersection == '':
status = 'INCONSISTENT'
logger.warn("Inconsistent new contraint: %s" % constraint)
logger.warn("Clashes with: [%s] (derived from %s)"
% (edge.constraint, edge.constraint.history_string()))
elif new_relset == existing_relset:
status = 'NEW=EXISTING'
elif intersection == existing_relset:
Expand Down
22 changes: 22 additions & 0 deletions code/components/merging/sputlink/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,25 @@ def has_normalized_relation(self):
"""Return True if the relation is one of the normalized ones, return
False otherwise."""
return NORMALIZED_RELATIONS.get(self.relset, False)

def pp_history(self, indent=''):
if isinstance(self.history, tuple):
print("%s%s" % (indent, str(self.history[0])))
print("%s%s" % (indent, str(self.history[1])))
elif self.history.__class__.__name__ == 'Tag':
tlink = "TLINK(relType=%s)" % self.history.attrs.get('relType')
print("%s%s" % (indent, tlink))
elif self.history.__class__.__name__ == 'Constraint':
print("%s%s" % (indent, self.history))
else:
print("%sno history" % indent)

def history_string(self):
if isinstance(self.history, tuple):
return "[%s] and [%s]" % (str(self.history[0]), str(self.history[1]))
elif self.history.__class__.__name__ == 'Tag':
return "TLINK(relType=%s)" % self.history.attrs.get('relType')
elif self.history.__class__.__name__ == 'Constraint':
return "[%s]" % self.history
else:
return "None"

0 comments on commit 72eb1ff

Please sign in to comment.