json-ld / json-ld.org

JSON for Linked Data's documentation and playground site
https://json-ld.org/
Other
856 stars 152 forks source link

json-playground with jsonld 1.1 works with inline @context, but fails with uri in context #710

Closed OyvindLGjesdal closed 4 years ago

OyvindLGjesdal commented 4 years ago

asked for help on this in the IIIF-slack, and received advice from @ahankinson debug using the '@context' inline, which

If I use the web-service for the url https://iiif.spraksamlingane.no/iiif/manifest/8bc611e9-d0d3-320a-b787-a3d76d8d41cd.json (json-ld 1.1) I get

TypeError: Cannot read property '@context' of null

If I edit the jsonld file and add the context inline it passes but has a warning in Codemirror-lint-arker-warning

/allOf/2/additionalProperties/anyOf: Data does not match any schemas from "anyOf"

Context pasted inline in jsonld:

{"@context": {
      "@version": 1.1,

    "iiif_prezi": "http://iiif.io/api/presentation/3#",
    "iiif_image": "http://iiif.io/api/image/3#",
    "exif": "http://www.w3.org/2003/12/exif/ns#",
    "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#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "as": "http://www.w3.org/ns/activitystreams#",
    "ebu": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#",
    "schema": "https://schema.org/",

    "id": "@id",
    "type": "@type",

    "Collection": {
      "@id": "iiif_prezi:Collection",
      "@context": {
        "partOf": {
          "@id": "dcterms:partOf",
          "@type": "@id",
          "@container": "@set"
        }
      }
    },
    "Manifest": {
      "@id": "iiif_prezi:Manifest",
      "@context": {
        "partOf": {
          "@id": "dcterms:partOf",
          "@type": "@id",
          "@container": "@set"
        }
      }
    },
    "Canvas": {
      "@id": "iiif_prezi:Canvas",
      "@context": {
        "partOf": {
          "@id": "dcterms:partOf",
          "@type": "@id",
          "@container": "@set"
        }
      }
    },
    "Range": {
      "@id": "iiif_prezi:Range",
      "@context": {
        "partOf": {
          "@id": "dcterms:partOf",
          "@type": "@id",
          "@container": "@set"
        }
      }
    },

    "AnnotationCollection": {
      "@id": "as:OrderedCollection",
      "@context": [
        "http://www.w3.org/ns/anno.jsonld",
        {
          "partOf": {
            "@id": "dcterms:partOf",
            "@type": "@id",
            "@container": "@set"
          },
          "label": {
            "@id": "rdfs:label",
            "@container": ["@language", "@set"],
            "@context": {
              "none": "@none"
            }
          }          
        }
      ]
    },
    "AnnotationPage": {
      "@id": "as:OrderedCollectionPage",
      "@context": [
        "http://www.w3.org/ns/anno.jsonld",
        {
          "label": {
            "@id": "rdfs:label",
            "@container": ["@language", "@set"],
            "@context": {
              "none": "@none"
            }
          }          
        }
      ]
    },
    "Annotation": {
      "@id": "oa:Annotation",
      "@context": [
        "http://www.w3.org/ns/anno.jsonld",
        {
          "label": {
            "@id": "rdfs:label",
            "@container": ["@language", "@set"],
            "@context": {
              "none": "@none"
            }
          }          
        }
      ]
    },

    "Dataset": "dctypes:Dataset",
    "Image": "dctypes:StillImage",
    "Video": "dctypes:MovingImage",
    "Audio": "dctypes:Sound",
    "Text": "dctypes:Text",
    "Service": "schema:WebAPI",
    "Agent": "dcterms:Agent",

    "label": {
      "@id": "rdfs:label",
      "@container": ["@language", "@set"],
      "@context": {
        "none": "@none"
      }
    },
    "value": {
      "@id": "rdf:value",
      "@container": ["@language", "@set"],
      "@context": {
        "none": "@none"
      }
    },
    "metadata": {
      "@type": "@id",
      "@id": "iiif_prezi:metadataEntries",
      "@container": "@list"
    },
    "summary": {
      "@id": "as:summary",
      "@container": ["@language", "@set"],
      "@context": {
        "none": "@none"
      }      
    },
    "requiredStatement": {
      "@id": "iiif_prezi:requiredStatement",
      "@type": "@id"
    },
    "rights": {
      "@type": "@id",
      "@id": "dcterms:rights"
    },
    "provider": {
      "@type": "@id",
      "@id": "schema:provider",
      "@container": "@set"
    },
    "logo": {
      "@type": "@id",
      "@id": "foaf:logo",
      "@container": "@set"
    },
    "thumbnail": {
      "@type": "@id",
      "@id": "iiif_prezi:thumbnail",
      "@container": "@set"
    },
    "navDate": {
      "@id": "iiif_prezi:navigationDate"
    },
    "accompanyingCanvas": {
        "@type": "@id",
        "@id": "iiif_prezi:accompanyingCanvas"
    },
    "placeholderCanvas": {
        "@type": "@id",
        "@id": "iiif_prezi:placeholderCanvas"
    },

    "format": {
      "@id": "dc:format"
    },
    "language": {
      "@id": "dc:language",
      "@container": "@set"
    },
    "profile": {
      "@type": "@vocab",
      "@id": "dcterms:conformsTo"
    },
    "height": {
      "@id": "exif:height",
      "@type": "xsd:integer"
    },
    "width": {
      "@id": "exif:width",
      "@type": "xsd:integer"
    },
    "duration": {
      "@id": "ebu:duration"
    },
    "viewingDirection": {
      "@id": "iiif_prezi:viewingDirection",
      "@type": "@vocab",
      "@container": "@set",
      "@context": {
        "left-to-right": "iiif_prezi:leftToRightDirection",
        "right-to-left": "iiif_prezi:rightToLeftDirection",
        "top-to-bottom": "iiif_prezi:topToBottomDirection",
        "bottom-to-top": "iiif_prezi:bottomToTopDirection"
      }
    },
    "behavior": {
      "@id": "iiif_prezi:behavior",
      "@type": "@vocab",
      "@container": "@set",
      "@context": {
        "auto-advance": "iiif_prezi:autoAdvanceHint",
        "no-auto-advance": "iiif_prezi:noAutoAdvanceHint",
        "repeat": "iiif_prezi:repeatHint",
        "no-repeat": "iiif_prezi:noRepeatHint",
        "unordered": "iiif_prezi:unordered",
        "individuals": "iiif_prezi:individualsHint",
        "continuous": "iiif_prezi:continuousHint",
        "paged": "iiif_prezi:pagedHint",
        "facing-pages": "iiif_prezi:facingPagesHint",
        "non-paged": "iiif_prezi:nonPagedHint",
        "multi-part": "iiif_prezi:multiPartHint",
        "together": "iiif_prezi:togetherHint",
        "sequence": "iiif_prezi:sequenceHint",
        "thumbnail-nav": "iiif_prezi:thumbnailNavHint",
        "no-nav": "iiif_prezi:noNavHint",        
        "hidden": "iiif_prezi:noneHint"
      }
    },

    "timeMode": {
      "@id": "iiif_prezi:timeMode",
      "@type": "@vocab",
      "@context": {
        "trim": "iiif_prezi:trimMode",
        "scale": "iiif_prezi:scaleMode",
        "loop": "iiif_prezi:loopMode"
      }
    },

    "homepage": {
      "@type": "@id",
      "@id": "foaf:homepage",
      "@container": "@set"
    },
    "rendering": {
      "@id": "dcterms:hasFormat",
      "@type": "@id",
      "@container": "@set"
    },
    "service": {
      "@type": "@id",
      "@id": "schema:potentialAction",
      "@container": "@set",
      "@context": {
        "ImageService1": {
          "@id": "http://iiif.io/api/image/1#ImageService",
          "@context": [
            "http://iiif.io/api/image/1/context.json",
            {
              "id": null,
              "type": null
            }
          ]
        },
        "ImageService2": {
          "@id": "http://iiif.io/api/image/2#ImageService",
          "@context": [
            "http://iiif.io/api/image/2/context.json",
            {
              "id": null,
              "type": null
            }
          ]
        },
        "ImageService3": {
          "@id": "http://iiif.io/api/image/3#ImageService",
          "@context": "http://iiif.io/api/image/3/context.json"
        },
        "SearchService1": {
          "@id": "http://iiif.io/api/search/1#SearchService",
          "@context": [
            "http://iiif.io/api/search/1/context.json",
            {
              "id": null,
              "type": null
            }
          ]
        },
        "AutoCompleteService1": {
          "@id": "http://iiif.io/api/search/1#AutoCompleteService",
          "@context": [
            "http://iiif.io/api/search/1/context.json",
            {
              "id": null,
              "type": null
            }
          ]
        },
        "AuthCookieService1": {
          "@id": "http://iiif.io/api/auth/1#CookieService",
          "@context": [
            "http://iiif.io/api/auth/1/context.json",
            {
              "id": null,
              "type": null
            }
          ]
        },
        "AuthTokenService1": {
          "@id": "http://iiif.io/api/auth/1#TokenService",
          "@context": [
            "http://iiif.io/api/auth/1/context.json",
            {
              "id": null,
              "type": null
            }
          ]
        },
        "AuthLogoutService1": {
          "@id": "http://iiif.io/api/auth/1#LogoutService",
          "@context": [
            "http://iiif.io/api/auth/1/context.json",
            {
              "id": null,
              "type": null
            }
          ]
        }
      }
    },

    "seeAlso": {
      "@type": "@id",
      "@id": "rdfs:seeAlso",
      "@container": "@set"
    },

    "start": {
      "@type": "@id",
      "@id": "iiif_prezi:start"
    },
    "supplementary": {
      "@type": "@id",
      "@id": "iiif_prezi:supplementary"
    },

    "items": {
      "@type": "@id",
      "@id": "as:items",
      "@container": "@list"
    },
    "structures": {
      "@type": "@id",
      "@id": "iiif_prezi:structures",
      "@container": "@list"
    },
    "annotations": {
      "@type": "@id",
      "@id": "iiif_prezi:annotations",
      "@container": "@list"
    },

    "painting": "iiif_prezi:painting",
    "supplementing": "iiif_prezi:supplementing"
  },"id":"https://iiif.spraksamlingane.no/iiif/manifest/8bc611e9-d0d3-320a-b787-a3d76d8d41cd.json","type":"Manifest","metadata":[{"label":{"nb":["Oppslagsord"]},"value":{"none":["Kile"]}},{"label":{"nb":["Oppskriver"]},"value":{"none":["Kåre Hoel"]}},{"label":{"nb":["År"]},"value":{"none":["1950-54"]}},{"label":{"nb":["Fylke"]},"value":{"none":["Østfold"]}},{"label":{"nb":["Herred"]},"value":{"none":["Hvaler"]}},{"label":{"nb":["GNIDu"]},"value":{"none":["01110010"]}},{"label":{"nb":["GNR"]},"value":{"none":["10"]}},{"label":{"nb":["KNR"]},"value":{"none":["0111"]}}],"thumbnail":[{"id":"https://iiif.spraksamlingane.no/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc/full/250,145/0/default.jpg","type":"Image","service":{"@id":"https://iiif.spraksamlingane.no/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc","@type":"ImageService2","profile":"level1"}}],"viewingDirection":"right-to-left","behavior":["paged"],"rights":"http://creativecommons.org/licenses/by/4.0/","items":[{"id":"https://iiif.spraksamlingane.no/canvas/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc","type":"Canvas","items":[{"id":"https://iiif.spraksamlingane.no/annotationpage/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc","type":"AnnotationPage","items":[{"id":"https://iiif.spraksamlingane.no/annotation/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc","type":"Annotation","target":"https://iiif.spraksamlingane.no/canvas/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc","body":{"id":"https://iiif.spraksamlingane.no/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc","type":"Image","service":{"@id":"https://iiif.spraksamlingane.no/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc","@type":"ImageService2","profile":"level1"},"format":"image/jpeg","height":1440,"width":835},"motivation":"painting"}]}],"label":{"none":["e55e681e-9c02-35c1-b018-32e6c4ad95dc"]},"target":"https://iiif.spraksamlingane.no/canvas/iiif/image/e55e681e-9c02-35c1-b018-32e6c4ad95dc","height":835,"width":1440},{"id":"https://iiif.spraksamlingane.no/canvas/iiif/image/ead56e0c-fbae-398e-b357-9dd83eeeae7a","type":"Canvas","items":[{"id":"https://iiif.spraksamlingane.no/annotationpage/iiif/image/ead56e0c-fbae-398e-b357-9dd83eeeae7a","type":"AnnotationPage","items":[{"id":"https://iiif.spraksamlingane.no/annotation/iiif/image/ead56e0c-fbae-398e-b357-9dd83eeeae7a","type":"Annotation","target":"https://iiif.spraksamlingane.no/canvas/iiif/image/ead56e0c-fbae-398e-b357-9dd83eeeae7a","body":{"id":"https://iiif.spraksamlingane.no/iiif/image/ead56e0c-fbae-398e-b357-9dd83eeeae7a","type":"Image","service":{"@id":"https://iiif.spraksamlingane.no/iiif/image/ead56e0c-fbae-398e-b357-9dd83eeeae7a","@type":"ImageService2","profile":"level1"},"format":"image/jpeg","height":1440,"width":830},"motivation":"painting"}]}],"label":{"none":["ead56e0c-fbae-398e-b357-9dd83eeeae7a"]},"target":"https://iiif.spraksamlingane.no/canvas/iiif/image/ead56e0c-fbae-398e-b357-9dd83eeeae7a","height":830,"width":1440},{"id":"https://iiif.spraksamlingane.no/canvas/iiif/image/5bc9c212-9d86-3d3c-bc10-0e1899f5ab6d","type":"Canvas","items":[{"id":"https://iiif.spraksamlingane.no/annotationpage/iiif/image/5bc9c212-9d86-3d3c-bc10-0e1899f5ab6d","type":"AnnotationPage","items":[{"id":"https://iiif.spraksamlingane.no/annotation/iiif/image/5bc9c212-9d86-3d3c-bc10-0e1899f5ab6d","type":"Annotation","target":"https://iiif.spraksamlingane.no/canvas/iiif/image/5bc9c212-9d86-3d3c-bc10-0e1899f5ab6d","body":{"id":"https://iiif.spraksamlingane.no/iiif/image/5bc9c212-9d86-3d3c-bc10-0e1899f5ab6d","type":"Image","service":{"@id":"https://iiif.spraksamlingane.no/iiif/image/5bc9c212-9d86-3d3c-bc10-0e1899f5ab6d","@type":"ImageService2","profile":"level1"},"format":"image/jpeg","height":1440,"width":858},"motivation":"painting"}]}],"label":{"none":["5bc9c212-9d86-3d3c-bc10-0e1899f5ab6d"]},"target":"https://iiif.spraksamlingane.no/canvas/iiif/image/5bc9c212-9d86-3d3c-bc10-0e1899f5ab6d","height":858,"width":1440},{"id":"https://iiif.spraksamlingane.no/canvas/iiif/image/248f8257-9b6b-34e8-b06c-e544ffb064de","type":"Canvas","items":[{"id":"https://iiif.spraksamlingane.no/annotationpage/iiif/image/248f8257-9b6b-34e8-b06c-e544ffb064de","type":"AnnotationPage","items":[{"id":"https://iiif.spraksamlingane.no/annotation/iiif/image/248f8257-9b6b-34e8-b06c-e544ffb064de","type":"Annotation","target":"https://iiif.spraksamlingane.no/canvas/iiif/image/248f8257-9b6b-34e8-b06c-e544ffb064de","body":{"id":"https://iiif.spraksamlingane.no/iiif/image/248f8257-9b6b-34e8-b06c-e544ffb064de","type":"Image","service":{"@id":"https://iiif.spraksamlingane.no/iiif/image/248f8257-9b6b-34e8-b06c-e544ffb064de","@type":"ImageService2","profile":"level1"},"format":"image/jpeg","height":1440,"width":849},"motivation":"painting"}]}],"label":{"none":["248f8257-9b6b-34e8-b06c-e544ffb064de"]},"target":"https://iiif.spraksamlingane.no/canvas/iiif/image/248f8257-9b6b-34e8-b06c-e544ffb064de","height":849,"width":1440}],"label":{"nb":["Seddel for Kile"]}}
