Mercurial > code > home > repos > homeauto
annotate service/reasoning/graphop.py @ 923:4ae49c6adecb
errors and logging in reasoning
Ignore-this: 112b2985e0f5fd2a36abded52a5292b6
darcs-hash:20130922073139-312f9-4bb490330fe3e64b3ee87176e7eb2385255c4c72
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sun, 22 Sep 2013 00:31:39 -0700 |
parents | 1815d2343a3f |
children | 0f2ac014d9ea |
rev | line source |
---|---|
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: | |
923
4ae49c6adecb
errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents:
854
diff
changeset
|
33 log.info("graph A only:") |
853 | 34 for s in lost: |
35 log.info(" %s", s) | |
36 new = stmtsB - stmtsA | |
37 if new: | |
923
4ae49c6adecb
errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents:
854
diff
changeset
|
38 log.info("graph B only:") |
853 | 39 for s in new: |
40 log.info(" %s", s) | |
41 return False |