Search code examples
sparqlsemantic-webontology

Where is my mistake in this SPARQL query?


"@PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " +
            "SELECT ?o ?stringTest ?boolTest " +
            "where { "+
            "?s ?p ?o . "+
            "BIND (xsd:string(?o) as ?stringTest). " +
            "BIND (xsd:boolean(?o) as ?boolTest) "+
            
            "}\n ";

I am trying to execute this using Jena in Eclipse, but I can't find my mistake. It is very simple query and I can not figure what my mistake is. Can anybody gice me some feedback?

Here is only SPARQL code:

@PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            SELECT ?o ?stringTest ?boolTest
            where { 
            ?s ?p ?o . 
            BIND (xsd:string(?o) as ?stringTest). 
            BIND (xsd:boolean(?o) as ?boolTest) 
            
            }

And this is the error I am getting:

Encountered " <LANGTAG> "@prefix "" at line 1, column 1.
Was expecting one of:
    "\ufeff" ...
    "base" ...
    "prefix" ...
    "select" ...
    "describe" ...
    "construct" ...
    "ask" ...

Solution

  • As the error says, the SPARQL processor encountered @prefix where it expected prefix.

    SPARQL 1.1 syntax uses PREFIX (no @ sign).

    Turtle 1.1 syntax uses either @PREFIX (dating from before SPARQL) or PREFIX (now preferred, as it harmonizes with SPARQL 1.1).