import inf.unibz.it.dl.domain.NamedConcept;
import inf.unibz.it.obda.owlapi.OWLAPIController;
import inf.unibz.it.obda.owlapi.sparql.SPARQLPrefixBuilder;
import inf.unibz.it.ucq.domain.ConceptQueryAtom;
import inf.unibz.it.ucq.domain.ConjunctiveQuery;
import inf.unibz.it.ucq.domain.QueryResult;
import inf.unibz.it.ucq.domain.UnionOfConjunctiveQueries;
import inf.unibz.it.ucq.domain.VariableTerm;
import inf.unibz.it.ucq.parser.sparql.UCQTranslator;
import it.fub.inf.quonto.owlapi.QuontoOWLReasonerFactory;
import it.fub.inf.quonto.owlapi.QuontoOWLReasonerWrapper;
import it.uniroma1.dis.quonto.QuontoConfiguration;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.util.Properties;
import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyManager;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryFactory;
public class example1 {
public static String owlfile = "/Users/mariano/ontologies/example3/example3.owl";
public static String configFile = "config.properties";
public static void main(String args[]) {
QuontoOWLReasonerWrapper reasoner = null;
try {
// Loading the OWL file
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntologyFromPhysicalURI((new File(owlfile)).toURI());
// Loading the OBDA data (note, the obda file must be in the same folder as the owl file
OWLAPIController controller = new OWLAPIController(manager, ontology);
controller.loadData(new File(owlfile).toURI());
// Creating a new instance of a quonto reasoner
QuontoOWLReasonerFactory factory = new QuontoOWLReasonerFactory();
factory.setOBDAController(controller);
reasoner = (QuontoOWLReasonerWrapper) factory.createReasoner(manager);
reasoner.loadOntologies(manager.getOntologies());
// Loading a set of configurations for the reasoner and giving them to quonto
Properties properties = new Properties();
properties.load(new FileInputStream(configFile));
QuontoConfiguration config = new QuontoConfiguration(properties);
reasoner.setConfiguration(config);
// One time classification call.
reasoner.classify();
// Now we are ready for querying
ConjunctiveQuery cq = new ConjunctiveQuery();
VariableTerm term1 = new VariableTerm("x");
cq.addHeadTerm(term1);
ConceptQueryAtom atom1 = new ConceptQueryAtom(new NamedConcept(URI.create("Person")), term1);
cq.addQueryAtom(atom1);
UnionOfConjunctiveQueries ucq = new UnionOfConjunctiveQueries();
ucq.addQuery(cq);
// Executing the query
QueryResult result = reasoner.answerUCQ(ucq);
// Printing the results
System.out.println("Results:");
int cols = result.getColumnCount();
while (result.nextRow()) {
for (int i = 0; i < cols; i++) {
System.out.print(result.getConstantFromColumn(i) + " ");
}
System.out.println("");
}
System.out.println("-------------------");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
reasoner.dispose();
} catch (Exception e) {
}
}
}
}