davidlehn commented 4 years ago

It's a bug in the newer jsonld.js context handling code. It's exposed in the giant data blob above where some @contexts have type: null or similar. Or at least I distilled it down to something like that.

A much simpler test case is: example.jsonld:

{
  "@context": "https://example.com/context.jsonld",
} 

context.jsonld:

{
  "@context": {
    "t": null
  }
}

@dlongley Looks like the issue is in lib/ContextResolver.js _resolveContextUrls. What's the best way to fix? Add if(!context) return at the start? Or if(ctx[term]) in the term loop at the end? I'm unsure if there are other similar bugs with this processing code trying to handle arbitrary context data, so maybe take a quick look?

dlongley commented 4 years ago

I think if(!context) { return; } should suffice to fix this.

davidlehn commented 4 years ago

I think this is fixed in jsonld.js 2.0.2, and the playground was updated. An empty object using that URL for a context loads now. Please test.

OyvindLGjesdal commented 4 years ago

Thank you for the fix! Not sure if the testing comment is for me.

I've tried with https://iiif.spraksamlingane.no/iiif/manifest/8bc611e9-d0d3-320a-b787-a3d76d8d41cd.json and it loads. Some of the output-views have processing errors (signed with bitcoin, signed with rsa)

Error: The property "id" in the input was not defined in the context.

but still has output in the <div class="codeMirror-code">

davidlehn commented 4 years ago

@OyvindLGjesdal Yes, I was hoping you could test whatever you were trying to do.

What input are you using to test? I was just trying a basic test that at least loaded and parsed the context. For empty data like this the "signing" examples work:

{
  "@context": "https://iiif.spraksamlingane.no/iiif/manifest/8bc611e9-d0d3-320a-b787-a3d76d8d41cd.json"
}

There may be other reasons those signing examples don't work, so I'd not worry about it if your real use case is working ok.

OyvindLGjesdal commented 4 years ago

I used the url from your @context as the remote url document in the web service, which contains both data and context.

I also tried https://oyvindg.no/manifest/test22.jsonld which I downloaded from the Bodleian University Library IIIF service, retrieved from:

curl 'https://iiif.bodleian.ox.ac.uk/iiif/manifest/eb45e6ee-395d-4da1-8337-d8bfdde72ae9.json' -H 'Accept: application/ld+json;profile=http://iiif.io/api/presentation/3/context.json'

My use case is solved, thanks again for the help.