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

问题描述

所以,这是我的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"
    },"@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"
    },"describedById": "id2","describedByLabel": "Secondary entity","label": "Main entity"
}

基本上,这是基于先前的describedById创建两个新属性describedByLabeldescribedBy

解决方法

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

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