我有一个 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"
}
这可能吗?
最佳答案
每个@context
实际上可以是多个对象(或 URL),然后按照它们出现的顺序组合(这样可以改变术语的含义 - 注意这里 )。
为此,您可以使用一个数组,您可以在其中混合本地和外部上下文。这是你的例子
{
"@context":
[
"http://example.com/base_context.jsonld",
{
"@vocab": "http://example.com/"
}
]
}
它在 section 6.7 中有描述JSON-LD 规范。
关于semantic-web - 在 JSON-LD 中,是否可以扩展上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26232346/