【问题标题】:JSON-LD framing with optional properties?具有可选属性的 JSON-LD 框架?
【发布时间】:2015-08-03 19:47:05
【问题描述】:

如何在 JSON-LD 上下文中将某些属性定义为“可选”?

我创建了问题的简单示例。这是相同的example in JSON-LD Playground。这是示例数据:

{
  "@context": {
    "ex": "http://example.org/ex#",
    "foaf": "http://xmlns.com/foaf/0.1/",
    "frapo": "http://purl.org/cerif/frapo/",
    "owl": "http://www.w3.org/2002/07/owl#",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "xsd": "http://www.w3.org/2001/XMLSchema#"
  },
  "@graph": [
    {
      "@id": "ex:Organization_1",
      "@type": "foaf:Organisation",
      "foaf:member": [
        {
          "@id": "ex:Person_1"
        },
        {
          "@id": "ex:Person_2"
        }
      ],
      "frapo:funds": [
        {
          "@id": "ex:Project_1"
        },
        {
          "@id": "ex:Project_2"
        }
      ]
    },
    {
      "@id": "ex:Person_2",
      "@type": "foaf:Person",
      "foaf:currentProject": {
        "@id": "ex:Project_2"
      },
      "foaf:name": "Jack"
    },
    {
      "@id": "ex:Project_2",
      "@type": "foaf:Project",
      "foaf:name": "Small project 2"
    },
    {
      "@id": "ex:Project_1",
      "@type": "foaf:Project",
      "foaf:name": "Big project 1"
    },
    {
      "@id": "ex:Person_1",
      "@type": "foaf:Person",
      "foaf:name": "Bill",
      "foaf:pastProject": [
        {
          "@id": "ex:Project_1"
        },
        {
          "@id": "ex:Project_2"
        }
      ]
    }
  ]
}

我希望Organization为主节点,如:

foaf:组织

  • 成员:[{Person}, {Person}]

  • 资金:[{Project}, {Project}]

为了创建这样的结构,我创建了框架:

{
 "@context": {
  "ex": "http://example.org/ex#",
  "foaf": "http://xmlns.com/foaf/0.1/",
  "owl": "http://www.w3.org/2002/07/owl#",
  "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
  "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
  "xsd": "http://www.w3.org/2001/XMLSchema#",
  "frapo": "http://purl.org/cerif/frapo/"
},
"@type": "foaf:Organisation",
"foaf:member": {
"foaf:currentProject": {
  "@embed": false
},
"foaf:pastProject": {
  "@embed": false
 }
},
"frapo:funds": {}
}

现在的问题是 foaf:member 原来是“null”,如果你删除那些项目关系,项目就会嵌入到 Person 实例中。

【问题讨论】:

    标签: rdf embedding json-ld


    【解决方案1】:

    用这个框架试试吧:

    {
        "@context": {
            "ex": "http://example.org/ex#",
            "foaf": "http://xmlns.com/foaf/0.1/",
            "owl": "http://www.w3.org/2002/07/owl#",
            "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
            "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
            "xsd": "http://www.w3.org/2001/XMLSchema#",
            "frapo": "http://purl.org/cerif/frapo/"
        },
        "@type": "foaf:Organisation",
        "foaf:member": {
            "foaf:currentProject": {
                "@default": [],
                "@embed": false
            },
            "foaf:pastProject": {
                "@default": [],
                "@embed": false
            }
        },
        "frapo:funds": {}
    }
    

    【讨论】:

    • 它在 JSON-LD 操场上工作,但由于某种原因不适用于 JSON-LD-JAVA 库。
    • 不过还是谢谢,我想它也应该适用于 JSONLD-JAVA。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2019-02-25
    • 1970-01-01
    相关资源
    最近更新 更多