Skip to content
Guohui Xiao edited this page Sep 18, 2013 · 4 revisions

Using Quest Reasoner

Table of Contents

From Protege

Quest is included in the OBDA Plugin package. If you installed the OBDA Plugin, you will see Quest in the "reasoners" menu. To initialise Quest simply click the "classify" button. To query Quest with SPARQL or another supported language, use the OBDA Query Tab.

It is important to configure the mode in which Quest is supposed to work, e.g., virtual or classic. To do that, use the Quest tab in Protege's preferences. You can get to the Protege's Preference Dialog by going into the main menu of Protege and clicking "Preferences". You should see the dialog shown next. An explanation of each of the configuration parameters is described in the Configuration Documentation.


From Java Code

You can use Quest from Java similar to a traditional OWLAPI 2 reasoner, however, with some small extensions to accomodate the OBDA requirements. The following is an example of a simple program that loads an ontology and OBDA model into Quest, to query in virtual OBDA mode. Refer to the inline comments of the Java example for more details.

#java
import it.unibz.krdb.obda.io.DataManager;
import it.unibz.krdb.obda.model.OBDADataFactory;
import it.unibz.krdb.obda.model.OBDAMappingAxiom;
import it.unibz.krdb.obda.model.OBDAModel;
import it.unibz.krdb.obda.model.OBDAQuery;
import it.unibz.krdb.obda.model.OBDAResultSet;
import it.unibz.krdb.obda.model.OBDAStatement;
import it.unibz.krdb.obda.model.impl.OBDADataFactoryImpl;

import it.unibz.krdb.obda.owlapi.ReformulationPlatformPreferences;

import it.unibz.krdb.obda.owlrefplatform.core.QuestOWL;
import it.unibz.krdb.obda.owlrefplatform.core.QuestOWLFactory;

import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyManager;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Set;

public class QuestTest {

	private static final String owlFileName = "book-publication.owl";
	private static final String obdaFileName = "book-publication.obda";
	
	public static void main(String[] args) {
	
		URI owlUri = new File(owlFileName).toURI();
		URI obdaUri = new File(obdaFileName).toURI();
		try {
			// Load the OWL file using the OWL API
			OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
			OWLOntology ontology = manager.loadOntologyFromPhysicalURI(owlUri);
        
			// Load the OBDA model using the OBDALib-Core
			OBDADataFactory factory = OBDADataFactoryImpl.getInstance();
			OBDAModel model = factory.getOBDAModel();
			DataManager ioManager = new DataManager(model);
			ioManager.loadOBDADataFromURI(obdaUri, ontology.getURI(), model.getPrefixManager());
			
			// Setup Quest to work in virtual mode 
			ReformulationPlatformPreferences pref = new ReformulationPlatformPreferences();
			pref.setCurrentValueOf("org.obda.owlreformulationplatform.aboxmode", "virtual");
			
                        // Load the ontology, OBDA model and preferences into Quest and classify
			QuestOWLFactory reasonerFactory = new QuestOWLFactory();
			QuestOWL reasoner = (QuestOWL)reasonerFactory.createReasoner(manager);
			reasoner.loadOntologies(manager.getOntologies());
			reasoner.loadOBDAModel(model);
			reasoner.setPreferences(pref);
			reasoner.classify();
			
			// Now we are ready for querying.
			String query = 
				"PREFIX : <http://meraka/moss/exampleBooks.owl#><br>n" +
				"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#><br>n" +
				"select ?title ?author where { ?x :writtenBy ?y. ?x :title ?title. ?y :name ?author. }";

			// To query, get an OBDAStatement from Quest, and execute the query using that statement
			// This is just like JDBC, so remember to close the statement when you are done
			OBDAStatement stmt = reasoner.getStatement();
			OBDAResultSet result = stmt.executeQuery(query);
			
			// Print the result
			while (result.nextRow()) {
				String row = String.format("%s by %s", result.getAsString(1), result.getAsString(2));
				System.out.println(row);
			}

			result.close();
			stmt.close();

                        reasoner.disconnect();
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

To compile and run this program you will need to import Quest, the OBDALib-Core and all their dependencies into your classpath. These are included in the .zip file that you can download from our website. The list of all the dependencies is as follows:

lib/antlr-2.7.5.jar
lib/antlr-3.1.3.jar
lib/antlr-runtime-3.1.3.jar
lib/arq-2.2.jar
lib/arq-extra-2.2.jar
lib/commons-cli-1.1.jar
lib/commons-logging-1.1.1.jar
lib/concurrent-jena-1.3.2.jar
lib/h2-1.3.157.jar
lib/icu4j-3.4.4.jar
lib/iri-0.5.jar
lib/jena-2.5.5.jar
lib/jenatest-2.5.5.jar
lib/json-jena-1.0.jar
lib/log4j-1.2.12.jar
lib/logback-classic-0.9.20.jar
lib/logback-core-0.9.20.jar
lib/lucene-core-2.2.0.jar
lib/obdalib-core-1.6.jar
lib/obdalib-owlapi-1.6.jar
lib/owlapi-2.2.0-r1317.jar
lib/reformulation-core-1.6.jar
lib/relaxngDatatype-20050407.jar
lib/slf4j-api-1.5.11.jar
lib/stax-api-1.0.jar
lib/stringtemplate-3.2.jar
lib/wstx-asl-3.0.0.jar
lib/xercesImpl-2.7.1.jar
lib/xmlParserAPIs-2.0.2.jar
lib/xsdlib-20030225.jar
logback-test.xml   

If you are working in virtual mode, you will also need include the jars for the JDBC drivers for your particular database.

Clone this wiki locally