@@ -92,15 +92,17 @@ def to_nx_graph_as_bipartite_hypergraph_equivalent(gp):
9292
9393
9494def canonicalize_gp_to_rdf_graph (gp , fixed_vars = None ):
95- assert isinstance (gp , Iterable )
95+ assert isinstance (gp , Iterable ), "gp not iterable: %r" % gp
9696 if fixed_vars is None :
9797 fixed_vars = set ()
9898
9999 triple_bnodes = set ()
100100 g = Graph ()
101101 for t in gp :
102102 triple_bnode = BNode ()
103- assert triple_bnode not in triple_bnodes
103+ assert triple_bnode not in triple_bnodes , \
104+ "%r triple_bnode %r not meant to be in triple_bnodes %r" % (
105+ gp , triple_bnode , triple_bnodes )
104106 s , p , o = [
105107 BNode (i ) if isinstance (i , Variable ) and i not in fixed_vars else i
106108 for i in t
@@ -116,7 +118,8 @@ def canonicalize_gp_to_rdf_graph(gp, fixed_vars=None):
116118def canonicalize_rdf_cg_to_gp (cg ):
117119 cgp = []
118120 for triple_bnode in cg .subjects (RDF ['type' ], RDF ['Statement' ]):
119- assert isinstance (triple_bnode , BNode )
121+ assert isinstance (triple_bnode , BNode ), \
122+ "expected BNode, got %r in %r" % (triple_bnode , list (cg ))
120123 t = [
121124 cg .value (triple_bnode , p )
122125 for p in [RDF ['subject' ], RDF ['predicate' ], RDF ['object' ]]
@@ -335,8 +338,10 @@ def __new__(
335338 notably rdflib.Variables) or None. The given mappings are
336339 applied during creation for the new GraphPattern.
337340 """
338- assert mapping is None or isinstance (mapping , dict )
339- assert isinstance (triples , Iterable )
341+ assert mapping is None or isinstance (mapping , dict ), \
342+ 'mapping should be a dict: %r' % mapping
343+ assert isinstance (triples , Iterable ), \
344+ "triples not iterable: %r" % triples
340345 triples = set (triples )
341346 assert not triples or isinstance (next (iter (triples )), tuple )
342347 mapping = mapping .copy () if mapping else {}
@@ -782,12 +787,16 @@ def diameter(self):
782787 return nx .diameter (g )
783788
784789 def __add__ (self , other ):
785- assert isinstance (other , Iterable )
790+ assert isinstance (other , Iterable ), \
791+ "self: %s, other not iterable: %r" % (self , other )
786792 if __debug__ and not isinstance (other , GraphPattern ):
787793 try :
788794 it = iter (other )
789795 peek = next (it )
790- assert isinstance (peek , tuple )
796+ assert isinstance (peek , tuple ), \
797+ "self: %sother first element not a tuple %r, other: %r" % (
798+ self , peek , other
799+ )
791800 other = chain ((peek ,), it )
792801 except StopIteration :
793802 pass
@@ -797,7 +806,8 @@ def __sub__(self, other):
797806 return GraphPattern (set (self ) - set (other ))
798807
799808 def flip_edge (self , edge_idx ):
800- assert edge_idx < len (self )
809+ assert edge_idx < len (self ), \
810+ "edge_idx %d out of bounds: %s" % (edge_idx , self )
801811 e = self [edge_idx ]
802812 return GraphPattern (self [:edge_idx ] + (e [::- 1 ],) + self [edge_idx + 1 :])
803813
@@ -856,9 +866,10 @@ def __init__(self):
856866 self .gt_pairs = set ()
857867
858868 def add_graph_pattern (self , gp , stimulus , response ):
859- assert isinstance (gp , GraphPattern )
869+ assert isinstance (gp , GraphPattern ), "%r not a GraphPattern" % gp
860870 gtp = (stimulus , response )
861- assert gtp not in self .gt_pairs
871+ assert gtp not in self .gt_pairs , \
872+ "gtp %r not in gt_pairs: %r" % (gtp , self .gt_pairs )
862873 self .gt_pairs .add (gtp )
863874 identifiers = gp .identifier_counts (exclude_vars = True )
864875 self .identifier_gt_pair_count .update (identifiers .keys ())
0 commit comments