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

IMPORT NAMESPACES #187

Open
kurtcagle opened this issue May 23, 2023 · 6 comments
Open

IMPORT NAMESPACES #187

kurtcagle opened this issue May 23, 2023 · 6 comments

Comments

@kurtcagle
Copy link

Why?

I may have missed this in the SPARQL 1.2 suggestions, but it has been on my wish list for a while.

Namespace management in SPARQL is a pane. Different systems handle namespaces in different ways, some providing user or system namespaces if no namespaces are provided, others requiring that namespaces must be declared. When you're potentially dealing with dozens of namespaces, this makes namespace declarations a frequent source for problems, especially when different people may have to manually enter these.

Previous work

Jena currently requires namespace declarations regardless, Allegrograph defines user and system namespace declarations, others tend to be all over the place.

Proposed solution

Create a new directive in SPARQL called IMPORT NAMESPACES that would either link to an RDF file with prefix declarations or would load the namespaces from a system-defined namespaces file if the default keyword was applied.

It would have the following form:

IMPORT NAMESPACES <URL>|SYSTEM|USER NOCACHE?

This would import the namespace and prefix declarations then keep a cached (and optimized) version of this CONTEXT object in memory. If the NOCACHE directive was used, then this would reload the namespaces prior to making the query (which might be the case if the namespaces themselves are under development).

The query could contain more than one such import statement. If namespaces and prefixes are the same from multiple declarations, duplications would be ignored. If the prefixes are the same but namespaces are different, then the engine should throw an exception. A namespace can have more than one distinct prefix.

IMPORT NAMESPACES must precede PREFIX statements.

IMPORT NAMESPACES <file:///c:/path/to/namespaces.ttl>
IMPORT NAMESPACES <https://myCommonNamespaces.ttl>
PREFIX someNS: <http://somenamespace.com/not/in/others#>

SELECT ?car ?vin where {
     ?car schema:vin ?vin.
} order by ?vin 

or

IMPORT NAMESPACES system

SELECT ?car ?vin where {
     ?car schema:vin ?vin.
} order by ?vin 

or

IMPORT NAMESPACES user


SELECT ?car ?vin where {
     ?car schema:vin ?vin.
     
} order by ?vin 

The assumption on behavior is that collisions would be resolved as if the imported namespaces had been included inline.

If the IMPORT NAMESPACES path is not included, then either system or user must be included. This indicates that whatever is currently defined as a system or user namespace set be loaded. If neither of these are defined, this would throw an error.

If no IMPORT NAMESPACES expression is included, then only items defined by PREFIX are added as namespaces. PREFIX declared namespaces would override any imported namespaces, or throw an exception if that is the default behavior of the database.

The system would load the namespaces from the turtle file and would otherwise ignore the contents of the file. Once loaded, the

Considerations for backward compatibility

The default behavior if IMPORT NAMESPACES is not included is to only include PREFIX'd namespace declarations, which should be the case normally.

@namedgraph
Copy link

I don't think the query string should depend on external data.

@kurtcagle
Copy link
Author

A variant to this was brought up previously: #70. I'll update this if I find any other mentions.

@MichaelSullivanArchitect
Copy link

@VladimirAlexiev
Copy link
Contributor

VladimirAlexiev commented Jul 20, 2024

@kurtcagle many databases (including GraphDB) automatically add newly encountered prefixes to their namespaces.
So there's no need for a new command

IMPORT NAMESPACES <file:///c:/path/to/namespaces.ttl>

If that file has only prefix declarations, LOAD will do just the same.

@ericprud
Copy link
Member

ericprud commented Aug 6, 2024

If the query uses prefixes that are declared differently in LOADed documents, query behavior will dependent on their order (which could be a bit painful to debug). That reassignment scenario may seem unlikely but I've seen a fair amount of confusion WRT the wd* prefixes in Wikidata.

@VladimirAlexiev
Copy link
Contributor

@namedgraph

I don't think the query string should depend on external data.

Agreed! Query editors can automatically add prefixes, but query runners should not.

@ericprud

That reassignment scenario may seem unlikely
query behavior will dependent on their order

The repos I know don't overrider prefixes when they see a new definition.

  • I think this is the right behavior.
  • And I think the often seen practice of using the : prefix to define own terms in an ontology is BAD.

Query editor behavior should depend on defined namespaces / captured prefixes.
So the user will see immediately what namespace is used by his/her repository.
If a user wants to redefine a namespace in the repository, then they have to use a custom repo function (namespace management).
Unless we define a new command DELETE PREFIX...

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

5 participants