我正在尝试使用 JSON-LD 使旧版 JSON 文件变得机器可读。相关 JSON 文件有一个顶级对象,其中的 item
成员引用包含实际相关数据的对象。
{
"item": {
"id": "123",
"name": "Test"
}
}
当我现在介绍如下上下文时:
{
"@context": {
"name": "https://example.org/name"
}
}
没有提取任何知识,这意味着不能从中解释三元组。为了使其发挥作用,我意识到我可以执行以下操作:
{
"@context": {
"item": "https://example.org/exists",
"name": "https://example.org/name"
}
}
这个有效,这意味着可以很好地提取带有名称谓词的三元组。然而,这种方法的问题是,还提取了带有 exists
谓词的不必要的三元组。
因此我尝试将顶级对象标记为索引容器,以便完全忽略 item
键。我只是找不到一种方法来做到这一点,而不需要为 item
项分配 IRI,如果我分配一个,则再次提取不必要的三元组。
{
"@context": {
"name": "https://example.org/name"
}
}
没有提取任何知识,这意味着不能从中解释三元组。为了使其发挥作用,我意识到我可以执行以下操作:
这根本不起作用(因为 item
术语没有 IRI):
{
"@context": {
"item": {
"@container": "@index"
},
"name": "https://example.org/name"
}
}
这确实有效,但又出现了不必要的三元组:
{
"@context": {
"@container": "@index",
"item": "https://example.org/exists",
"name": "https://example.org/name"
}
}
我在这里缺少什么?如何创建仅提取 name
三元组的上下文?
最佳答案
根据您的 JSON-LD 处理器检查这一点:
{
"item": {
"id": "123",
"name": "Test"
} ,
"@context": {
"@base": "http://example.com/id/",
"id": "@id",
"item": "@nest",
"name": "https://example.org/name"
}
}
在 JSON-LD Playground 中,此上下文 produces以下单个 RDF 三元组:
<http://example.com/id/123> <https://example.org/name> "Test" .
使用的 JSON-LD 功能:
- 4.1.6 Keyword Aliasing (
"id": "@id"
); - 4.4 Nested Properties (
"item": "@nest"
) — new在 JSON-LD 1.1 中。
您可能还对 RML 感兴趣.
关于rdf - JSON-LD 中顶级仅索引键的上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65148090/