1

I am trying to query an ontology with the Sesame API. The usual way of querying is not possible, as it gives an UnsupportedQueryLanguageException. No factory is available for query language SPARQL.

Eventually I am querying with:

SPARQLParser parser=new SPARQLParser();
ParsedQuery query=parser.parseQuery(queryString,null);

StatementPatternCollector collector=new StatementPatternCollector();
query.getTupleExpr().visit(collector);

List<StatementPattern> patterns=collector.getStatementPatterns();

When I display the result, it doesn't contain any statements; how can I display the statements?

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • What have you tried so far? Without some code for context, it's not clear what you're asking. "Usual way of querying": what's this? – Joshua Taylor May 02 '14 at 15:22
  • Out of interest: how did you come up with this code? Reason I ask is that I remember other people doing something similar, so I wonder if there is a tutorial somewhere online that mistakenly recommends this approach for querying... – Jeen Broekstra May 02 '14 at 19:52
  • As Joshua said in his answer: this code does not execute a query, it just parses a query string. It's completely the wrong approach. The problem you're facing is one of classpath configuration, not a programming issue, you should concentrate on solving that, instead. – Jeen Broekstra May 03 '14 at 22:47

1 Answers1

2

If you're getting a UnsupportedQueryLanguageException you probably don't have your classpath set up correctly. Sesame loads things via the JDK ServiceLoader, so you're probably missing a jar file which contains the SPARQL stuff.

As far as your code snippet goes, that's not executing a SPARQL query. That's walking the algebra of the parsed query and collecting any BGP's which are contained in the query. I dont think that's what you were intending.

Double check your classpath to make sure you have the appropriate Sesame jars included and re-try the normal way of querying a Sesame Repository.

Michael
  • 4,858
  • 19
  • 32
  • 1
    Given the specific error message in the exception, I'd say OP is missing either `sesame-queryparser-sparql-.jar` or `sesame-queryparser-api-.jar`, at the very least. Some general advice: use a dependency management tool to import your Sesame libraries, like Maven or Ivy. – Jeen Broekstra May 02 '14 at 20:06
  • Yes, i got this code online. The usual way i said is with the simple way of doing this as TupleQuery tuplequery=con.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult result=tuplequery.evaluate(). – user3556249 May 03 '14 at 11:09
  • I am doing it for an Android application. If you remember i ask the similar question for loading file. That problem was solved by writing TurtleParser parser=new TurtleParser() and then using this parser in code. After, i got the problem with Query and i thought may be it could be solved in a similar way. – user3556249 May 03 '14 at 11:21
  • I now used Maven in Eclipse for my Android Application but now its unable to run ClassNotFoundException on Main Activity. – user3556249 May 03 '14 at 16:15
  • @user3556249 if you solved that other question, would you be so kind as to actually add your solution to that question as an answer there? That way, others with a similar problem can more easily find it. Thanks. – Jeen Broekstra May 03 '14 at 22:55
  • ok but i am still not sure whether its the right way how i did. This was the reason of not adding that. Kindly tell me the solution of this query problem. I found a similar question and your answer at http://stackoverflow.com/questions/14500599/sparql-parser-for-java-code but in my case SailTupleQuery() is giving problem. – user3556249 May 04 '14 at 00:00