我有一个JSON-LD文档,其中的基本前缀没有按我的预期扩展,而是先缩短到其根,然后附加@id
数据:
{
"@context": {
"tag": "@type",
"@base": "http://example.com/base#auth-1/",
"Line": "lit:Line",
"load": "book:load",
"book": "http://gerastree.at/auth-1/",
"lnum": "lit:lnum",
"lline": {
"@language": "deu",
"@id": "lit:lines"
},
"lit": "http://gerastree.at/lit_2014#",
"lid": "@id"
},
"loadid": "loadIDstring",
"load": [
{
"tag": "Line",
"lnum": 1,
"lline": "asdf1",
"lid": "1"
},
{
"tag": "Line",
"lnum": 2,
"lline": "asdf2",
"lid": "2"
}
]
}
RIOT(或操场)给出:
riot --syntax=jsonld --output=turtle lines.jsonld
@prefix lit: <http://gerastree.at/lit_2014#> .
@prefix book: <http://gerastree.at/auth-1/> .
_:b0 book:load <http://example.com/1> ;
book:load <http://example.com/2> .
<http://example.com/1>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> lit:Line ;
lit:lines "asdf1"@deu ;
lit:lnum 1 .
<http://example.com/2>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> lit:Line ;
lit:lines "asdf2"@deu ;
lit:lnum 2 .
我不明白为什么这两行的ID只是<http://example.com/2>
而不是<http://example.com/base#auth-1/2>
。为什么基前缀会缩短?我可以做些什么来避免这种情况?
答案 0 :(得分:7)
@base
遵循RFC 3986的Establishing a Base URI,它表示(粗体强调):
如果基本URI是从URI引用中获取的,则在将该引用用作基本URI之前,必须将该引用转换为绝对形式并剥离任何片段组件。
所以你
"@base": "http://example.com/base#auth-1/",
将产生此基本IRI:
http://example.com/base
如果您指定"lid": "#auth-1/2"
而不是"lid": "2"
,则最终得到http://example.com/base#auth-1/2
。
或者,您可以为这些值定义前缀,例如
"foobar": "http://example.com/base#auth-1/"
并使用
"lid": "foobar:2"