psychoinformatics-de / datalad-concepts

Other
3 stars 2 forks source link

`data-distribution` schema `type` definition is problematic #123

Closed mih closed 3 months ago

mih commented 3 months ago

It produces a JSON-LD serialization that looks like this:

  {
    "@id": "https://example.com/custom-namespace/datasetversion/.",
    "@type": [
      {
        "@type": "http://www.w3.org/2001/XMLSchema#anyURI",
        "@value": "dlco:Distribution"
      }
    ],
    "https://concepts.datalad.org/ontology/conforms_to": ...

The JSON-LD playground complains

jsonld.SyntaxError: Invalid JSON-LD syntax; "@type" value must a string, an array of strings, an empty object, or a default object.

It did not yet find a way to make this less than

  {
    "@id": "https://example.com/custom-namespace/datasetversion/.",
    "@type": [
      {
        "@value": "dlco:Distribution"
      }
    ]
  }

The target is the syntax compliant

  {
    "@id": "https://example.com/custom-namespace/datasetversion/.",
    "@type": "dlco:Distribution"
  }
mih commented 3 months ago

Update: This problem only happens when converting to JSON-LD (with rdfpipe) from an intermediate TTL export.

mih commented 3 months ago

Leaving some hints:

When type is defined as RDF:type in the linkml schema, linkml-convert to JSON-LD would still do something like:

{
  "id": "thisdsver:.",
  "type": "dlco:Distribution",
  "conforms_to": "https://bids-specification.readthedocs.io/en/v1.4.0",
  "has_part": [
    {
      "id": "thisdsver:./dummy.dat",
      "type": "dlco:Distribution",
      "format": "funky:3475"
    }
  ],
  "@type": "Distribution",
...
}

There is @type only for the top-level object, otherwise just type (sometimes in addition).

This converts back to YAML via linkml-convert as

id: thisdsver:.
type: dlco:Distribution
conforms_to: https://bids-specification.readthedocs.io/en/v1.4.0
has_part:
- id: thisdsver:./dummy.dat
  type: dlco:Distribution
  format: funky:3475

If I change the JSON-LD export, and replace every type with @type, and remove the type definition from the context -- I get a more "normal" JSON-LD document, which nevertheless converts back to an identical YAML form.

Framing the document like with

{
  "@context": "...",
  "@type": "https://concepts.datalad.org/ontology/Distribution",
  "@id": "https://example.com/custom-namespace/datasetversion/."
}

to pick out the root distribution object works as expected.

mih commented 3 months ago

I am closing this now. #125 brought a separation of type and meta_type, and #126 has some documentation on the underlying function.