SPARQL BASE keyword not supported

55 views
Skip to first unread message

Andy

unread,
Jul 31, 2009, 2:20:37 PM7/31/09
to OpenAnzo
SPARQL section 4.1.1 describes the BASE keyword for use with relative
IRIs. Using the BASE keyword in a SPARQL query generates an
application error with Anzo nightly build 2009-07-27 from the command
line:

anzo query "BASE <http://example.org/> DESCRIBE <person/1>"

generates:

Parse error: Encountered "BASE" at line 1, column 1.
Was expecting one of:
"prefix" ...
"select" ...
"construct" ...
"ask" ...
"describe" ...
BASE <http://example.org/> DESCRIBE <person/1>
^
Error executing command:[query failed]

Lee Feigenbaum

unread,
Jul 31, 2009, 2:30:12 PM7/31/09
to open...@googlegroups.com
Actually, the Open Anzo SPARQL engine (Glitter) does indeed support the
BASE keyword. What you're seeing here is a bug in the command-line
client (the CLI). The 'anzo query' CLI command attempts to aid you in
writing queries by prepending PREFIX declarations for prefixes in your
settings.trig file; but because the BASE keyword must come _before_ all
prefixes in a SPARQL query, this leads to a (non-obvious) syntax error
in this particular case.

I've opened a ticket for this and will follow-up in this thread once
it's resolved.

In the meantime, if you issue queries via the API, the BASE ketword
should work as specified.

Lee
--
Lee Feigenbaum
VP Technology & Standards, Cambridge Semantics Inc
l...@cambridgesemantics.com
1-617-553-1060

Lee Feigenbaum

unread,
Jul 31, 2009, 2:33:37 PM7/31/09
to open...@googlegroups.com
Sorry, I forgot to add here that another alternative is to use the -x
flag on the 'anzo query' command line - this suppresses the automatic
inclusion of prefixes and so will avoid the parse error.

best,
Lee

Jordi Albornoz Mulligan

unread,
Jul 31, 2009, 2:51:18 PM7/31/09
to open...@googlegroups.com
Lee Feigenbaum wrote:
> Sorry, I forgot to add here that another alternative is to use the -x
> flag on the 'anzo query' command line - this suppresses the automatic
> inclusion of prefixes and so will avoid the parse error.

Also, if you'd like to keep the convenience of the the automatic prefix
stuff and still use a base IRI, you can supply the base IRI via the -b
option in the 'anzo query' command line rather than in the query.

You can get info on the options by executing: anzo help query


--
Jordi Albornoz Mulligan
Founding Engineer - Cambridge Semantics
jo...@cambridgesemantics.com
(617) 401-7321

Andy

unread,
Jul 31, 2009, 3:39:58 PM7/31/09
to OpenAnzo
Seems like even if you do "anzo query -f file.rq" the command line
will also add those automatic prefixes too.

However, there seems to be something wrong with application of BASE.
Lets look at the following TRIG:

@base <http://example.org/> .

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix domain: <http://example.org/> .
@prefix class: <http://example.org/class/> .
@prefix property: <http://example.org/property/> .

domain:person
{
<person/5> rdf:type class:person .
<person/5> property:id "5"^^xsd:unsignedInt .
<person/5> property:name "Carol"^^xsd:string .
<person/5> property:gender "female"^^xsd:string .

<person/10> rdf:type class:person .
<person/10> property:id "10"^^xsd:unsignedInt .
<person/10> property:name "Thom"^^xsd:string .
<person/10> property:gender "male"^^xsd:string .
}

Now lets run the following SPARQL against it:

BASE <http://example.org/>

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

PREFIX domain: <http://example.org/>
PREFIX class: <http://example.org/class/>
PREFIX property: <http://example.org/property/>

CONSTRUCT
{
?s ?p ?o .
}
FROM NAMED domain:person
WHERE
{
GRAPH domain:person
{
?s a class:person ;
?p ?o .
FILTER ( ?s = <person/5> ) .
}
}

This SPARQL results in an error:

Error executing command:[query failed] Root Cause: No colon in URI:
[person/1]

Looks like the BASE keyword wasn't applied to the <person/5> relative
URI in the FILTER clause. Lets change the SPARQL slightly to the
following:

BASE <http://example.org/>

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

PREFIX domain: <http://example.org/>
PREFIX class: <http://example.org/class/>
PREFIX property: <http://example.org/property/>

CONSTRUCT
{
<person/5> ?p ?o .
}
FROM NAMED domain:person
WHERE
{
GRAPH domain:person
{
<person/5> a class:person ;
?p ?o .
}
}

You still get the same error on the <person/5> relative URI. However,
changing these relative URIs to absolute URIs the SPARQL queries work
as expected.


On Jul 31, 2:33 pm, Lee Feigenbaum <l...@cambridgesemantics.com>
wrote:
> 1-617-553-1060- Hide quoted text -
>
> - Show quoted text -

Lee Feigenbaum

unread,
Aug 17, 2009, 1:14:53 PM8/17/09
to open...@googlegroups.com
Hi Andy,

Thanks. This has been fixed in a recent commit. You'll have to wait for
the next nightly, but then this problem should be gone - the data &
query you've got below work correctly for me now.

Lee
Reply all
Reply to author
Forward
0 new messages