Mercurial > code > home > repos > homeauto
comparison lib/patchablegraph.py @ 474:1d2817cb9a6f
py3
Ignore-this: dc6b89c94aaec08f11a07df9fd23beee
author | drewp@bigasterisk.com |
---|---|
date | Sat, 20 Apr 2019 23:53:04 -0700 |
parents | 388769b5f8ff |
children |
comparison
equal
deleted
inserted
replaced
473:388769b5f8ff | 474:1d2817cb9a6f |
---|---|
20 differences between RDF graphs | 20 differences between RDF graphs |
21 | 21 |
22 """ | 22 """ |
23 import sys, json, logging, itertools | 23 import sys, json, logging, itertools |
24 import cyclone.sse | 24 import cyclone.sse |
25 sys.path.append("/my/proj/rdfdb") | |
26 from rdfdb.grapheditapi import GraphEditApi | 25 from rdfdb.grapheditapi import GraphEditApi |
27 from rdflib import ConjunctiveGraph | 26 from rdflib import ConjunctiveGraph |
28 from rdfdb.rdflibpatch import patchQuads | 27 from rdfdb.rdflibpatch import patchQuads, inGraph |
29 from rdfdb.patch import Patch | 28 from rdfdb.patch import Patch |
30 from rdflib_jsonld.serializer import from_rdf | 29 from rdflib_jsonld.serializer import from_rdf |
31 from rdflib.parser import StringInputSource | 30 from rdflib.parser import StringInputSource |
32 from cycloneerr import PrettyErrorHandler | 31 from cycloneerr import PrettyErrorHandler |
33 from greplin import scales | 32 from greplin import scales |
63 | 62 |
64 | 63 |
65 def patchFromJson(j): | 64 def patchFromJson(j): |
66 body = json.loads(j)['patch'] | 65 body = json.loads(j)['patch'] |
67 a = ConjunctiveGraph() | 66 a = ConjunctiveGraph() |
68 a.parse(StringInputSource(json.dumps(body['adds'])), format='json-ld') | 67 a.parse(StringInputSource(json.dumps(body['adds']).encode('utf8')), format='json-ld') |
69 d = ConjunctiveGraph() | 68 d = ConjunctiveGraph() |
70 d.parse(StringInputSource(json.dumps(body['deletes'])), format='json-ld') | 69 d.parse(StringInputSource(json.dumps(body['deletes']).encode('utf8')), format='json-ld') |
71 return Patch(addGraph=a, delGraph=d) | 70 return Patch(addGraph=a, delGraph=d) |
72 | 71 |
73 def graphAsJson(g): | 72 def graphAsJson(g): |
74 # This is not the same as g.serialize(format='json-ld')! That | 73 # This is not the same as g.serialize(format='json-ld')! That |
75 # version omits literal datatypes. | 74 # version omits literal datatypes. |