You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Christian Fuerber <c....@unibw.de> on 2011/11/15 17:58:24 UTC

Problem with SPARQL NOT EXISTS over Jena

Dear all,

I experience some problems with query execution over jena. For some reason I
cannot execute the following query to my local TDB:

         String queryString = 
				"PREFIX
dqm:<http://purl.org/dqm-vocabulary/v1.1/dqm#>" +
				"PREFIX
xsd:<http://www.w3.org/2001/XMLSchema#>" +
				"SELECT ?dqr ?i" +
				"WHERE {" +
				"?dqr a dqm:PropertyCompletenessRule ." +
				"?dqr dqm:testedClass ?tclass ." +
				"?dqr dqm:testedProperty1 ?tprop ." +
				"?dqr dqm:requiredValue
\"true\"^^xsd:boolean ." +
				"?dqr dqm:requiredProperty
\"true\"^^xsd:boolean ." +
				"?tclass dqm:hasURI ?tclassreal ." +
				"?tprop dqm:hasURI ?tpropreal ." +
				"BIND (IRI(str(?tpropreal)) AS ?tpropURI) ."
+
				"BIND (IRI(str(?tclassreal)) AS ?tclassURI)
." +
				"{" +
				"?i a ?tclassURI ." +
				"NOT EXISTS{" +
				"?i ?tpropURI ?value ." +
				"}" +
				"}UNION{" +
				"?i a ?tclassURI ." +
				"?i ?tpropURI \"\"." +
				"}" +
				"}";	
        String directory = "D:/Fuseki-0.2.0/DB" ;
        Dataset ds = TDBFactory.createDataset(directory) ;
        Query query =
QueryFactory.create(queryString,Syntax.syntaxSPARQL_11);		
        QueryExecution qe = QueryExecutionFactory.create(query, ds);
        ResultSet results = qe.execSelect();
        System.out.print(ResultSetFormatter.asText(results));

When I execute the above code, I receive the following error:

Exception in thread "main" com.hp.hpl.jena.query.QueryParseException:
Encountered " <NOTEXISTS> "NOT EXISTS "" at line 1, column 478.
Was expecting one of:
    <IRIref> ...
    <PNAME_NS> ...
    <PNAME_LN> ...
    <BLANK_NODE_LABEL> ...
    <VAR1> ...
    <VAR2> ...
    "graph" ...
    "optional" ...
    "minus" ...
    "bind" ...
    "service" ...
    "filter" ...
    "true" ...
    "false" ...
    <INTEGER> ...
    <DECIMAL> ...
    <DOUBLE> ...
    <INTEGER_POSITIVE> ...
    <DECIMAL_POSITIVE> ...
    <DOUBLE_POSITIVE> ...
    <INTEGER_NEGATIVE> ...
    <DECIMAL_NEGATIVE> ...
    <DOUBLE_NEGATIVE> ...
    <STRING_LITERAL1> ...
    <STRING_LITERAL2> ...
    <STRING_LITERAL_LONG1> ...
    <STRING_LITERAL_LONG2> ...
    "(" ...
    <NIL> ...
    "{" ...
    "}" ...
    "[" ...
    <ANON> ...
    
	at
com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:87)
	at
com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse(ParserSPARQL11.java:40)
	at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:132)
	at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:69)
	at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
	at SPARQLTDB.main(SPARQLTDB.java:46)

Other queries without NOT EXISTS work fine. The query also executes on
FUSEKI's query UI without any problems.

Thanks for your help,

Christian 

------------------------------------------
Dipl.-Kfm. Christian Fürber
Professur für Allgemeine BWL, insbesondere E-Business
e-business & web science research group
Universität der Bundeswehr München
 
e-mail: c.fuerber@unibw.de
www:   http://www.unibw.de/ebusiness/
skype: c.fuerber
twitter: cfuerber




Re: Problem with SPARQL NOT EXISTS over Jena

Posted by Andy Seaborne <an...@apache.org>.
On 16/11/11 10:10, Damian Steer wrote:
>
> On 15 Nov 2011, at 16:58, Christian Fuerber wrote:
>
>> Dear all,
>>
>> I experience some problems with query execution over jena. For some reason I
>> cannot execute the following query to my local TDB:
>> 			"{" +
>> 				"?i a ?tclassURI ." +
>> 				"NOT EXISTS{" +
>> 				"?i ?tpropURI ?value ." +
>> 				"}" +
>> 				"}UNION{" +
>> 				"?i a ?tclassURI ." +
>> 				"?i ?tpropURI \"\"." +
>> 				"}" +
>
> That's hard to read, but you want either *FILTER* NOT EXISTS or MINUS here. [1]

Absolutely.  Put some newlines in the query or use StrUtils.strjoin

Print the string is really helpful.

>
> Damian
>
> [1]<http://www.w3.org/TR/sparql11-query/#neg-notexists-minus>
>

Damian is correct.

Or use Syntax.synatxARQ where FILTER is not needed with NOT EXISTS.  You 
are parsing with strict SPARQL 1.1

The SPARQL-WG decided to require the word FILTER

 >> Other queries without NOT EXISTS work fine. The query also executes
 >> on FUSEKI's query UI without any problems.

because the parser is set to accept extensions.

	Andy

Re: Problem with SPARQL NOT EXISTS over Jena

Posted by Damian Steer <d....@bristol.ac.uk>.
On 15 Nov 2011, at 16:58, Christian Fuerber wrote:

> Dear all,
> 
> I experience some problems with query execution over jena. For some reason I
> cannot execute the following query to my local TDB:
> 			"{" +
> 				"?i a ?tclassURI ." +
> 				"NOT EXISTS{" +
> 				"?i ?tpropURI ?value ." +
> 				"}" +
> 				"}UNION{" +
> 				"?i a ?tclassURI ." +
> 				"?i ?tpropURI \"\"." +
> 				"}" +

That's hard to read, but you want either *FILTER* NOT EXISTS or MINUS here. [1]

Damian

[1] <http://www.w3.org/TR/sparql11-query/#neg-notexists-minus>