From eaa50f971f28f04255eae40eb22365ccf374b036 Mon Sep 17 00:00:00 2001 From: Rob Sanderson Date: Wed, 24 Oct 2018 17:08:01 +0200 Subject: [PATCH 1/3] recursive scoped contexts --- tests/recursive/anno.jsonld | 125 ++++++++++++++++++++++++++++ tests/recursive/image-b.json | 27 ++++++ tests/recursive/image.json | 28 +++++++ tests/recursive/manifest-1.json | 37 ++++++++ tests/recursive/manifest-2.json | 40 +++++++++ tests/recursive/presentation-b.json | 45 ++++++++++ tests/recursive/presentation.json | 50 +++++++++++ tests/recursive/process.py | 44 ++++++++++ 8 files changed, 396 insertions(+) create mode 100644 tests/recursive/anno.jsonld create mode 100644 tests/recursive/image-b.json create mode 100644 tests/recursive/image.json create mode 100644 tests/recursive/manifest-1.json create mode 100644 tests/recursive/manifest-2.json create mode 100644 tests/recursive/presentation-b.json create mode 100644 tests/recursive/presentation.json create mode 100644 tests/recursive/process.py diff --git a/tests/recursive/anno.jsonld b/tests/recursive/anno.jsonld new file mode 100644 index 00000000..48da447c --- /dev/null +++ b/tests/recursive/anno.jsonld @@ -0,0 +1,125 @@ +{ + "@context": { + "oa": "http://www.w3.org/ns/oa#", + "dc": "http://purl.org/dc/elements/1.1/", + "dcterms": "http://purl.org/dc/terms/", + "dctypes": "http://purl.org/dc/dcmitype/", + "foaf": "http://xmlns.com/foaf/0.1/", + "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "skos": "http://www.w3.org/2004/02/skos/core#", + "xsd": "http://www.w3.org/2001/XMLSchema#", + "iana": "http://www.iana.org/assignments/relation/", + "owl": "http://www.w3.org/2002/07/owl#", + "as": "http://www.w3.org/ns/activitystreams#", + "schema": "http://schema.org/", + + "id": {"@type": "@id", "@id": "@id"}, + "type": {"@type": "@id", "@id": "@type"}, + + "Annotation": "oa:Annotation", + "Dataset": "dctypes:Dataset", + "Image": "dctypes:StillImage", + "Video": "dctypes:MovingImage", + "Audio": "dctypes:Sound", + "Text": "dctypes:Text", + "TextualBody": "oa:TextualBody", + "ResourceSelection": "oa:ResourceSelection", + "SpecificResource": "oa:SpecificResource", + "FragmentSelector": "oa:FragmentSelector", + "CssSelector": "oa:CssSelector", + "XPathSelector": "oa:XPathSelector", + "TextQuoteSelector": "oa:TextQuoteSelector", + "TextPositionSelector": "oa:TextPositionSelector", + "DataPositionSelector": "oa:DataPositionSelector", + "SvgSelector": "oa:SvgSelector", + "RangeSelector": "oa:RangeSelector", + "TimeState": "oa:TimeState", + "HttpRequestState": "oa:HttpRequestState", + "CssStylesheet": "oa:CssStyle", + "Choice": "oa:Choice", + "Person": "foaf:Person", + "Software": "as:Application", + "Organization": "foaf:Organization", + "AnnotationCollection": "as:OrderedCollection", + "AnnotationPage": "as:OrderedCollectionPage", + "Audience": "schema:Audience", + + "Motivation": "oa:Motivation", + "bookmarking": "oa:bookmarking", + "classifying": "oa:classifying", + "commenting": "oa:commenting", + "describing": "oa:describing", + "editing": "oa:editing", + "highlighting": "oa:highlighting", + "identifying": "oa:identifying", + "linking": "oa:linking", + "moderating": "oa:moderating", + "questioning": "oa:questioning", + "replying": "oa:replying", + "reviewing": "oa:reviewing", + "tagging": "oa:tagging", + + "auto": "oa:autoDirection", + "ltr": "oa:ltrDirection", + "rtl": "oa:rtlDirection", + + "body": {"@type": "@id", "@id": "oa:hasBody"}, + "target": {"@type": "@id", "@id": "oa:hasTarget"}, + "source": {"@type": "@id", "@id": "oa:hasSource"}, + "selector": {"@type": "@id", "@id": "oa:hasSelector"}, + "state": {"@type": "@id", "@id": "oa:hasState"}, + "scope": {"@type": "@id", "@id": "oa:hasScope"}, + "refinedBy": {"@type": "@id", "@id": "oa:refinedBy"}, + "startSelector": {"@type": "@id", "@id": "oa:hasStartSelector"}, + "endSelector": {"@type": "@id", "@id": "oa:hasEndSelector"}, + "renderedVia": {"@type": "@id", "@id": "oa:renderedVia"}, + "creator": {"@type": "@id", "@id": "dcterms:creator"}, + "generator": {"@type": "@id", "@id": "as:generator"}, + "rights": {"@type": "@id", "@id": "dcterms:rights"}, + "homepage": {"@type": "@id", "@id": "foaf:homepage"}, + "via": {"@type": "@id", "@id": "oa:via"}, + "canonical": {"@type": "@id", "@id": "oa:canonical"}, + "stylesheet": {"@type": "@id", "@id": "oa:styledBy"}, + "cached": {"@type": "@id", "@id": "oa:cachedSource"}, + "conformsTo": {"@type": "@id", "@id": "dcterms:conformsTo"}, + "items": {"@type": "@id", "@id": "as:items", "@container": "@list"}, + "partOf": {"@type": "@id", "@id": "as:partOf"}, + "first": {"@type": "@id", "@id": "as:first"}, + "last": {"@type": "@id", "@id": "as:last"}, + "next": {"@type": "@id", "@id": "as:next"}, + "prev": {"@type": "@id", "@id": "as:prev"}, + "audience": {"@type": "@id", "@id": "schema:audience"}, + "motivation": {"@type": "@vocab", "@id": "oa:motivatedBy"}, + "purpose": {"@type": "@vocab", "@id": "oa:hasPurpose"}, + "textDirection": {"@type": "@vocab", "@id": "oa:textDirection"}, + + "accessibility": "schema:accessibilityFeature", + "bodyValue": "oa:bodyValue", + "format": "dc:format", + "language": "dc:language", + "processingLanguage": "oa:processingLanguage", + "value": "rdf:value", + "exact": "oa:exact", + "prefix": "oa:prefix", + "suffix": "oa:suffix", + "styleClass": "oa:styleClass", + "name": "foaf:name", + "email": "foaf:mbox", + "email_sha1": "foaf:mbox_sha1sum", + "nickname": "foaf:nick", + "label": "rdfs:label", + + "created": {"@id": "dcterms:created", "@type": "xsd:dateTime"}, + "modified": {"@id": "dcterms:modified", "@type": "xsd:dateTime"}, + "generated": {"@id": "dcterms:issued", "@type": "xsd:dateTime"}, + "sourceDate": {"@id": "oa:sourceDate", "@type": "xsd:dateTime"}, + "sourceDateStart": {"@id": "oa:sourceDateStart", "@type": "xsd:dateTime"}, + "sourceDateEnd": {"@id": "oa:sourceDateEnd", "@type": "xsd:dateTime"}, + + "start": {"@id": "oa:start", "@type": "xsd:nonNegativeInteger"}, + "end": {"@id": "oa:end", "@type": "xsd:nonNegativeInteger"}, + "total": {"@id": "as:totalItems", "@type": "xsd:nonNegativeInteger"}, + "startIndex": {"@id": "as:startIndex", "@type": "xsd:nonNegativeInteger"} + } +} \ No newline at end of file diff --git a/tests/recursive/image-b.json b/tests/recursive/image-b.json new file mode 100644 index 00000000..d9a034e1 --- /dev/null +++ b/tests/recursive/image-b.json @@ -0,0 +1,27 @@ +{ + "@context": { + "@version": 1.1, + "image": "http://iiif.io/api/image/3/context.json", + "prezi": "http://iiif.io/api/presentation/3/context.json", + "exif": "http://www.w3.org/2003/12/exif/ns#", + "as": "http://www.w3.org/ns/activitystreams#", + + "id": "@id", + "type": "@type", + + "ImageService3": "http://iiif.io/api/image/3/ImageService", + + "height": "exif:height", + "width": "exif:width", + + "partOf": { + "@type": "@id", + "@id": "as:partOf", + "@container": "@set" + }, + + "Manifest": { + "@id": "prezi:Manifest" + } + } +} diff --git a/tests/recursive/image.json b/tests/recursive/image.json new file mode 100644 index 00000000..42fab3cb --- /dev/null +++ b/tests/recursive/image.json @@ -0,0 +1,28 @@ +{ + "@context": { + "@version": 1.1, + "image": "http://iiif.io/api/image/3/context.json", + "prezi": "http://iiif.io/api/presentation/3/context.json", + "exif": "http://www.w3.org/2003/12/exif/ns#", + "as": "http://www.w3.org/ns/activitystreams#", + + "id": "@id", + "type": "@type", + + "ImageService3": "http://iiif.io/api/image/3/ImageService", + + "height": "exif:height", + "width": "exif:width", + + "partOf": { + "@type": "@id", + "@id": "as:partOf", + "@container": "@set" + }, + + "Manifest": { + "@id": "prezi:Manifest", + "@context": "http://iiif.io/api/presentation/3/context.json" + } + } +} diff --git a/tests/recursive/manifest-1.json b/tests/recursive/manifest-1.json new file mode 100644 index 00000000..3baee768 --- /dev/null +++ b/tests/recursive/manifest-1.json @@ -0,0 +1,37 @@ +{ + "@context": "http://iiif.io/api/presentation/3/context.json", + "id": "http://example.org/iiif/prezi/1/manifest.json", + "type": "Manifest", + "label": {"en": ["Manifest"]}, + "items": [ + { + "id": "http://example.org/iiif/prezi/1/canvas/1.json", + "type": "Canvas", + "items": [ + { + "id": "http://example.org/iiif/prezi/1/list/1.json", + "type": "AnnotationPage", + "items": [ + { + "id": "http://example.org/anno/1.json", + "type": "Annotation", + "target": "http://example.org/iiif/prezi/1/canvas/1.json", + "body": { + "id": "http://example.org/content/image/1.png", + "type": "Image", + "service": { + "id": "http://example.org/iiif/image/1/info.json", + "type": "ImageService3", + "partOf": { + "id": "http://example.org/iiif/prezi/1/collection.json", + "type": "Collection" + } + } + } + } + ] + } + ] + } + ] +} diff --git a/tests/recursive/manifest-2.json b/tests/recursive/manifest-2.json new file mode 100644 index 00000000..1c33b342 --- /dev/null +++ b/tests/recursive/manifest-2.json @@ -0,0 +1,40 @@ +{ + "@context": "http://iiif.io/api/presentation/3b/context.json", + "id": "http://example.org/iiif/prezi/1/manifest.json", + "type": "Manifest", + "label": {"en": ["Manifest"]}, + "items": [ + { + "id": "http://example.org/iiif/prezi/1/canvas/1.json", + "type": "Canvas", + "items": [ + { + "id": "http://example.org/iiif/prezi/1/list/1.json", + "type": "AnnotationPage", + "items": [ + { + "@context": "http://www.w3.org/ns/anno.jsonld", + "id": "http://example.org/anno/1.json", + "type": "Annotation", + "target": "http://example.org/iiif/prezi/1/canvas/1.json", + "body": { + "id": "http://example.org/content/image/1.png", + "type": "Image", + "service": { + "@context": "http://iiif.io/api/image/3b/context.json", + "id": "http://example.org/iiif/image/1/info.json", + "type": "ImageService3", + "partOf": { + "@context": "http://iiif.io/api/presentation/3b/context.json", + "id": "http://example.org/iiif/prezi/1/collection.json", + "type": "Collection" + } + } + } + } + ] + } + ] + } + ] +} diff --git a/tests/recursive/presentation-b.json b/tests/recursive/presentation-b.json new file mode 100644 index 00000000..b20e6485 --- /dev/null +++ b/tests/recursive/presentation-b.json @@ -0,0 +1,45 @@ +{ + "@context": { + "@version": 1.1, + "image": "http://iiif.io/api/image/3b/context.json", + "prezi": "http://iiif.io/api/presentation/3b/context.json", + "as": "http://www.w3.org/ns/activitystreams#", + "oa": "http://www.w3.org/ns/oa#", + + "Collection": "prezi:Collection", + "Manifest": "prezi:Manifest", + "Canvas": "prezi:Canvas", + "Range": "prezi:Range", + + "AnnotationCollection": { + "@id": "as:OrderedCollection" + }, + "AnnotationPage": { + "@id": "as:OrderedCollectionPage" + }, + "Annotation": { + "@id": "oa:Annotation" + }, + + "ImageService3": { + "@id": "http://iiif.io/api/image/3/ImageService" + }, + + "id": "@id", + "type": "@type", + "label": { + "@id": "rdfs:label", + "@container": "@language" + }, + "service": { + "@type": "@id", + "@id": "svcs:has_service", + "@container": "@set" + }, + "items": { + "@type": "@id", + "@id": "as:orderedItems", + "@container": "@list" + } + } +} \ No newline at end of file diff --git a/tests/recursive/presentation.json b/tests/recursive/presentation.json new file mode 100644 index 00000000..a8be339b --- /dev/null +++ b/tests/recursive/presentation.json @@ -0,0 +1,50 @@ +{ + "@context": { + "@version": 1.1, + "image": "http://iiif.io/api/image/3/context.json", + "prezi": "http://iiif.io/api/presentation/3/context.json", + "as": "http://www.w3.org/ns/activitystreams#", + "oa": "http://www.w3.org/ns/oa#", + + "Collection": "prezi:Collection", + "Manifest": "prezi:Manifest", + "Canvas": "prezi:Canvas", + "Range": "prezi:Range", + + "AnnotationCollection": { + "@id": "as:OrderedCollection", + "@context": "http://www.w3.org/ns/anno.jsonld" + }, + "AnnotationPage": { + "@id": "as:OrderedCollectionPage", + "@context": "http://www.w3.org/ns/anno.jsonld" + }, + "Annotation": { + "@id": "oa:Annotation", + "@context": "http://www.w3.org/ns/anno.jsonld" + }, + + "ImageService3": { + "@id": "http://iiif.io/api/image/3/ImageService", + "@context": "http://iiif.io/api/image/3/context.json" + }, + + "id": "@id", + "type": "@type", + "label": { + "@id": "rdfs:label", + "@container": ["@language", "@set"] + }, + "service": { + "@type": "@id", + "@id": "svcs:has_service", + "@container": "@set" + }, + "items": { + "@type": "@id", + "@id": "as:orderedItems", + "@container": "@list" + } + + } +} \ No newline at end of file diff --git a/tests/recursive/process.py b/tests/recursive/process.py new file mode 100644 index 00000000..67575f88 --- /dev/null +++ b/tests/recursive/process.py @@ -0,0 +1,44 @@ + +from pyld import jsonld +from pyld.jsonld import compact, expand, frame +import json + +docCache = {} + +def load_document_local(url): + if docCache.has_key(url): + return docCache[url] + + doc = { + 'contextUrl': None, + 'documentUrl': None, + 'document': '' + } + if url == "http://iiif.io/api/presentation/3/context.json": + fn = "presentation.json" + elif url == "http://iiif.io/api/presentation/3b/context.json": + fn = "presentation-b.json" + elif url == "http://iiif.io/api/image/3/context.json": + fn = "image.json" + elif url == "http://iiif.io/api/image/3b/context.json": + fn = "image-b.json" + elif url == "http://www.w3.org/ns/anno.jsonld": + fn = "anno.jsonld" + else: + print url + + fh = file(fn) + data = fh.read() + fh.close() + doc['document'] = data; + docCache[url] = doc + return doc + +jsonld.set_document_loader(load_document_local) + +fh = file('manifest-2.json') +mfst = json.load(fh) +fh.close() + +expand(mfst) + From e581c21475d39a525e30ea128126531b187dc2bc Mon Sep 17 00:00:00 2001 From: Rob Sanderson Date: Wed, 24 Oct 2018 17:15:08 +0200 Subject: [PATCH 2/3] use rawgit URIs for online --- tests/recursive/image.json | 2 +- tests/recursive/manifest-1.json | 2 +- tests/recursive/presentation.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/recursive/image.json b/tests/recursive/image.json index 42fab3cb..f6f4ad45 100644 --- a/tests/recursive/image.json +++ b/tests/recursive/image.json @@ -22,7 +22,7 @@ "Manifest": { "@id": "prezi:Manifest", - "@context": "http://iiif.io/api/presentation/3/context.json" + "@context": "https://rawgit.com/w3c/json-ld-api/recursive-test/tests/recursive/presentation.json" } } } diff --git a/tests/recursive/manifest-1.json b/tests/recursive/manifest-1.json index 3baee768..35e3212d 100644 --- a/tests/recursive/manifest-1.json +++ b/tests/recursive/manifest-1.json @@ -1,5 +1,5 @@ { - "@context": "http://iiif.io/api/presentation/3/context.json", + "@context": "https://rawgit.com/w3c/json-ld-api/recursive-test/tests/recursive/presentation.json", "id": "http://example.org/iiif/prezi/1/manifest.json", "type": "Manifest", "label": {"en": ["Manifest"]}, diff --git a/tests/recursive/presentation.json b/tests/recursive/presentation.json index a8be339b..d2b61f57 100644 --- a/tests/recursive/presentation.json +++ b/tests/recursive/presentation.json @@ -26,7 +26,7 @@ "ImageService3": { "@id": "http://iiif.io/api/image/3/ImageService", - "@context": "http://iiif.io/api/image/3/context.json" + "@context": "https://rawgit.com/w3c/json-ld-api/recursive-test/tests/recursive/image.json" }, "id": "@id", From ce52f0064ba985f83b539adb2786dca1cdee6a44 Mon Sep 17 00:00:00 2001 From: Rob Sanderson Date: Wed, 24 Oct 2018 17:19:14 +0200 Subject: [PATCH 3/3] just use rawgithub --- tests/recursive/image.json | 2 +- tests/recursive/manifest-1.json | 2 +- tests/recursive/presentation.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/recursive/image.json b/tests/recursive/image.json index f6f4ad45..401ebbf3 100644 --- a/tests/recursive/image.json +++ b/tests/recursive/image.json @@ -22,7 +22,7 @@ "Manifest": { "@id": "prezi:Manifest", - "@context": "https://rawgit.com/w3c/json-ld-api/recursive-test/tests/recursive/presentation.json" + "@context": "https://raw.githubusercontent.com/w3c/json-ld-api/recursive-test/tests/recursive/presentation.json" } } } diff --git a/tests/recursive/manifest-1.json b/tests/recursive/manifest-1.json index 35e3212d..bbb23f9b 100644 --- a/tests/recursive/manifest-1.json +++ b/tests/recursive/manifest-1.json @@ -1,5 +1,5 @@ { - "@context": "https://rawgit.com/w3c/json-ld-api/recursive-test/tests/recursive/presentation.json", + "@context": "https://raw.githubusercontent.com/w3c/json-ld-api/recursive-test/tests/recursive/presentation.json", "id": "http://example.org/iiif/prezi/1/manifest.json", "type": "Manifest", "label": {"en": ["Manifest"]}, diff --git a/tests/recursive/presentation.json b/tests/recursive/presentation.json index d2b61f57..35f84306 100644 --- a/tests/recursive/presentation.json +++ b/tests/recursive/presentation.json @@ -26,7 +26,7 @@ "ImageService3": { "@id": "http://iiif.io/api/image/3/ImageService", - "@context": "https://rawgit.com/w3c/json-ld-api/recursive-test/tests/recursive/image.json" + "@context": "https://raw.githubusercontent.com/w3c/json-ld-api/recursive-test/tests/recursive/image.json" }, "id": "@id",