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