简体   繁体   中英

owlapi HERMIT and SPARQL

How is it possible to execute a SPARQL Query in Java using the HERMIT reasoner 1.3.8? I'm using owlapi 4.2 and i have loaded the HERMIT reasoner using:

OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
OWLReasoner reasonerHermit = reasonerFactory.createReasoner(ontology);

Unfortunately i could not find any explanation how to execute a SPARQL Query with this reasoner?! Is this possible at all? If not, what other possibilities (other reasoners) do i have using owlapi and SPARQL?

EDIT:

I now know that i need a SPARQL Engine. This is why i used SPARQL-DL like this:

QueryEngine engine = QueryEngine.create(manager, reasoner, true);
Query query = Query.create("...");
QueryResult result = engine.execute(query);
System.out.println(result);

The query works, but if I'm now getting something like

?de.derivo.sparqldlapi.Var@69 = http://www.example.com/project1#document_1

how do i get out the http://www.example.com/project1#document_1 ? I could not find a proper Method for getting this value.

HermiT is an OWL reasoner and not a SPARQL engine. There is an API called SPARQL-DL, but according to its website it supports just OWL API v3.x. A newer forked version with OWL API 4 support can be found as part of the Protege project: https://github.com/protegeproject/sparql-dl-api

Looking at the source for QueryResult, available here , what you have there is a query binding. You have methods to iterate over all the bindings, and you should find the value you are after in the bound values of the binding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM