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

Are prefixes carried from one section to another? Can they repeat? #54

Open
VladimirAlexiev opened this issue Feb 13, 2025 · 5 comments

Comments

@VladimirAlexiev
Copy link

VladimirAlexiev commented Feb 13, 2025

(cc @afs @cygri @lisp @kasei @ericprud)

Prefixes can appear anywhere in Turtle: this facilitates concatenating Turtle files, which I use often.

SPARQL:

  • Prefix redeclaration or redefinition is allowed in Jena (https://sparql.org/sparql.html).
  • Neither prefix redeclaration nor redefinition is allowed in rdf4j

SPARQL Update allows multiple updates (; separated sections).

TARQL supports SELECT and CONSTRUCT (not Update) and allows multiple CONSTRUCT in the same query (a non-standard extension)

Afaik both Query spec and Update spec are silent on this point. I propose to add a section before the SPARQL grammar:

Prefix Reuse, Redeclaration and Redefinition

  • SPARQL Query does not allow the same prefix to be declared multiple times.
    Query processors should return a syntax error
  • SPARQL Update allows multiple updates (; separated sections) in the same query.
    Each section may have its own BASE and PREFIX definitions, and these are carried over to subsequent sections.
  • The same prefix can be redeclared several times to the same namespace.
    However, redefining a prefix to a different namespace is not allowed: Update processors should return a syntax error.
  • Redefining BASE to a new namespace is allowed between sections
@afs
Copy link
Contributor

afs commented Feb 13, 2025

Same as Turtle.

I don't see any text that says it is an error to mention a prefix name more than once.

SPARQL Update operation boundaries are not significant in the parsing process. It is the structure and execution of "update" that has the concept of boundaries.

PREFIX applies to the parsing process - the document from that point onwards.
Multiple BASE are allowed. (And all IRIs are resolved - PREFIX IRIs can be relative references)

Any spec defines what is correct, and can not cover every error possibility, the spec would more than double in size; there are more errors than correct behaviour.

If you want clarification, the best way is to submit a PR to rdf-tests which is more than the previous WG's test suite.

TARQL behavior is not as intended and that is acknowledged in the issue.

Please do not reference private JIRA.

The user experience such as indicating strange or unusual input is a product issue.

@TallTed
Copy link
Member

TallTed commented Feb 14, 2025

Please don't question anyone's mental health nor make such disparaging remarks about our possible data export habits.

Please also don't forbid redefinition of a single prefix to a different namespace within a Turtle document. There are plenty of situations where the same generic prefixes (e.g., prefix1:) might be used when multiple queries are used to output multiple Turtle data files which might then be concatenated for loading into another system or graph.

  • Prefix redeclaration or redefinition is allowed [in SPARQL]

Yes, and it should remain so.

GraphDB allows redeclaring prefixes (good), but if a section has ANY prefixes then the prefixes from prior sections are forgotten

The forgetfulness is certainly a bug. I don't know why it should be evidence that we should specify or forbid anything.

SPARQL Query does not allow the same prefix to be declared multiple times.

It should. Just like Turtle.

Query processors should return a syntax error

No.

SPARQL Update allows multiple updates (; separated sections) in the same query.
Each section may have its own BASE and PREFIX definitions, and these are carried over to subsequent sections.
The same prefix can be redeclared several times to the same namespace.

Sounds right.

However, redefining a prefix to a different namespace is not allowed:

It should be.

Update processors should return a syntax error.

Nope.

Redefining BASE to a new namespace is allowed between sections

As it should be. Might be should be allowed in more locations than that.

@VladimirAlexiev
Copy link
Author

@TallTed

SPARQL Query does not allow the same prefix to be declared multiple times.
It should. Just like Turtle.

A SPARQL query is a single query. The prefixes all come at the beginning.

  • Can you give one useful scenario where the same prefix is mentioned twice?
  • Or a concatenation scenario that will result in the same prefix being mentioned twice?

@afs

I don't see any text that says it is an error to mention a prefix name more than once.
PREFIX applies to the parsing process - the document from that point onwards.

Where does it say that? IMHO there isn't any text to say which prefix wins in such case.

Multiple BASE are allowed. (And all IRIs are resolved - PREFIX IRIs can be relative references)

This is indeed the behavior explicitly specified by Turtle 1.2 (references in w3c/rdf-turtle#87).
But I don't see such specific wording in the SPARQL specs.

Any spec defines what is correct

@abrokenjester
The fact is that a major SPARQL implementation (rdf4j) has a bug in that regard. And IMHO that's because the spec is not clear enough (unlike the Turtle 1.2 spec)

@Tpt
Copy link
Contributor

Tpt commented Feb 17, 2025

Can you give one useful scenario where the same prefix is mentioned twice?

If a system wants to provide default SPARQL prefixes, an easy way to do it is to concatenate the user query to the default list of prefixes. This way if the user wants to overrides some prefixes, they can but the query can still make use of the default prefixes.

@TallTed
Copy link
Member

TallTed commented Feb 17, 2025

SPARQL Query does not allow the same prefix to be declared multiple times.

It should. Just like Turtle.

A SPARQL query is a single query. The prefixes all come at the beginning.

  • Can you give one useful scenario where the same prefix is mentioned twice?
  • Or a concatenation scenario that will result in the same prefix being mentioned twice?

Just as @Tpt says above, a number of deployments have a set of default prefixes which they prepend to all user queries and on which some users depend (by not including any prefix declarations in their queries), while other users put their own set of prefixes into all their queries (which is, after all, the only way users can be certain what prefixes are in effect for their query).

These deployment decisions rely on both the ability to change the prefix declaration and the ability to re-declare identically.

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

No branches or pull requests

4 participants