【发布时间】:2018-09-25 15:17:32
【问题描述】:
在将未编辑的 JSON 数据转换为 JSON-LD 时,使用前缀和数据值为对象构造 IRI 时遇到问题。我运行的示例代码是:
{
"@context" :
{ "prefix" : "http://www.gerastree.at/",
"rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@vocab" : "http://example.com/" ,
"load" : "prefix:load"
"items" : "prefix:item"
},
"@type" : "tree",
"@id" : "prefix:t1" ,
"items" :
[
{ "@id" : "prefix:t2",
"@type" : "item",
"load" : "some111"
},
{ "@id" : "prefix:t3",
"@type" : "item",
"load" : "some2222"
}
]
}
但是当我将 @id 值从“prefix:t1”更改为原始 JSON 中的纯数据值(即仅“t1”、“t2”和“t3”)时,不会处理对象与了。
不正确的 JSON-LD 代码(至少 riot 没有读取)
{
"@context" :
{ "prefix" : "http://www.gerastree.at/",
"rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@vocab" : "http://example.com/" ,
"load" : "prefix:load"
"items" : "prefix:item"
},
"@type" : "tree",
"@id" : "t1" ,
"items" :
[
{ "@id" : "t2",
"@type" : "item",
"load" : "some111"
},
{ "@id" : "t3",
"@type" : "item",
"load" : "some2222"
}
]
}
值“t1”等是唯一的,我想用它们加上前缀作为 IRI 来将数据与其他数据链接起来。有没有一种方法可以在不更改生成 JSON 数据的程序或编辑文件的情况下生成 IRI,并在上下文中添加一些内容。
我找到了一个解决方案(基于Json-LD > Define a "person" for easy reuse as values on different keys for WebPage schema 的解决方案),但不明白它为什么有效。
{
"@context" :
{ "prefix" : "http://www.gerastree.at/",
"rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@base" : "http://example.com/" ,
"load" : "prefix:load",
"items" : "prefix:item"
},
"@type" : "tree",
"@id" : "t1" ,
"items" :
[
{ "@id" : "t2",
"@type" : "item",
"load" : "some111"
},
{ "@id" : "t3",
"@type" : "item",
"load" : "some2222"
}
]
}
我不认为这是 Any way to specify the default URI for the @id of a @type or the values of a property? 的副本。
需要对上下文进行哪些添加和更改?
【问题讨论】:
标签: json-ld