Dmitry Frank
Dmitry Frank

Reputation: 10767

OpenRDF Sesame: can't define prefix

I am trying to build correct query for my test server, and i am faced the problem that i'm not able to define PREFIX.

For instance, this query works:

select * where
{
   ?stayingURL <http://localhost/resource_lng> ?lng .
   ?stayingURL <http://localhost/resource_staying_date> ?date .
   ?stayingURL <http://localhost/resource_address> ?address .
}
LIMIT 100

I try to add filter by date, just like that:

select * where
{
   ?stayingURL <http://localhost/resource_lng> ?lng .
   ?stayingURL <http://localhost/resource_staying_date> ?date .
   ?stayingURL <http://localhost/resource_address> ?address .
   FILTER (?date > "2012-01-01"^^xsd:date)
}
LIMIT 100

Now i got the following error: "MALFORMED QUERY: org.openrdf.query.parser.sparql.ast.VisitorException: QName 'xsd:date' uses an undefined prefix"

OK, i try to declare this prefix manually by adding the following line to the start of query:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

Now i got this error:

MALFORMED QUERY: Encountered " "<" "< "" at line 1, column 14.
 Was expecting:
 <Q_IRI_REF> ...

This is pretty strange for me, but anyway i tried to write it directly, without any prefix:

select * where
{
 ?stayingURL <http://localhost/resource_lng> ?lng .
 ?stayingURL <http://localhost/resource_staying_date> ?date .
 ?stayingURL <http://localhost/resource_address> ?address .
 FILTER (?date > "2012-01-01"^^<http://www.w3.org/2001/XMLSchema#date> )
 }
LIMIT 100

Result is almost the same:

MALFORMED QUERY: Encountered " "<" "< "" at line 1, column 228.
Was expecting one of:
    <Q_IRI_REF> ...
    <PNAME_NS> ...
    <PNAME_LN> ...

What am I doing wrong?

Here's my server address: http://176.34.226.101:8080/openrdf-sesame/repositories/ecomobile .

Upvotes: 3

Views: 2780

Answers (1)

Manuel Salvadores
Manuel Salvadores

Reputation: 16525

It works for me if I URI encode all the query parameter:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select * where
{
 ?stayingURL <http://localhost/resource_lng> ?lng .
 ?stayingURL <http://localhost/resource_staying_date> ?date .
 ?stayingURL <http://localhost/resource_address> ?address .
 FILTER (?date > "2012-01-01"^^<http://www.w3.org/2001/XMLSchema#date> )
 }
LIMIT 100

This would be the request:

http://176.34.226.101:8080/openrdf-sesame/repositories/ecomobile?query=PREFIX%20xsd%3A%20%3Chttp%3A//www.w3.org/2001/XMLSchema%23%3E%20select%20%2A%20where%0A%7B%0A%20%20%20%3FstayingURL%20%3Chttp%3A//localhost/resource_lng%3E%20%3Flng%20.%0A%20%20%20%3FstayingURL%20%3Chttp%3A//localhost/resource_staying_date%3E%20%3Fdate%20.%0A%20%20%20%3FstayingURL%20%3Chttp%3A//localhost/resource_address%3E%20%3Faddress%20.%0A%20%20%20FILTER%20%28%3Fdate%20%3E%20%222012-01-01%22%5E%5Exsd%3Adate%29%0A%7D%0ALIMIT%20100

Apologies for the cryptic unreadable URI ... a shorten version here:

http://bit.ly/xTQhSV

Upvotes: 4

Related Questions