Mercurial > code > home > repos > homeauto
annotate service/reasoning/graphop.py @ 1000:df5a40967a2f
polymer updates
Ignore-this: f4f88b324b54abf90af6dc5360910041
darcs-hash:20150830185325-312f9-8f07ba7ccc6ecd6528159fa5fd09a166d3ce1650
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sun, 30 Aug 2015 11:53:25 -0700 |
parents | 5da9200418db |
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 |