所以我有一个预定义的本体和一个现有的 JSON 服务(两次都读为“无法更改那里的现有内容”),返回类似于以下 JSON 的内容:
{
"propA": "someResource",
"propB": "otherResource"
}
我想通过添加(我无法更改现有属性,但可以添加新属性)上下文定义来将该输出转换为 JSON-LD。在第一步中,我添加了一个默认上下文,如下所示:
"@context": {
"@vocab": "https://example.org/",
"propA": { "@type": "@vocab" },
"propB": { "@type": "@vocab" }
},
"@id": "https://example.org/blub",
这会将两个资源映射到 @vocab
( playground ) 指定的命名空间。
<https://example.org/blub> <https://example.org/propA> <https://example.org/someResource> .
<https://example.org/blub> <https://example.org/propB> <https://example.org/otherResource> .
但是,两个引用的资源属于两个不同的命名空间。所以我需要的是一些上下文,映射到以下内容:
<https://example.org/blub> <https://example.org/propA> <https://foo.com/someResource> .
<https://example.org/blub> <https://example.org/propB> <https://bar.com/otherResource> .
我在某个地方发现了一个hack using @base
,但这仅作为一种解决方法,如果您需要一个额外的命名空间而不是多个命名空间。
那么,当我需要两个以上的属性时,如何为不同的属性定义单独的命名空间前缀?
最佳答案
这是一种方法:
{
"@context": {
"dcat": "http://www.w3.org/ns/dcat#",
"org": "http://www.w3.org/ns/org#",
"vcard": "http://www.w3.org/2006/vcard/ns#",
"foaf": "https://project-open-data.cio.gov/v1.1/schema#",
"dc": "http://purl.org/dc/terms/",
"pod": "https://project-open-data.cio.gov/v1.1/schema#",
"skos": "http://www.w3.org/2004/02/skos/core#",
}
}
然后您将使用 CURIE 格式 ( https://en.wikipedia.org/wiki/CURIE ) 来指定 key:value
对,其中 key
是 vocab
并且值
是公理/语句中使用的词汇术语
。
关于namespaces - JSON-LD 上下文中的不同值前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52126765/