48
|
1
|
|
2 def graphWithoutMetadata(g, ignorePredicates=[]):
|
|
3 """
|
|
4 graph filter that removes any statements whose subjects are
|
|
5 contexts in the graph and also any statements with the given
|
|
6 predicates
|
|
7 """
|
|
8 ctxs = map(URIRef, set(g.contexts())) # weird they turned to strings
|
|
9
|
|
10 out = ConjunctiveGraph()
|
|
11 for stmt in g.quads((None, None, None)):
|
|
12 if stmt[0] not in ctxs and stmt[1] not in ignorePredicates:
|
|
13 out.addN([stmt])
|
|
14 return out
|
|
15
|
|
16 def graphEqual(a, b, ignorePredicates=[]):
|
|
17 """
|
|
18 compare graphs, omitting any metadata statements about contexts
|
|
19 (especially modification times) and also any statements using the
|
|
20 given predicates
|
|
21 """
|
|
22 stmtsA = set(graphWithoutMetadata(a, ignorePredicates))
|
|
23 stmtsB = set(graphWithoutMetadata(b, ignorePredicates))
|
|
24 if stmtsA == stmtsB:
|
|
25 return True
|
|
26
|
|
27 if log.getEffectiveLevel() <= logging.INFO:
|
|
28 lost = stmtsA - stmtsB
|
|
29 if lost:
|
|
30 log.info("lost statements:")
|
|
31 for s in lost:
|
|
32 log.info(" %s", s)
|
|
33 new = stmtsB - stmtsA
|
|
34 if new:
|
|
35 log.info("new statements:")
|
|
36 for s in new:
|
|
37 log.info(" %s", s)
|
|
38 return False
|