json-ld / json-ld.org

JSON for Linked Data's documentation and playground site
https://json-ld.org/
Other
856 stars 152 forks source link

Bug in scoped contexts #734

Closed jakubklimek closed 2 years ago

jakubklimek commented 4 years ago

There is probably a bug in handling scoped contexts. In the snippet below, začátek and konec (beginning and end in Czech) have equivalent contexts. However, when used in data, they behave differently. Namely the context in konec is ignored, while when začátek is used, the context is applied. When the začátek definition is removed from the context, konec starts working. This can be tested in json-ld playground.

{
    "@context": {
        "typ": "@type",
        "time": "http://www.w3.org/2006/time#",
        "Časový interval": {
            "@id": "time:ProperInterval",
            "@context": {
                "začátek": {
                    "@id": "time:hasBeginning",
                    "@context": {
                        "time": "http://www.w3.org/2006/time#",
                        "xsd": "http://www.w3.org/2001/XMLSchema#",
                        "časy": "https://slovník.gov.cz/generický/čas/pojem/",
                        "Časový okamžik": {
                            "@id": "time:Instant",
                            "@context": {
                                "datum": {
                                    "@id": "time:inXSDDate",
                                    "@type": "xsd:date"
                                },
                                "datum_a_čas": {
                                    "@id": "time:inXSDDateTimeStamp",
                                    "@type": "xsd:dateTimeStamp"
                                },
                                "nespecifikovaný": {
                                    "@id": "časy:je-nespecifikovaný",
                                    "@type": "xsd:boolean"
                                }
                            }
                        }
                    }

                },
                "konec": {
                    "@id": "time:hasEnd",
                    "@context": {
                        "time": "http://www.w3.org/2006/time#",
                        "xsd": "http://www.w3.org/2001/XMLSchema#",
                        "časy": "https://slovník.gov.cz/generický/čas/pojem/",
                        "Časový okamžik": {
                            "@id": "time:Instant",
                            "@context": {
                                "datum": {
                                    "@id": "time:inXSDDate",
                                    "@type": "xsd:date"
                                },
                                "datum_a_čas": {
                                    "@id": "time:inXSDDateTimeStamp",
                                    "@type": "xsd:dateTimeStamp"
                                },
                                "nespecifikovaný": {
                                    "@id": "časy:je-nespecifikovaný",
                                    "@type": "xsd:boolean"
                                }
                            }
                        }
                    }

                }
            }
        }
    },
    "typ": "Časový interval",
    "konec": {
        "typ": "Časový okamžik",
        "datum_a_čas": "2019-01-14T09:30:00+02:00"
    }
}
gkellogg commented 4 years ago

This may be an issue in jsonld.js, which runs the playground. Running on my distiller, I get the following:

[
  {
    "@type": [
      "http://www.w3.org/2006/time#ProperInterval"
    ],
    "http://www.w3.org/2006/time#hasEnd": [
      {
        "@type": [
          "http://www.w3.org/2006/time#Instant"
        ],
        "http://www.w3.org/2006/time#inXSDDateTimeStamp": [
          {
            "@type": "http://www.w3.org/2001/XMLSchema#dateTimeStamp",
            "@value": "2019-01-14T09:30:00+02:00"
          }
        ]
      }
    ]
  }
]

which seems correct to me.

The outer type "Časový interval" establishes a type-scoped context at that level, but it is removed inside of "konec", which establishes it's own property-scoped context. Then, within that "Časový okamžik" layers on a type-scoped context, so that the term "datum_a_čas" should be in scope.

cc/@davidlehn

RinkeHoekstra commented 3 years ago

Added a detailed comment at https://github.com/digitalbazaar/jsonld.js/issues/409 showing a reproducible effect for a much simpler scoped @context definition with just two triples.

It looks like processing of scoped @context is order dependent, where it shouldn't be.

RinkeHoekstra commented 3 years ago

Let's keep the discussion at https://github.com/digitalbazaar/jsonld.js/issues/409 rather than in three places.