@context 中的 json-ld @id 和 @type 有什么区别?

inf*_*rno 3 json-ld

我在这里复制了json-ld 标准示例的一部分:

{
  "@context":
  {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "picture": { "@id": "foaf:depiction", "@type": "@id" }
  },
  "picture": "http://twitter.com/account/profile_image/markuslanthaler"
}
Run Code Online (Sandbox Code Playgroud)

我不明白,为什么我们应该在@context 中使用@id。它应该是:

{
  "@context":
  {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "picture": { "@type": ["@id", "foaf:depiction"] }
  },
  "picture": "http://twitter.com/account/profile_image/markuslanthaler"
}
Run Code Online (Sandbox Code Playgroud)

你有什么解释吗?

几年后:

我猜上面的意思是更可重用的形式:

{
    "http://xmlns.com/foaf/0.1/depiction": "http://twitter.com/account/profile_image/markuslanthaler"
}
Run Code Online (Sandbox Code Playgroud)

如果我们先检查展平的表格并尝试逐渐压缩它,会更容易理解。所以@id是属性的 IRI 和@type值的类型,这里是@id,这可能会令人困惑,但这只是意味着我们期望 IRI 作为值。

Gre*_*ogg 5

@id 告诉 JSON-LD 处理器如何扩展术语。如果您使用@vocab,或者该术语采用紧凑 IRI 的形式,则可以省略它。

@type 告诉处理器如何处理正文中使用的该术语的纯字符串值(如果是 JSON-LD 文档)。它可以是类似于 xsd 数据类型、@id 或 @vocab。最后两个非常相似,除了一个根据文档库进行评估,另一个作为词汇术语进行评估。

如果上下文中术语定义的值是字符串,而不是对象,则它是仅使用 @id 指定对象的简写。不要将上下文视为 rdfs/owl 词汇表,而是一种前缀机制。