Mercurial > code > home > repos > homeauto
annotate service/reasoning/graphop.py @ 984:5da9200418db
reasoning: -v verbose setting, more oneshot support, some custom stuff for mpd commands
Ignore-this: 7646fba7b5496eb1f33a87452af6c6de
darcs-hash:20150514083000-312f9-ef4db22cf33250e690b6021b6b1968cc788d14cb
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Thu, 14 May 2015 01:30:00 -0700 |
parents | 4ae49c6adecb |
children | f3f667769aef |
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 """ | |
984
5da9200418db
reasoning: -v verbose setting, more oneshot support, some custom stuff for mpd commands
drewp <drewp@bigasterisk.com>
parents:
923
diff
changeset
|
11 |
5da9200418db
reasoning: -v verbose setting, more oneshot support, some custom stuff for mpd commands
drewp <drewp@bigasterisk.com>
parents:
923
diff
changeset
|
12 ctxs = [ctx.identifier for ctx in g.contexts()] |
853 | 13 |
14 out = ConjunctiveGraph() | |
15 for stmt in g.quads((None, None, None)): | |
16 if stmt[0] not in ctxs and stmt[1] not in ignorePredicates: | |
17 out.addN([stmt]) | |
18 return out | |
19 | |
20 def graphEqual(a, b, ignorePredicates=[]): | |
21 """ | |
22 compare graphs, omitting any metadata statements about contexts | |
23 (especially modification times) and also any statements using the | |
24 given predicates | |
25 """ | |
26 stmtsA = set(graphWithoutMetadata(a, ignorePredicates)) | |
27 stmtsB = set(graphWithoutMetadata(b, ignorePredicates)) | |
28 if stmtsA == stmtsB: | |
29 return True | |
30 | |
31 if log.getEffectiveLevel() <= logging.INFO: | |
32 lost = stmtsA - stmtsB | |
33 if lost: | |
923
4ae49c6adecb
errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents:
854
diff
changeset
|
34 log.info("graph A only:") |
853 | 35 for s in lost: |
36 log.info(" %s", s) | |
37 new = stmtsB - stmtsA | |
38 if new: | |
923
4ae49c6adecb
errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents:
854
diff
changeset
|
39 log.info("graph B only:") |
853 | 40 for s in new: |
41 log.info(" %s", s) | |
42 return False |