From 4013a9d33d0f1a06b87d12dd0543912c53bba137 Mon Sep 17 00:00:00 2001 From: yzhou Date: Tue, 28 Apr 2015 17:13:55 +0100 Subject: pass the wine realisation --- test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java | 464 +++++++++++++++++++++ .../ac/ox/cs/pagoda/ore/PagodaReasonerFactory.java | 39 ++ test/uk/ac/ox/cs/pagoda/tester/ORETester.java | 21 - 3 files changed, 503 insertions(+), 21 deletions(-) create mode 100644 test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java create mode 100644 test/uk/ac/ox/cs/pagoda/ore/PagodaReasonerFactory.java delete mode 100644 test/uk/ac/ox/cs/pagoda/tester/ORETester.java (limited to 'test/uk/ac/ox') diff --git a/test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java b/test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java new file mode 100644 index 0000000..4b0c1d4 --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java @@ -0,0 +1,464 @@ +package uk.ac.ox.cs.pagoda.ore; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.semanticweb.owlapi.model.AxiomType; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLDataPropertyExpression; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; +import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyChange; +import org.semanticweb.owlapi.reasoner.AxiomNotInProfileException; +import org.semanticweb.owlapi.reasoner.BufferingMode; +import org.semanticweb.owlapi.reasoner.ClassExpressionNotInProfileException; +import org.semanticweb.owlapi.reasoner.FreshEntitiesException; +import org.semanticweb.owlapi.reasoner.FreshEntityPolicy; +import org.semanticweb.owlapi.reasoner.InconsistentOntologyException; +import org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy; +import org.semanticweb.owlapi.reasoner.InferenceType; +import org.semanticweb.owlapi.reasoner.Node; +import org.semanticweb.owlapi.reasoner.NodeSet; +import org.semanticweb.owlapi.reasoner.OWLReasoner; +import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException; +import org.semanticweb.owlapi.reasoner.TimeOutException; +import org.semanticweb.owlapi.reasoner.UnsupportedEntailmentTypeException; +import org.semanticweb.owlapi.reasoner.impl.OWLClassNodeSet; +import org.semanticweb.owlapi.util.Version; + +import uk.ac.ox.cs.JRDFox.model.GroundTerm; +import uk.ac.ox.cs.JRDFox.model.Individual; +import uk.ac.ox.cs.pagoda.query.AnswerTuples; +import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; + +public class PagodaOWLReasoner implements OWLReasoner { + + QueryReasoner reasoner; + OWLOntology ontology; + OWLDataFactory factory; + boolean sat; + + public PagodaOWLReasoner(OWLOntology ontology) { + this.ontology = ontology; + factory = ontology.getOWLOntologyManager().getOWLDataFactory(); + reasoner = QueryReasoner.getInstance(ontology); + reasoner.setToClassify(false); + reasoner.loadOntology(ontology); + sat = reasoner.preprocess(); + thing = new OWLClassNodeSet(factory.getOWLThing()); + } + + @Override + public String getReasonerName() { + return "PAGOdA"; + } + + @Override + public Version getReasonerVersion() { + return null; + } + + @Override + public BufferingMode getBufferingMode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void flush() { + // TODO Auto-generated method stub + + } + + @Override + public List getPendingChanges() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Set getPendingAxiomAdditions() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Set getPendingAxiomRemovals() { + // TODO Auto-generated method stub + return null; + } + + @Override + public OWLOntology getRootOntology() { + return ontology; + } + + @Override + public void interrupt() { + // TODO Auto-generated method stub + + } + + @Override + public void precomputeInferences(InferenceType... inferenceTypes) throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException { + if (inferenceTypes.length == 1 && inferenceTypes[0].equals(InferenceType.CLASS_ASSERTIONS) && types.isEmpty()) { + Set queriedClasses = new HashSet(); + for (OWLOntology onto: ontology.getImportsClosure()) + for (OWLClass cls: onto.getClassesInSignature(true)) { +// if (cls.toStringID().equals("http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#Meritage")); +// else continue; + if (!cls.equals(factory.getOWLThing()) && !queriedClasses.contains(cls)) { + queriedClasses.add(cls); + AnswerTuples tuples = null; + try { + tuples = reasoner.evaluate(String.format("select distinct ?x where { ?x <%s> .}", cls.toStringID())); + int cnt = 0; + for (GroundTerm t; tuples.isValid(); tuples.moveNext()) { + t = tuples.getTuple().getGroundTerm(0); + if (t instanceof Individual) { + addType(((Individual) t).getIRI(), cls); + ++cnt; + } + } + System.out.println("The number of answers: " + cnt); + } finally { + if (tuples != null) tuples.dispose(); + } + } + } + } + } + + private void addType(String iri, OWLClass cls) { + OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(iri)); + OWLClassNodeSet set; + if (types.containsKey(ind)) { + set = types.get(ind); + } + else { + set = new OWLClassNodeSet(factory.getOWLThing()); + types.put(ind, set); + } + set.addEntity(cls); + } + + @Override + public boolean isPrecomputed(InferenceType inferenceType) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Set getPrecomputableInferenceTypes() { + return java.util.Collections.singleton(InferenceType.CLASS_ASSERTIONS); + } + + @Override + public boolean isConsistent() throws ReasonerInterruptedException, TimeOutException { + return sat; + } + + @Override + public boolean isSatisfiable(OWLClassExpression classExpression) throws ReasonerInterruptedException, TimeOutException, ClassExpressionNotInProfileException, FreshEntitiesException, InconsistentOntologyException { + // TODO Auto-generated method stub + return false; + } + + @Override + public Node getUnsatisfiableClasses() throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isEntailed(OWLAxiom axiom) + throws ReasonerInterruptedException, + UnsupportedEntailmentTypeException, TimeOutException, + AxiomNotInProfileException, FreshEntitiesException, + InconsistentOntologyException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isEntailed(Set axioms) + throws ReasonerInterruptedException, + UnsupportedEntailmentTypeException, TimeOutException, + AxiomNotInProfileException, FreshEntitiesException, + InconsistentOntologyException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isEntailmentCheckingSupported(AxiomType axiomType) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Node getTopClassNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getBottomClassNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getSubClasses(OWLClassExpression ce, boolean direct) + throws ReasonerInterruptedException, TimeOutException, + FreshEntitiesException, InconsistentOntologyException, + ClassExpressionNotInProfileException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getSuperClasses(OWLClassExpression ce, + boolean direct) throws InconsistentOntologyException, + ClassExpressionNotInProfileException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getEquivalentClasses(OWLClassExpression ce) + throws InconsistentOntologyException, + ClassExpressionNotInProfileException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getDisjointClasses(OWLClassExpression ce) + throws ReasonerInterruptedException, TimeOutException, + FreshEntitiesException, InconsistentOntologyException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getTopObjectPropertyNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getBottomObjectPropertyNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getSubObjectProperties( + OWLObjectPropertyExpression pe, boolean direct) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getSuperObjectProperties( + OWLObjectPropertyExpression pe, boolean direct) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getEquivalentObjectProperties( + OWLObjectPropertyExpression pe) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getDisjointObjectProperties( + OWLObjectPropertyExpression pe) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getInverseObjectProperties( + OWLObjectPropertyExpression pe) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getObjectPropertyDomains( + OWLObjectPropertyExpression pe, boolean direct) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getObjectPropertyRanges( + OWLObjectPropertyExpression pe, boolean direct) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getTopDataPropertyNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getBottomDataPropertyNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getSubDataProperties(OWLDataProperty pe, + boolean direct) throws InconsistentOntologyException, + FreshEntitiesException, ReasonerInterruptedException, + TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getSuperDataProperties(OWLDataProperty pe, + boolean direct) throws InconsistentOntologyException, + FreshEntitiesException, ReasonerInterruptedException, + TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getEquivalentDataProperties(OWLDataProperty pe) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getDisjointDataProperties( + OWLDataPropertyExpression pe) throws InconsistentOntologyException, + FreshEntitiesException, ReasonerInterruptedException, + TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getDataPropertyDomains(OWLDataProperty pe, + boolean direct) throws InconsistentOntologyException, + FreshEntitiesException, ReasonerInterruptedException, + TimeOutException { + // TODO Auto-generated method stub + return null; + } + + private Map types = new HashMap(); + private OWLClassNodeSet thing; + + @Override + public NodeSet getTypes(OWLNamedIndividual ind, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { + if (types.containsKey(ind)) return types.get(ind); + return thing; + } + + @Override + public NodeSet getInstances(OWLClassExpression ce, + boolean direct) throws InconsistentOntologyException, + ClassExpressionNotInProfileException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getObjectPropertyValues( + OWLNamedIndividual ind, OWLObjectPropertyExpression pe) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Set getDataPropertyValues(OWLNamedIndividual ind, + OWLDataProperty pe) throws InconsistentOntologyException, + FreshEntitiesException, ReasonerInterruptedException, + TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getSameIndividuals(OWLNamedIndividual ind) + throws InconsistentOntologyException, FreshEntitiesException, + ReasonerInterruptedException, TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public NodeSet getDifferentIndividuals( + OWLNamedIndividual ind) throws InconsistentOntologyException, + FreshEntitiesException, ReasonerInterruptedException, + TimeOutException { + // TODO Auto-generated method stub + return null; + } + + @Override + public long getTimeOut() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public FreshEntityPolicy getFreshEntityPolicy() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IndividualNodeSetPolicy getIndividualNodeSetPolicy() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + +} diff --git a/test/uk/ac/ox/cs/pagoda/ore/PagodaReasonerFactory.java b/test/uk/ac/ox/cs/pagoda/ore/PagodaReasonerFactory.java new file mode 100644 index 0000000..8ecdf1d --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/ore/PagodaReasonerFactory.java @@ -0,0 +1,39 @@ +package uk.ac.ox.cs.pagoda.ore; + +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.reasoner.IllegalConfigurationException; +import org.semanticweb.owlapi.reasoner.OWLReasoner; +import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration; +import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; + +public class PagodaReasonerFactory implements OWLReasonerFactory { + + @Override + public String getReasonerName() { + return "PAGOdA"; + } + + @Override + public OWLReasoner createNonBufferingReasoner(OWLOntology ontology) { + // TODO Auto-generated method stub + return null; + } + + @Override + public OWLReasoner createReasoner(OWLOntology ontology) { + return new PagodaOWLReasoner(ontology); + } + + @Override + public OWLReasoner createNonBufferingReasoner(OWLOntology ontology, OWLReasonerConfiguration config) throws IllegalConfigurationException { + // TODO Auto-generated method stub + return null; + } + + @Override + public OWLReasoner createReasoner(OWLOntology ontology, OWLReasonerConfiguration config) throws IllegalConfigurationException { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/test/uk/ac/ox/cs/pagoda/tester/ORETester.java b/test/uk/ac/ox/cs/pagoda/tester/ORETester.java deleted file mode 100644 index ae58ba9..0000000 --- a/test/uk/ac/ox/cs/pagoda/tester/ORETester.java +++ /dev/null @@ -1,21 +0,0 @@ -package uk.ac.ox.cs.pagoda.tester; - -import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; -import uk.ac.ox.cs.pagoda.util.Properties; - -public class ORETester { - - public static void main(String... args) { -// args = new String[] { "/home/yzhou/krr-nas-share/Yujiao/ontologies/ORE2014/DL/00a1118a-5420-46f0-b4b2-a2585165b28a_ePizza.owl" }; -// args = new String[] { "/home/yzhou/krr-nas-share/Yujiao/ontologies/ORE2014/DL/77de15c6-cc39-4960-a38a-e35e487d52b0_owl%2Fcoma" }; -// args = new String[] { "/home/yzhou/krr-nas-share/Yujiao/ontologies/ORE2014/DL/wine_nodatatype.owl" }; - -// args = new String[] { "/home/yzhou/krr-nas-share/Yujiao/ontologies/ORE2014/EL/b7700fe1-103b-4b32-a21c-f6604a763ba5_t-cell.owl" }; -// args = new String[] { "/home/yzhou/krr-nas-share/Yujiao/ontologies/ORE2014/EL/baa29363-f93c-4285-827e-0e2380c82efc_cations.n3" }; - - Properties properties = new Properties("config/sys.conf"); - QueryReasoner pagoda = QueryReasoner.getInstance(properties); - pagoda.dispose(); - } - -} -- cgit v1.2.3