【问题标题】:Constructing IRI from prefix and data in JSON-LD从 JSON-LD 中的前缀和数据构造 IRI
【发布时间】: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


    【解决方案1】:

    通过更多阅读 JSON-LD 建议和实验,我找到了为什么我的第三个版本可以正常工作的解释。

    @vocab 仅应用于属性和对象 @base 用于完成主题的 IRI。

    不是很明显,但对于我的应用程序来说足够灵活。

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 2021-12-06
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多