Re: [spr35236] Problem with namespace resolution for AG in CL
Richard Newman <[email protected]> Tue, 28 Oct 2008 11:45:41 -0700
| Newsgroups | gmane.lisp.allegro |
|---|---|
| Message-ID | <[email protected]> |
Hi Stewart,
> but when I run a simple query like (sparql:run-sparql " SELECT DISTINCT ?s ?o
> WHERE { ?s rdfs:subClassOf ?o}"), I get this error (and the same for any other
> Qnames I try to use):
AllegroGraph's namespace mechanism is used for resolving future-parts with the '!' syntax: e.g.,
(add-triple !rdf:type !rdfs:label !"type")
It doesn't apply to SPARQL, because the SPARQL standard specifies its own namespace prefix mechanism.
The correct way to do things in SPARQL is
(sparql:run-sparql "
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?s ?o
WHERE {
?s rdfs:subClassOf ?o
}")
As a shorthand, you can supply a hash-table of the correct 'shape' as the value of the :default-prefixes argument, which
*namespaces* just so happens to be:
(sparql:run-sparql "
SELECT DISTINCT ?s ?o
WHERE {
?s rdfs:subClassOf ?o
}"
:default-prefixes db.agraph::*namespaces*)
This is mentioned in the documentation for run-sparql if you would like more details.
While convenient, this approach is generally inadvisable for 'real' code that you intend to keep and continue to use,
because the binding of *namespaces* can change.
If it does, the meaning of your query will change: for example, rdfs: could expand to a different URI, or it could be
removed entirely (resulting in a query parse error at runtime).
Let me know if that answers your question.
Regards,
-Richard