0

I'm attempting to compact at JSON-LD document, see below (we're using URNs but the same issue occurs with URLs). I want "org:example:property:schema;2"to be compacted to schema in both of the usages below, and the nested objects of the schema property to also be compacted reasonably. Sadly, this seems so far impossible.

[
  {
    "@id": "org:example:ExampleThing",
    "org:example:property:contents;2": [
          {
        "@type": "org:example:class:Property;2",
        "org:example:property:schema;2": {
          "@id": "org:example:instance:Schema:integer;2"
        }
      }
    ]
  },
  {
    "@id": "org:example:ExampleThing2",
    "org:example:property:contents;2": [
      {
        "@type": "org:example:class:Property;2",
        "org:example:property:schema;2": {
            "@type": "org:example:class:Enum;2",
            "org:example:property:valueSchema;2": {
                "@id": "org:example:instance:Schema:string;2"
            }
        }
      }
    ]
  }
]

What I would like to get out is the following:

[
    {
      "@id": "org:example:ExampleThing",
      "contents": {
        "@type": "Property",
        "schema": {
          "@id": "integer"
        }
      }
    },
    {
      "@id": "org:example:ExampleThing2",
      "contents": {
        "@type": "Property",
        "schema": {
          "@type": "Enum",
          "valueSchema": "string"
        }
      }
    }
  ]

The closest I've gotten is the following context. In it, however, org:example:instance:Schema:integer;2 is not compacted as required. Adding "@type": "@vocab" to the schema definition resolves this for ExampleThing, but then the schema term does not match the usage of the property in ExampleThing2, so it is not compacted there instead.

{
  "Property": { "@id": "org:example:class:Property;2" },
  "Enum": { "@id": "org:example:class:Enum;2" },
  "contents": { "@id": "org:example:property:contents;2" },
  "schema": { "@id": "org:example:property:schema;2" },
  "valueSchema": {
      "@id": "org:example:property:valueSchema;2",
      "@type": "@vocab"
  },
  "integer": { "@id": "org:example:instance:Schema:integer;2" },
  "string": { "@id": "org:example:instance:Schema:string;2" }
}

1 Answer 1

0

What you have is pretty close to what you want. You can check out the playground link here.

The main issue is that the "org:example:instance:Schema:integer;2" @id value can't be compacted any further, as values of @id are treated as IRIs relative to the document location, or @base. You could add an @base declaration to the context, which could get you somewhat closer. You could do better using scoped contexts, and use a different @base in the context scoped under either Property or schema.

Without doing that, this is what the compaction result looks like:

{
  "@context": {
    "Property": {"@id": "org:example:class:Property;2"},
    "Enum": {"@id": "org:example:class:Enum;2"},
    "contents": {"@id": "org:example:property:contents;2"},
    "schema": {"@id": "org:example:property:schema;2"},
    "valueSchema": {
      "@id": "org:example:property:valueSchema;2",
      "@type": "@vocab"
    },
    "integer": {"@id": "org:example:instance:Schema:integer;2"},
    "string": {"@id": "org:example:instance:Schema:string;2"}
  },
  "@graph": [
    {
      "@id": "org:example:ExampleThing",
      "contents": {
        "@type": "Property",
        "schema": {
          "@id": "org:example:instance:Schema:integer;2"
        }
      }
    },
    {
      "@id": "org:example:ExampleThing2",
      "contents": {
        "@type": "Property",
        "schema": {
          "@type": "Enum",
          "valueSchema": "string"
        }
      }
    }
  ]
}

You can read more in the Shortening IRIs section of the spec.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! It is unfortunate that I cannot achieve what I'd like to here, but I guess I'll have to make do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.