访问 json-ld 框架中嵌套的 属性

Accessing nested property in json-ld frame

所以,这是我的 json-ld 数据:

[
  {
    "@id": "http://example.com/id2",
    "http://www.w3.org/2008/05/skos-xl#literalForm": [
      {
        "@value": "Secondary entity"
      }
    ]
  },
  {
    "@id": "http://example.com/id1",
    "http://example.com/describedBy": [
      {
        "@id": "http://example.com/id2"
      }
    ],
    "http://www.w3.org/2000/01/rdf-schema#label": [
      {
        "@value": "Main entity"
      }
    ]
  }
]

这是我正在使用的框架:

{
  "@context" :
    {
      "label": {
        "@id":"http://www.w3.org/2000/01/rdf-schema#label"
      },
      "describedBy": {
        "@id":"http://example.com/describedBy"
      },
      "id": "@id",
      "@vocab" : "http://example.com/",
      "@base" : "http://example.com/"
  },
  "@graph" : {
    "describedBy": {}
  }
}

我得到的结果如下所示:

{
  "@context": {
    "label": {
      "@id": "http://www.w3.org/2000/01/rdf-schema#label"
    },
    "describedBy": {
      "@id": "http://example.com/describedBy"
    },
    "id": "@id",
    "@vocab": "http://example.com/",
    "@base": "http://example.com/"
  },
  "id": "id1",
  "describedBy": {
    "id": "id2",
    "http://www.w3.org/2008/05/skos-xl#literalForm": "Secondary entity"
  },
  "label": "Main entity"
}

是否可以将数据构造成如下所示:

{
  "@context": {
    "label": {
      "@id": "http://www.w3.org/2000/01/rdf-schema#label"
    },
    "describedBy": {
      "@id": "http://example.com/describedBy"
    },
    "id": "@id",
    "@vocab": "http://example.com/",
    "@base": "http://example.com/"
  },
  "id": "id1",
  "describedById": "id2",
  "describedByLabel": "Secondary entity",
  "label": "Main entity"
}

这基本上是在之前的 describedBy 的基础上创建两个新属性:describedByIddescribedByLabel

不能用框架真正做到这一点,因为“次要实体”是“id2”节点的 属性,这需要将其提升为 属性 “id1”节点。

您可以使用 SPARQL CONSTRUCT 执行此操作,但 JSON-LD 不允许您真正创建新数据。