Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@base treats trailing hash ('#') different from slash '/' #809

Open
simontaurus opened this issue Jul 2, 2023 · 3 comments
Open

@base treats trailing hash ('#') different from slash '/' #809

simontaurus opened this issue Jul 2, 2023 · 3 comments
Labels

Comments

@simontaurus
Copy link

simontaurus commented Jul 2, 2023

{
  "@context": {
    "@version": 1.1,
    "@base":"http://example.com/vocab/",
    "name": {"@id": "http://example.com/vocab#test", "@type": "@id"}
  },
  "@id": "http://example.org/places#BrewEats",
  "@type": "Restaurant",
  "name": "Restaurant"
}

expands to

[
  {
    "@id": "http://example.org/places#BrewEats",
    "@type": [
      "http://example.com/vocab/Restaurant"
    ],
    "http://example.com/vocab#test": [
      {
        "@id": "http://example.com/vocab/Restaurant"
      }
    ]
  }
]

(playground)
while

{
  "@context": {
    "@version": 1.1,
    "@base":"http://example.com/vocab#",
    "name": {"@id": "http://example.com/vocab#test", "@type": "@id"}
  },
  "@id": "http://example.org/places#BrewEats",
  "@type": "Restaurant",
  "name": "Restaurant"
}

ignores the hash and falls back to the last slash

[
  {
    "@id": "http://example.org/places#BrewEats",
    "@type": [
      "http://example.com/Restaurant"
    ],
    "http://example.com/vocab#test": [
      {
        "@id": "http://example.com/Restaurant"
      }
    ]
  }
]

(playground)

Is this behaviour intended? I did not found any hint in the spec

@gkellogg
Copy link
Member

This follows RFC3987 resolution of IRI references, which does not have special provision for IRIs ending with #. See the IRI Expansion Algorithm step 8.

Otherwise, if document relative is true set value to the result of resolving value against the base IRI from active context. Only the basic algorithm in section 5.2 of [RFC3986] is used; neither Syntax-Based Normalization nor Scheme-Based Normalization are performed. ...

@simontaurus
Copy link
Author

Thank you for the clarification. So there is no way to use a vocabulary that uses # as part of its IRIs as a @base, e. g. to expand

{"type": "string"}

to

{"type": "http://www.w3.org/2001/XMLSchema#string"}

?

@gkellogg
Copy link
Member

Certainly, you can use @vocab for thins like @type IRI expansion. @type is special as it can expand either relative to the vocabulary or document base. Vocabulary expansion, also used for keys, uses string concatenation, rather than IRI resolution, for this purpose.

@base is used to override the document location, for entities described within that document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants