m-ld / m-ld-js

m-ld Javascript engine
https://js.m-ld.org
MIT License
37 stars 2 forks source link

Type-scoped contexts should apply #143

Open Peeja opened 1 year ago

Peeja commented 1 year ago

Consider the following JSON-LD document:

{
  "@context": {
    "appliances": "ex:appliances",
    "Appliance": {
      "@id": "ex:Appliance",
      "@context": {
        "color": "ex:color"
      }
    }
  },
  "appliances": [
    { "@id": "toaster", "@type": "Appliance", "color": "chrome" },
    { "@id": "microwave", "@type": "Appliance", "color": "black" }
  ]
}

According to the JSON-LD playground, this compacts (with an empty context) to:

{
  "ex:appliances": [
    {
      "@id": "toaster",
      "@type": "ex:Appliance",
      "ex:color": "chrome"
    },
    {
      "@id": "microwave",
      "@type": "ex:Appliance",
      "ex:color": "black"
    }
  ]
}

However, m-ld doesn't notice that color should be defined as ex:color:

[
  {
    "@id": ".well-known/genid/clfh07iez00033b6mxeie63ec",
    "ex:appliances": [
      {
        "@id": "microwave"
      },
      {
        "@id": "toaster"
      }
    ]
  },
  {
    "@id": "microwave",
    "color": "black",
    "@type": "ex:Appliance"
  },
  {
    "@id": "toaster",
    "color": "chrome",
    "@type": "ex:Appliance"
  }
]

See: JSON-LD: 4.1.8 Scoped Contexts