Skip to content

Property-scoped @context makes roundtrip.generated drop an unrelated property #149

Description

@simontaurus

What happens

OOLD-CMP-5266 asks a term that brings in an embedded object by $ref to declare a scoped @context. Declaring it makes roundtrip.generated fail, and the property it reports as lost is not the one that carries the scoped context:

FAIL roundtrip.generated    Composition.schema.json: property lost through RDF despite being mapped: type

oold-python 0.18.0, meta-schema 1.0.0-rc.3. Removing the scoped @context and changing nothing else: 29 ok, 0 failed, and the OOLD-CMP-5266 warning returns. So the rule and the check contradict each other on the same document.

Repro

One file, no siblings needed. amount is defined in $defs, is not reachable from the root object, and the generated instance is {"type": ["Composition"]}.

Composition.schema.json
{
  "$schema": "https://oo-ld.org/latest/meta/oold-meta-schema.json",
  "$id": "Composition.schema.json",
  "x-oold-version": "0.1.0",
  "x-oold-uuid": "21e7c9d7-bf27-5c8f-a02d-03ae1075d090",
  "title": "Composition",
  "type": "object",
  "properties": {
    "type": {"type": "array", "items": {"type": "string"}, "default": ["Composition"]}
  },
  "$defs": {
    "Component": {
      "type": "object",
      "title": "Component",
      "properties": {
        "type": {"type": "array", "items": {"type": "string"}, "default": ["Component"]},
        "amount": {"$ref": "https://w3id.org/oo-ld/schemas/quantities/0.2/MassFraction.schema.json"}
      },
      "required": ["type", "amount"]
    }
  },
  "@context": [
    "https://w3id.org/oo-ld/schemas/quantities/0.2/MassFraction.schema.json",
    {
      "@version": 1.1,
      "comp": {"@id": "https://w3id.org/oo-ld/schemas/materials/0.2/Composition.schema.json#", "@prefix": true},
      "id": "@id",
      "type": {"@id": "@type", "@container": "@set"},
      "Composition": "https://w3id.org/oo-ld/schemas/materials/0.2/Composition.schema.json",
      "Component": "comp:/$defs/Component",
      "amount": {
        "@id": "comp:/$defs/Component/properties/amount",
        "@type": "@id",
        "@context": "https://w3id.org/oo-ld/schemas/quantities/0.2/MassFraction.schema.json"
      }
    }
  ]
}
oold validate <dir>          # FAIL, type lost
# delete the "@context" entry inside the amount term definition
oold validate <dir>          # 29 ok, 1 warning (OOLD-CMP-5266)

Not caused by the surrounding modelling: dropping the remote context from the root array, dropping "@type": "@id", and using a plain comp:amount instead of the JSON-pointer CURIE each still fail the same way.

Where it is not

JSON-LD processing itself is fine. Same document, same loader, compaction through the schema URL:

doc = {"@context": url, "type": ["Composition"]}
back = jsonld.compact(jsonld.from_rdf(jsonld.to_rdf(doc, {"format": "application/n-quads"})), url)
# {"id": "_:b0", "type": ["Composition"]}   with and without the scoped context

jsonld.expand also resolves the scoped remote context correctly through the validator's DocumentLoader: a term inside amount reaches qudt:value exactly as it does when the same context sits at the root. So the loss looks like it comes from the round-trip step of the pipeline (framing / promoted terms), not from context processing.

Why it matters here

Without the scoped context, the terms of an embedded schema resolve globally. Two sibling properties that embed the same base then cannot share a term name, because one global definition would win for both. In the materials reference schemas that forces components (chemical composition) and constituents (material composition) to be spelled differently to keep distinct predicates, where a scoped context would let both be components. It also leaves three OOLD-CMP-5266 warnings standing that we cannot act on.

Ask

  • Fix the generated round-trip under a property-scoped @context, or
  • state in the specification which form a scoped context may take when the target is an OO-LD schema (schema IRI as here, versus a context document), and make OOLD-CMP-5266 recommend only what the round-trip supports.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingscienceDomain-driven: science / materials science and engineering profile requests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions