|
2 | 2 | import schema_salad.ref_resolver
|
3 | 3 | import schema_salad.main
|
4 | 4 | import schema_salad.schema
|
| 5 | +from schema_salad.jsonld_context import makerdf |
5 | 6 | import rdflib
|
6 | 7 | import ruamel.yaml as yaml
|
| 8 | +import json |
| 9 | + |
7 | 10 | try:
|
8 | 11 | from ruamel.yaml import CSafeLoader as SafeLoader
|
9 | 12 | except ImportError:
|
@@ -249,5 +252,75 @@ def test_typedsl_ref(self):
|
249 | 252 | ra, _ = ldr.resolve_all({"type": "File[]?"}, "")
|
250 | 253 | self.assertEqual({'type': ['null', {'items': 'File', 'type': 'array'}]}, ra)
|
251 | 254 |
|
| 255 | + def test_scoped_id(self): |
| 256 | + ldr = schema_salad.ref_resolver.Loader({}) |
| 257 | + ctx = { |
| 258 | + "id": "@id", |
| 259 | + "location": { |
| 260 | + "@id": "@id", |
| 261 | + "@type": "@id" |
| 262 | + }, |
| 263 | + "bar": "http://example.com/bar", |
| 264 | + "ex": "http://example.com/" |
| 265 | + } |
| 266 | + ldr.add_context(ctx) |
| 267 | + |
| 268 | + ra, _ = ldr.resolve_all({ |
| 269 | + "id": "foo", |
| 270 | + "bar": { |
| 271 | + "id": "baz" |
| 272 | + } |
| 273 | + }, "http://example.com") |
| 274 | + self.assertEqual({'id': 'http://example.com/#foo', |
| 275 | + 'bar': { |
| 276 | + 'id': 'http://example.com/#foo/baz'}, |
| 277 | + }, ra) |
| 278 | + |
| 279 | + g = makerdf(None, ra, ctx) |
| 280 | + print(g.serialize(format="n3")) |
| 281 | + |
| 282 | + ra, _ = ldr.resolve_all({ |
| 283 | + "location": "foo", |
| 284 | + "bar": { |
| 285 | + "location": "baz" |
| 286 | + } |
| 287 | + }, "http://example.com", checklinks=False) |
| 288 | + self.assertEqual({'location': 'http://example.com/foo', |
| 289 | + 'bar': { |
| 290 | + 'location': 'http://example.com/baz'}, |
| 291 | + }, ra) |
| 292 | + |
| 293 | + g = makerdf(None, ra, ctx) |
| 294 | + print(g.serialize(format="n3")) |
| 295 | + |
| 296 | + ra, _ = ldr.resolve_all({ |
| 297 | + "id": "foo", |
| 298 | + "bar": { |
| 299 | + "location": "baz" |
| 300 | + } |
| 301 | + }, "http://example.com", checklinks=False) |
| 302 | + self.assertEqual({'id': 'http://example.com/#foo', |
| 303 | + 'bar': { |
| 304 | + 'location': 'http://example.com/baz'}, |
| 305 | + }, ra) |
| 306 | + |
| 307 | + g = makerdf(None, ra, ctx) |
| 308 | + print(g.serialize(format="n3")) |
| 309 | + |
| 310 | + ra, _ = ldr.resolve_all({ |
| 311 | + "location": "foo", |
| 312 | + "bar": { |
| 313 | + "id": "baz" |
| 314 | + } |
| 315 | + }, "http://example.com", checklinks=False) |
| 316 | + self.assertEqual({'location': 'http://example.com/foo', |
| 317 | + 'bar': { |
| 318 | + 'id': 'http://example.com/#baz'}, |
| 319 | + }, ra) |
| 320 | + |
| 321 | + g = makerdf(None, ra, ctx) |
| 322 | + print(g.serialize(format="n3")) |
| 323 | + |
| 324 | + |
252 | 325 | if __name__ == '__main__':
|
253 | 326 | unittest.main()
|
0 commit comments