BlueBrain / nexus

Blue Brain Nexus - A knowledge graph for data-driven science
https://bluebrainnexus.io/
Apache License 2.0
280 stars 74 forks source link

Schema Registration: RemoteContextError #3085

Closed tobiasschweizer closed 2 years ago

tobiasschweizer commented 2 years ago

Describe the bug A schema referring to a remote context cannot be registered.

What part of Nexus is affected

To Reproduce Schema to be registered:

{
  "@context": [
    "https://incf.github.io/neuroshapes/contexts/schema.json",
    {
      "this": "http://rescs.org/dash/thing/"
    }
  ],
  "@type": "nxv:Schema",
  "@id": "http://rescs.org/dash/thing",
  "shapes": [
    {
      "@id": "this:ThingShape",
      "@type": "sh:NodeShape",
      "label": "Thing",
      "comment": "The most generic type of item.",
      "targetClass": "schema:Thing",
      "property": [
        {
          "path": "schema:alternateName",
          "name": "alternateName",
          "description": "An alias for the item.",
          "datatype": "xsd:string"
        },
        {
          "path": "schema:description",
          "name": "description",
          "description": "A description of the item.",
          "or": [
            {
              "datatype": "xsd:string"
            },
            {
              "datatype":  "rdf:langString"
            }
          ],
          "maxCount": 1
        },
        {
          "path": "schema:identifier",
          "name": "identifier",
          "description": "The identifier property represents any kind of identifier for any kind of [[Thing]], such as ISBNs, GTIN codes, UUIDs etc. Schema.org provides dedicated properties for representing many of these, either as textual strings or as URL (URI) links. See [background notes](/docs/datamodel.html#identifierBg) for more details.",
          "or": [
            {
              "datatype": "xsd:string"
            },
            {
              "nodeKind": "sh:IRI"
            }
          ],
          "maxCount": 1
        },
        {
          "path": "schema:image",
          "name": "image",
          "description": "An image of the item.",
          "nodeKind": "sh:IRI",
          "maxCount": 1
        },
        {
          "path": "schema:name",
          "name": "name",
          "description": "The name of the item.",
          "datatype": "xsd:string",
          "minCount": 1,
          "maxCount": 1
        },
        {
          "path": "schema:sameAs",
          "name": "sameAs",
          "description": "URL of a reference Web page that unambiguously indicates the item's identity. E.g. the URL of the item's Wikipedia page, Wikidata entry, or official website.",
          "nodeKind": "sh:IRI"
        },
        {
          "path": "schema:url",
          "name": "url",
          "description": "URL of the item.",
          "nodeKind": "sh:IRI"
        }
      ]
    }
  ]
}

When trying to register this schema using an HTTP POST request to /schemas/org/project, I get an HTTP 400 error code saying

{'@context': 'https://bluebrain.github.io/nexus/contexts/error.json', '@type': 'InvalidJsonLdFormat', 'reason': 'Schema has invalid JSON-LD payload.', 'rdf': {'@type': 'RemoteContextError', 'error': {'@type': 'RemoteContextNotAccessible', 'reason': "Resolution via static resolution and via resolvers failed in 'org/project'", 'details': {'history': {'rejections': {'cause': {'@type': 'ResourceNotFound', 'reason': "The resource was not found in project 'org/project'."}, 'project': 'org/project'}, 'resolverId': 'https://bluebrain.github.io/nexus/vocabulary/defaultInProject', 'success': False}}, 'iri': 'https://incf.github.io/neuroshapes/contexts/schema.json'}}}

Expected behavior According to the docs, remote schemas should be resolved on creation and updates.

Additional context It works when I remove "https://incf.github.io/neuroshapes/contexts/schema.json" from the context. However, then the registered schema is missing some information (it is unclear how to resolve the prefixes. I assume https://incf.github.io/neuroshapes/contexts/schema.json is somehow the standard way so Nexus Delta can handle this). I also found that it works when I compact the JSON-LD with an empty context object before registering it. In this case, it expands the prefixes and the schema is self-contained. Would that be a good way to do it? Also if the resolving of the remote context object worked, what would happen if it changed at some point, e.g, switching from http://schema.org to https://schema.org (in the schema, there is just the prefix schema:)?

Thanks a lot for your assistance. If you need more details, please let me know.

bogdanromanx commented 2 years ago

Hi @tobiasschweizer, thank you for reporting this.

Nexus Delta performs context resolution when an address is specified as a @context value by making use of the Resolver resources configured for the project. At this time, there are 2 types of resolver resources, namely: InProject (which performs lookups in the current project) and CrossProject(which performs lookups in other projects). Resolvers are evaluated in order of their configured priority.

In order to solve the issue you're seeing you would have to create the referenced resource in Nexus Delta (download from GitHub and register in Nexus), either in each project where it's being used or in a single project while configuring each other project to resolve it from there.

See: https://bluebrainnexus.io/docs/delta/api/resolvers-api.html

Closing the issue as this is not a bug.

tobiasschweizer commented 2 years ago

Hi @bogdanromanx,

Thanks for the clarification.

Could you confirm that compacting the JSON-LD with an empty context, i.e. expanding all prefixes before schema registration (schema:Thing -> http://schema.org/Thing) would also be a valid option? This way, the registered schema would be self-contained.

Closing the issue as this is not a bug.

mea culpa :-)

bogdanromanx commented 2 years ago

This is indeed also an option, but due to the JSON-LD encoding the contents would be less readable.