Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the base prefix in a relative IRI for an id shortened before expansion?

I have a JSON-LD document in which the base prefix is not expanded as I expect but shortened first to its root and then the @id data is appended:

{
    "@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 (or the playground) gives then:

 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 .

I cannot understand why the ids of the two lines are just <http://example.com/2> and not <http://example.com/base#auth-1/2>. Why is the base prefix shortened? What can I change to avoid this?

like image 914
user855443 Avatar asked Jan 18 '26 03:01

user855443


1 Answers

@base follows RFC 3986’s Establishing a Base URI, which says (bold emphasis mine):

If the base URI is obtained from a URI reference, then that reference must be converted to absolute form and stripped of any fragment component prior to its use as a base URI.

So your

"@base": "http://example.com/base#auth-1/",

will result in this base IRI:

http://example.com/base

If you specify "lid": "#auth-1/2" instead of "lid": "2", you end up with http://example.com/base#auth-1/2.

Alternatively, you could define a prefix for these values, like

"foobar": "http://example.com/base#auth-1/"

and use

"lid": "foobar:2"
like image 75
unor Avatar answered Jan 20 '26 23:01

unor