@@ -92,15 +92,17 @@ def to_nx_graph_as_bipartite_hypergraph_equivalent(gp):
92
92
93
93
94
94
def canonicalize_gp_to_rdf_graph (gp , fixed_vars = None ):
95
- assert isinstance (gp , Iterable )
95
+ assert isinstance (gp , Iterable ), "gp not iterable: %r" % gp
96
96
if fixed_vars is None :
97
97
fixed_vars = set ()
98
98
99
99
triple_bnodes = set ()
100
100
g = Graph ()
101
101
for t in gp :
102
102
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 )
104
106
s , p , o = [
105
107
BNode (i ) if isinstance (i , Variable ) and i not in fixed_vars else i
106
108
for i in t
@@ -116,7 +118,8 @@ def canonicalize_gp_to_rdf_graph(gp, fixed_vars=None):
116
118
def canonicalize_rdf_cg_to_gp (cg ):
117
119
cgp = []
118
120
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 ))
120
123
t = [
121
124
cg .value (triple_bnode , p )
122
125
for p in [RDF ['subject' ], RDF ['predicate' ], RDF ['object' ]]
@@ -335,8 +338,10 @@ def __new__(
335
338
notably rdflib.Variables) or None. The given mappings are
336
339
applied during creation for the new GraphPattern.
337
340
"""
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
340
345
triples = set (triples )
341
346
assert not triples or isinstance (next (iter (triples )), tuple )
342
347
mapping = mapping .copy () if mapping else {}
@@ -782,12 +787,16 @@ def diameter(self):
782
787
return nx .diameter (g )
783
788
784
789
def __add__ (self , other ):
785
- assert isinstance (other , Iterable )
790
+ assert isinstance (other , Iterable ), \
791
+ "self: %s, other not iterable: %r" % (self , other )
786
792
if __debug__ and not isinstance (other , GraphPattern ):
787
793
try :
788
794
it = iter (other )
789
795
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
+ )
791
800
other = chain ((peek ,), it )
792
801
except StopIteration :
793
802
pass
@@ -797,7 +806,8 @@ def __sub__(self, other):
797
806
return GraphPattern (set (self ) - set (other ))
798
807
799
808
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 )
801
811
e = self [edge_idx ]
802
812
return GraphPattern (self [:edge_idx ] + (e [::- 1 ],) + self [edge_idx + 1 :])
803
813
@@ -856,9 +866,10 @@ def __init__(self):
856
866
self .gt_pairs = set ()
857
867
858
868
def add_graph_pattern (self , gp , stimulus , response ):
859
- assert isinstance (gp , GraphPattern )
869
+ assert isinstance (gp , GraphPattern ), "%r not a GraphPattern" % gp
860
870
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 )
862
873
self .gt_pairs .add (gtp )
863
874
identifiers = gp .identifier_counts (exclude_vars = True )
864
875
self .identifier_gt_pair_count .update (identifiers .keys ())
0 commit comments