You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by Nallanchakravarthy Ramadurai Ananthanarayanan <dr...@gmail.com> on 2012/01/19 06:07:20 UTC
ERROR IN SPARQL Query
package QueryBuilder;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class Query4 {
public static void main(String[] args) throws IOException {
InputStream in = new FileInputStream(new File("d:/PROJECT/vc-db-1.rdf"));
// Create an empty in-memory model and populate it from the graph
Model model = ModelFactory.createMemModelMaker().createDefaultModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close();
// Create a new query
String queryString= "{<http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?g
WHERE { ?y Given ?g . FILTER regex(?g, 'r', 'i')}}";
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
// Important - free up resources used running the query
qe.close();
}
}
Error
-------
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException:
Encountered " "{" "{ "" at line 1, column 1.
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"describe" ...
"construct" ...
"ask" ...
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 com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28)
at QueryBuilder.Query4.main(Query4.java:25)
Re: ERROR IN SPARQL Query
Posted by Bruce Craig <rb...@gmail.com>.
It can also be very helpful to trial the query syntax in a Fuseki server
control panel or using the command line options of ARQ.
There are some syntax checking tools around also but I have not used.
Bruce
On Thu, Jan 19, 2012 at 12:38 AM, Ashwini Balu <as...@smartnapps.com>wrote:
> Hi,
> Check out SPARQL query syntax http://www.w3.org/TR/rdf-sparql-query/
>
>
> -----Original Message-----
> From: Nallanchakravarthy Ramadurai Ananthanarayanan
> [mailto:drnrananthanarayanen@gmail.com]
> Sent: 19 January 2012 10:37
> To: jena-dev@incubator.apache.org
> Subject: ERROR IN SPARQL Query
>
> package QueryBuilder;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import com.hp.hpl.jena.query.Query;
> import com.hp.hpl.jena.query.QueryExecution;
> import com.hp.hpl.jena.query.QueryExecutionFactory;
> import com.hp.hpl.jena.query.QueryFactory;
> import com.hp.hpl.jena.query.ResultSet;
> import com.hp.hpl.jena.query.ResultSetFormatter;
> import com.hp.hpl.jena.rdf.model.Model;
> import com.hp.hpl.jena.rdf.model.ModelFactory;
>
>
> public class Query4 {
> public static void main(String[] args) throws IOException {
> InputStream in = new FileInputStream(new File("d:/PROJECT/vc-db-1.rdf"));
> // Create an empty in-memory model and populate it from the graph
> Model model = ModelFactory.createMemModelMaker().createDefaultModel();
> model.read(in,null); // null base URI, since model URIs are absolute
> in.close();
> // Create a new query
> String queryString= "{<http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?g
> WHERE { ?y Given ?g . FILTER regex(?g, 'r', 'i')}}";
> Query query = QueryFactory.create(queryString);
> // Execute the query and obtain results
> QueryExecution qe = QueryExecutionFactory.create(query, model);
> ResultSet results = qe.execSelect();
> // Output query results
> ResultSetFormatter.out(System.out, results, query);
>
> // Important - free up resources used running the query
> qe.close();
>
> }
> }
>
> Error
> -------
> Exception in thread "main" com.hp.hpl.jena.query.QueryParseException:
> Encountered " "{" "{ "" at line 1, column 1.
> Was expecting one of:
> "base" ...
> "prefix" ...
> "select" ...
> "describe" ...
> "construct" ...
> "ask" ...
>
> 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 com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28)
> at QueryBuilder.Query4.main(Query4.java:25)
>
>
>
RE: ERROR IN SPARQL Query
Posted by Ashwini Balu <as...@smartnapps.com>.
Hi,
Check out SPARQL query syntax http://www.w3.org/TR/rdf-sparql-query/
-----Original Message-----
From: Nallanchakravarthy Ramadurai Ananthanarayanan
[mailto:drnrananthanarayanen@gmail.com]
Sent: 19 January 2012 10:37
To: jena-dev@incubator.apache.org
Subject: ERROR IN SPARQL Query
package QueryBuilder;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class Query4 {
public static void main(String[] args) throws IOException {
InputStream in = new FileInputStream(new File("d:/PROJECT/vc-db-1.rdf"));
// Create an empty in-memory model and populate it from the graph
Model model = ModelFactory.createMemModelMaker().createDefaultModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close();
// Create a new query
String queryString= "{<http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?g
WHERE { ?y Given ?g . FILTER regex(?g, 'r', 'i')}}";
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
// Important - free up resources used running the query
qe.close();
}
}
Error
-------
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException:
Encountered " "{" "{ "" at line 1, column 1.
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"describe" ...
"construct" ...
"ask" ...
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 com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28)
at QueryBuilder.Query4.main(Query4.java:25)