Skip to content

Commit 7008d94

Browse files
author
Peter Amstutz
committed
Bugfix makerdf (helper function for converting to RDF).
1 parent 94d9847 commit 7008d94

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

schema_salad/jsonld_context.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def fix_jsonld_ids(obj, ids):
188188
for entry in obj:
189189
fix_jsonld_ids(entry, ids)
190190

191-
def makerdf(workflow, wf, ctx):
191+
def makerdf(workflow, wf, ctx, graph=None):
192192
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType) -> Graph
193193
prefixes = {}
194194
idfields = []
@@ -201,20 +201,23 @@ def makerdf(workflow, wf, ctx):
201201
idfields.append(k)
202202
doc_url, frg = urlparse.urldefrag(url)
203203
if "/" in frg:
204-
p, _ = frg.split("/")
204+
p = frg.split("/")[0]
205205
prefixes[p] = u"%s#%s/" % (doc_url, p)
206206

207+
fix_jsonld_ids(wf, idfields)
208+
209+
if graph is None:
210+
g = Graph()
211+
else:
212+
g = graph
213+
207214
if isinstance(wf, list):
208-
wf = {
209-
"@context": ctx,
210-
"@graph": wf
211-
}
215+
for w in wf:
216+
w["@context"] = ctx
217+
g.parse(data=json.dumps(w), format='json-ld', location=workflow)
212218
else:
213219
wf["@context"] = ctx
214-
215-
fix_jsonld_ids(wf, idfields)
216-
217-
g = Graph().parse(data=json.dumps(wf), format='json-ld', location=workflow)
220+
g.parse(data=json.dumps(wf), format='json-ld', location=workflow)
218221

219222
# Bug in json-ld loader causes @id fields to be added to the graph
220223
for s,p,o in g.triples((None, URIRef("@id"), None)):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
extras_require = {} # TODO: to be removed when the above is added
4242

4343
setup(name='schema-salad',
44-
version='1.14',
44+
version='1.15',
4545
description='Schema Annotations for Linked Avro Data (SALAD)',
4646
long_description=open(README).read(),
4747
author='Common workflow language working group',

0 commit comments

Comments
 (0)