In JSON-LD, is it possible to extend a context?

Maarten

I have a JSON-LD document.

{
  "@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"
    }
  }
}

Now, part of the context of this document is generated in run-time (the Marty P object), but the foaf prefix definition is static, and repeated for each document.

If I have like 10 prefix definitions, it feel wasteful to put them in each and every document. So I would like to do something like

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"
  }

Is this possible?

Tomasz Pluskiewicz

Each @context can actually be multiple objects (or URLs), which are then combined in the order that they appear (so that it is possible to change meaning of terms - caution there).

To do that you use an array, where you can mix local and external contexts. Here's your example

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

It's described in section 6.7 of JSON-LD specs.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

In JSON-LD, is it possible to define a URI mapping for a property value?

来自分类Dev

@context中的json-ld @id和@type有什么区别?

来自分类Dev

JSON-LD中@vocab的用途是什么,与@context有什么区别?

来自分类Dev

LD JSON中的Javascript

来自分类Dev

JSON到JSON-LD

来自分类Dev

JSON-LD的错误扩展

来自分类Dev

从JSON转换为JSON-LD

来自分类Dev

测试schema.org ld + json内容

来自分类Dev

AngularJS脚本标签JSON-LD

来自分类Dev

How to return SPARQL results in JSON-LD?

来自分类Dev

是否必须嵌入JSON-LD?

来自分类Dev

JSON-LD + Hydra链接发现

来自分类Dev

Json-LD中的主从细节表示

来自分类Dev

框架json-ld文件追加子项

来自分类Dev

Jena RIOT中的JSON-LD?

来自分类Dev

使用Jena编写JSON-LD

来自分类Dev

JSON-LD中值的本地化

来自分类Dev

Json-LD中的主从细节表示

来自分类Dev

框架json-ld文件以追加子项

来自分类Dev

复制或链接到WebSite JSON-LD?

来自分类Dev

加入拆分的 JSON-LD 数据?

来自分类Dev

AMP JSON-LD 动态内容

来自分类Dev

Node.js:使用“@”符号解析 json-ld / JSON

来自分类Dev

从JSON到JSON LD,对原始JSON的更改最少(JSON-LD上下文中的所有更改)

来自分类Dev

JSON-LD文档+ Hydra Core生成Java代码

来自分类Dev

混合JSON-LD和Microdata Schema.org

来自分类Dev

遵循JSON-LD API中的所有链接

来自分类Dev

Schema.org:使用Microdata,RDFa或JSON-LD?

来自分类常见问题

Schema.org-JSON-LD-放置在哪里?