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

encodeForIRI(str) #78

Open
cygri opened this issue Apr 29, 2019 · 1 comment
Open

encodeForIRI(str) #78

cygri opened this issue Apr 29, 2019 · 1 comment
Labels
function More custom function improvements or inbuilds

Comments

@cygri
Copy link

cygri commented Apr 29, 2019

Why?

SPARQL already has ENCODE_FOR_URI(str) which is useful when allocating new URIs based on some string content, for use with CONSTRUCT or INSERT:

BIND (IRI(concat(str(widget:), ENCODE_FOR_URI(?widgetID))) AS ?widgetURI)

But RDF supports IRIs, and in general SPARQL is good about IRI support, so it is hard to see why no IRI-compatible version of this function is provided.

IRIs in RDF (just like in web browsers) are allowed to contain the full range of international alphanumeric characters. With ENCODE_FOR_URI, anything outside of US-ASCII gets %-encoded, which is not acceptable to some users in i18n scenarios.

Previous work

None that I'm aware of. (At TQ we construct IRIs in app logic outside of SPARQL, which happened to be simpler than adding a custom function. We would use encodeForIRI if it existed.)

Proposed solution

encodeForIRI(str) would %-encode only the characters in the argument that are not allowed in an IRI path, and otherwise behave like ENCODE_FOR_IRI.

While I'm at it, let me also propose adding a new function encodeForURI as an alias for ENCODE_FOR_IRI, and deprecating the old spelling. It's the only function in SPARQL that uses SCREAMING_SNAKE_CASE and the inconsistency drives me mad 😁

Considerations for backward compatibility

None.

@namedgraph
Copy link

namedgraph commented Apr 29, 2019

There is no corresponding XPath function though: https://www.w3.org/TR/xpath-functions-31/#anyURI-functions

But looks like it can be done like this: encode-for-uri(iri-to-uri($iri))

@JervenBolleman JervenBolleman added the function More custom function improvements or inbuilds label May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function More custom function improvements or inbuilds
Projects
None yet
Development

No branches or pull requests

3 participants