【问题标题】:In JSON-LD, is it possible to extend a context?在 JSON-LD 中,是否可以扩展上下文?
【发布时间】:2014-10-07 09:02:10
【问题描述】:

我有一个 JSON-LD 文档。

{
  "@id": "VDWW1LL3MZ",
  "first_name": "Vincent",
  "last_name": "Willems",
  "knows":["MartyP"],
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "first_name": "foaf:givenName",
    "last_name": "foaf:familyName",
    "knows": "foaf:knows",
    "MartyP": { 
      "@id": "http://example.com/martyp",
      "first_name": "Marty",
      "last_name": "P"
    }
  }
}

现在,此文档的部分上下文是在运行时生成的(Marty P 对象),但 foaf 前缀定义是静态的,并且对每个文档重复。

如果我有 10 个前缀定义,将它们放在每个文档中会感觉很浪费。所以我想做类似的事情

generated document:

{
  "@id": "VDWW1LL3MZ",
  "first_name": "Vincent",
  "last_name": "Willems",
  "knows":["MartyP"],
  "@context": {
    "@extends": "http://example.com/base_context.jsonld",
    "MartyP": { 
      "@id": "http://example.com/martyp",
      "first_name": "Marty",
      "last_name": "P"
    }
  }
}

base_context.jsonld:

  {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "first_name": "foaf:givenName",
    "last_name": "foaf:familyName",
    "knows": "foaf:knows"
  }

这可能吗?

【问题讨论】:

  • 顺便说一下,MartyP 资源不应该在@context 中。上下文仅用于将 JSON 键和值转换为 URI。相反,MartyP 对象应该在 knows 数组中完整。请尝试使用JSON-LD playgroud 来掌握它。

标签: semantic-web linked-data json-ld


【解决方案1】:

每个@context 实际上可以是多个对象(或 URL),然后按照它们出现的顺序组合起来(这样就可以改变术语的含义 - 注意)。

为此,您可以使用一个数组,您可以在其中混合本地和外部上下文。这是你的例子

{
  "@context": 
  [
    "http://example.com/base_context.jsonld",
    {
      "@vocab": "http://example.com/"
    }
  ]
}

在 JSON-LD 规范的section 6.7 中有描述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-22
    • 2018-08-16
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 2012-03-12
    相关资源
    最近更新 更多