json-ld 图的“@context”中是否允许带有“:”(冒号)的键?

Are keys with ":" (colon) allowed in the "@context" of a json-ld graph?

json-ld 上下文是否允许在其键中包含“:”?例如,以下是有效的 json-ld 文档吗?

{
  "@context": {
    "abc:def": "http://abc-def.com/"
  },
  "@graph": [
    {
      "abc:def": "something"
    }
  ]
}

我找不到关于规范的任何具体信息。我尝试使用两个最流行的 python 库 pyldrfdlib-jsonld 来解析上述文档,其中一个认为这是一个错误,而另一个解析正常。我也尝试了一些在线 json-ld 游乐场,他们也不同意上述文件是否格式正确。

pyld 给出错误提示 Invalid JSON-LD syntax; term in form of IRI must expand to definition.,而 rdflib-jsonld 将其扩展为

[
  {
    "http://abc-def.com/": [
      {
        "@value": "something"
      }
    ]
  }
]

哪一个是正确的?

根据 JSON-LD 1.1 规范 [1],应该可以在 @context 中使用紧凑的 IRI。但是,IRI 前缀应该存在于上下文中:

The compact IRI is expanded by concatenating the IRI mapped to the prefix to the (possibly empty) suffix. If the prefix is not defined in the active context, or the suffix begins with two slashes (such as in http://example.com), the value is interpreted as IRI instead.

因此,您的示例可能应该转换为:

{
  "@context": {
    "abc": "http://example.org/",
    "abc:def": {
      "@type": "@id"
    }
  },
      "abc:def": "something"
}

在JSON-LD游乐场[2]检查过,应该符合规范。

所以答案是,可以在JSON-LD @context中使用'colon'。我会说 pyld 的行为符合规范。