Mercurial > code > home > repos > homeauto
annotate service/reasoning/graphop.py @ 1462:2b29f14eb6bd
try new graph+view widget
Ignore-this: d5f9c5dc52f04324368716ba2f604fdb
darcs-hash:44e85a5c075ef73c34a58deaa3a3c1e8390dae52
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sun, 24 Nov 2019 00:01:00 -0800 |
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 |