在 JSON-LD 中,是否可以为属性值定义 URI 映射?

2024-01-08

假设我们有以下 JSON:

{
  "@context":
  {
    "name": "http://schema.org/name",
    "status": "http://schema.org/status"
  },
  "name": "Manu Sporny",
  "status": "trollin'"
}

()

The trollin'状态由 URI 标识:http://example.com/trolling。是否可以扩大trollin'将上例中的关键字添加到 URIhttp://example.com/trolling?

直接操作上下文是行不通的:

{
  "@context":
  {
    "name": "http://schema.org/name",
    "status": "http://schema.org/status",
    "trollin'": "http://example.com/trolling"
  },
  "name": "Manu Sporny",
  "status": "trollin'"
}

()

强制类型status to @id也行不通,因为它会假设trollin'是一个相对 URI。

{
  "@context":
  {
    "name": "http://schema.org/name",
    "status": {
      "@id": "http://schema.org/status",
      "@type": "@id"
    },
    "trollin'": "http://example.com/trolling"
  },
  "name": "Manu Sporny",
  "status": "trollin'"
}

()


是的,可以这样做,你需要将状态类型设置为@vocab:

{
  "@context":
  {
    "name": "http://schema.org/name",
    "status": {
      "@id": "http://schema.org/status",
      "@type": "@vocab"
    },
    "trollin'": "http://example.com/trolling"
  },
  "name": "Manu Sporny",
  "status": "trollin'"
}

这是一个到游乐场。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 JSON-LD 中,是否可以为属性值定义 URI 映射? 的相关文章

随机推荐