@@ -171,7 +171,8 @@ def add_context(self, newcontext, baseuri=""):
171
171
self .identity_links = set ()
172
172
self .standalone = set ()
173
173
self .nolinkcheck = set ()
174
- self .idmap = set ()
174
+ self .idmap = {}
175
+ self .mapPredicate = {}
175
176
self .vocab = {}
176
177
self .rvocab = {}
177
178
@@ -194,8 +195,11 @@ def add_context(self, newcontext, baseuri=""):
194
195
if isinstance (self .ctx [c ], dict ) and self .ctx [c ].get ("noLinkCheck" ):
195
196
self .nolinkcheck .add (c )
196
197
197
- if isinstance (self .ctx [c ], dict ) and self .ctx [c ].get ("idMap" ):
198
- self .idmap .add (c )
198
+ if isinstance (self .ctx [c ], dict ) and self .ctx [c ].get ("mapSubject" ):
199
+ self .idmap [c ] = self .ctx [c ]["mapSubject" ]
200
+
201
+ if isinstance (self .ctx [c ], dict ) and self .ctx [c ].get ("mapPredicate" ):
202
+ self .mapPredicate [c ] = self .ctx [c ]["mapPredicate" ]
199
203
200
204
if isinstance (self .ctx [c ], dict ) and "@id" in self .ctx [c ]:
201
205
self .vocab [c ] = self .ctx [c ]["@id" ]
@@ -338,22 +342,33 @@ def resolve_all(self, document, base_url, file_base=None):
338
342
if idmapField in document and isinstance (document [idmapField ], dict ):
339
343
ls = []
340
344
for k ,v in document [idmapField ].items ():
341
- v ["id" ] = k
345
+ if not isinstance (v , dict ):
346
+ if idmapField in loader .mapPredicate :
347
+ v = {loader .mapPredicate [idmapField ]: v }
348
+ else :
349
+ raise validate .ValidationException ("mapSubject '%s' value '%s' is not a dict and does not have a mapPredicate" , k , v )
350
+ v [loader .idmap [idmapField ]] = k
342
351
ls .append (v )
343
352
document [idmapField ] = ls
344
353
345
- for identifer in loader .identity_links :
354
+ for identifer in loader .identifiers :
346
355
if identifer in document :
347
356
if isinstance (document [identifer ], basestring ):
348
357
document [identifer ] = loader .expand_url (document [identifer ], base_url , scoped = True )
349
358
if document [identifer ] not in loader .idx or isinstance (loader .idx [document [identifer ]], basestring ):
350
359
loader .idx [document [identifer ]] = document
351
360
base_url = document [identifer ]
352
- elif isinstance (document [identifer ], list ):
353
- for n , v in enumerate (document [identifer ]):
354
- document [identifer ][n ] = loader .expand_url (document [identifer ][n ], base_url , scoped = True )
355
- if document [identifer ][n ] not in loader .idx :
356
- loader .idx [document [identifer ][n ]] = document [identifer ][n ]
361
+ else :
362
+ raise validate .ValidationException ("identifier field '%s' must be a string" % (document [identifer ]))
363
+
364
+ for identifer in loader .identity_links :
365
+ if identifer in document and isinstance (document [identifer ], list ):
366
+ for n , v in enumerate (document [identifer ]):
367
+ document [identifer ][n ] = loader .expand_url (document [identifer ][n ], base_url , scoped = True )
368
+ if document [identifer ][n ] not in loader .idx :
369
+ loader .idx [document [identifer ][n ]] = document [identifer ][n ]
370
+ #else:
371
+ # raise validate.ValidationException("identity field '%s' must be a string" % (document[identifer]))
357
372
358
373
for d in document :
359
374
d2 = loader .expand_url (d , "" , scoped = False , vocab_term = True )
0 commit comments