@@ -188,7 +188,7 @@ def fix_jsonld_ids(obj, ids):
188
188
for entry in obj :
189
189
fix_jsonld_ids (entry , ids )
190
190
191
- def makerdf (workflow , wf , ctx ):
191
+ def makerdf (workflow , wf , ctx , graph = None ):
192
192
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType) -> Graph
193
193
prefixes = {}
194
194
idfields = []
@@ -201,20 +201,23 @@ def makerdf(workflow, wf, ctx):
201
201
idfields .append (k )
202
202
doc_url , frg = urlparse .urldefrag (url )
203
203
if "/" in frg :
204
- p , _ = frg .split ("/" )
204
+ p = frg .split ("/" )[ 0 ]
205
205
prefixes [p ] = u"%s#%s/" % (doc_url , p )
206
206
207
+ fix_jsonld_ids (wf , idfields )
208
+
209
+ if graph is None :
210
+ g = Graph ()
211
+ else :
212
+ g = graph
213
+
207
214
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 )
212
218
else :
213
219
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 )
218
221
219
222
# Bug in json-ld loader causes @id fields to be added to the graph
220
223
for s ,p ,o in g .triples ((None , URIRef ("@id" ), None )):
0 commit comments