From: <jen...@us...> - 2008-02-24 19:29:09
|
Revision: 637 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=637&view=rev Author: jenslehmann Date: 2008-02-24 11:29:04 -0800 (Sun, 24 Feb 2008) Log Message: ----------- - prepared reasoner datatype support - implemented getRoleMembers in OWL API reasoner - now fully DIG 1.1 compliant - discovered another bug in OWL API export (adds an empty prefix) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-24 19:29:04 UTC (rev 637) @@ -550,6 +550,15 @@ } m.put(3,m3); } + + // boolean datatypes, e.g. testPositive = true + if(useBooleanDatatypes) { +// Set<Description> m3 = new TreeSet<Description>(conceptComparator); + // TODO: code for getting boolean datatypes +// m.put(3,m3); + // TODO: do not use put here because we overwrite the + // EXISTS quantor stuff + } } if(maxLength>2) { Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-24 19:29:04 UTC (rev 637) @@ -24,6 +24,7 @@ import java.util.Set; import java.util.SortedSet; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -88,5 +89,11 @@ public Set<ObjectProperty> getAtomicRoles(); + // currently, we do not require that datatype properties can be returned; + // the main reason is that DIG does not distinguish between datatype and + // object properties (of course one could implement it but it is not easy) + public Set<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> getIndividuals(); + } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-24 19:29:04 UTC (rev 637) @@ -25,6 +25,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -120,4 +121,8 @@ throw new ReasoningMethodUnsupportedException(); } + public Set<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-24 19:29:04 UTC (rev 637) @@ -486,6 +486,7 @@ // Reasoning-Resultate // zur�ckgegeben werden k�nnten private void handleExceptions(ReasoningMethodUnsupportedException e) { + e.printStackTrace(); throw new Error("Reasoning method not supported."); } Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-24 19:29:04 UTC (rev 637) @@ -196,8 +196,10 @@ } // disjoint classes axioms - DisjointClassesAxiom disjointAtomTypes = getDisjointClassesAxiom(atomTypes); - kb.addAxiom(disjointAtomTypes); + // OWL API is also buggy here, it adds a strange unused prefix + // and cannot parser its own generated file +// DisjointClassesAxiom disjointAtomTypes = getDisjointClassesAxiom(atomTypes); +// kb.addAxiom(disjointAtomTypes); // all different axiom (UNA) // exporting differentIndividuals axioms is broken in OWL API @@ -443,6 +445,7 @@ return new DoubleDatatypePropertyAssertion(dp, ind, value); } + @SuppressWarnings({"unused"}) private static DisjointClassesAxiom getDisjointClassesAxiom(Set<String> classes) { Set<Description> descriptions = new HashSet<Description>(); for(String namedClass : classes) Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-24 19:29:04 UTC (rev 637) @@ -35,6 +35,7 @@ import org.dllearner.core.ReasoningService; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; @@ -59,8 +60,8 @@ * model of the knowledge base (TODO: more explanation), which is neither correct nor * complete, but sufficient in many cases. A big advantage of the algorithm is that it * does not need even need to perform any set modifications (union, intersection, difference), - * so it avoids any object creation, which makes it very fast compared to standard - * reasoners (TODO: maybe add some benchmarks once it is implemented). + * so it avoids any Java object creation, which makes it extremely fast compared to standard + * reasoners. * * Note: This algorithm works only on concepts in negation normal form! * @@ -74,10 +75,11 @@ private Set<NamedClass> atomicConcepts; private Set<ObjectProperty> atomicRoles; + private Set<DatatypeProperty> datatypeProperties; private SortedSet<Individual> individuals; private ReasoningService rs; - private ReasonerComponent rc; + private OWLAPIReasoner rc; private Set<KnowledgeSource> sources; // we use sorted sets (map indices) here, because they have only log(n) @@ -94,7 +96,6 @@ this.sources = sources; } - /* (non-Javadoc) * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.config.ConfigEntry) */ @@ -109,17 +110,10 @@ @Override public void init() throws ComponentInitException { rc = new OWLAPIReasoner(sources); - // DIG will only be used to get the role pairs; - // outside the constructor, OWL API will be used because - // it is fast than DIG - DIGReasoner rcDIG = new DIGReasoner(sources); - try { - rc.init(); - rcDIG.init(); - } catch (ComponentInitException e1) { - e1.printStackTrace(); - } + rc.init(); + atomicConcepts = rc.getAtomicConcepts(); + datatypeProperties = rc.getDatatypeProperties(); atomicRoles = rc.getAtomicRoles(); individuals = rc.getIndividuals(); rs = new ReasoningService(rc); @@ -135,7 +129,7 @@ } for (ObjectProperty atomicRole : rs.getAtomicRoles()) { - opPos.put(atomicRole, rcDIG.getRoleMembers(atomicRole)); + opPos.put(atomicRole, rc.getRoleMembers(atomicRole)); } long dematDuration = System.currentTimeMillis() - dematStartTime; @@ -233,6 +227,11 @@ return atomicRoles; } + @Override + public Set<DatatypeProperty> getDatatypeProperties() { + return datatypeProperties; + } + /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getIndividuals() */ Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-24 19:29:04 UTC (rev 637) @@ -27,6 +27,7 @@ import java.util.Comparator; import java.util.HashSet; import java.util.LinkedList; +import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeMap; @@ -42,6 +43,7 @@ import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.owl.AssertionalAxiom; import org.dllearner.core.owl.ClassAssertionAxiom; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.EquivalentClassesAxiom; import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; @@ -76,6 +78,7 @@ import org.semanticweb.owl.model.OWLAxiom; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDataProperty; import org.semanticweb.owl.model.OWLDescription; import org.semanticweb.owl.model.OWLIndividual; import org.semanticweb.owl.model.OWLNamedObject; @@ -120,6 +123,8 @@ // primitives Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); Set<ObjectProperty> atomicRoles = new TreeSet<ObjectProperty>(roleComparator); + Set<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); +// Set<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); SortedSet<Individual> individuals = new TreeSet<Individual>(); public OWLAPIReasoner(Set<KnowledgeSource> sources) { @@ -164,7 +169,8 @@ } }; Set<OWLClass> classes = new TreeSet<OWLClass>(namedObjectComparator); - Set<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(namedObjectComparator); + Set<OWLObjectProperty> owlObjectProperties = new TreeSet<OWLObjectProperty>(namedObjectComparator); + Set<OWLDataProperty> owlDatatypeProperties = new TreeSet<OWLDataProperty>(namedObjectComparator); Set<OWLIndividual> owlIndividuals = new TreeSet<OWLIndividual>(namedObjectComparator); Set<OWLOntology> allImports = new HashSet<OWLOntology>(); @@ -178,7 +184,8 @@ OWLOntology ontology = manager.loadOntologyFromPhysicalURI(url.toURI()); allImports.addAll(manager.getImportsClosure(ontology)); classes.addAll(ontology.getReferencedClasses()); - properties.addAll(ontology.getReferencedObjectProperties()); + owlObjectProperties.addAll(ontology.getReferencedObjectProperties()); + owlDatatypeProperties.addAll(ontology.getReferencedDataProperties()); owlIndividuals.addAll(ontology.getReferencedIndividuals()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); @@ -202,7 +209,8 @@ allImports.add(ontology); atomicConcepts.addAll(kb.findAllAtomicConcepts()); atomicRoles.addAll(kb.findAllAtomicRoles()); - individuals.addAll(kb.findAllIndividuals()); + individuals.addAll(kb.findAllIndividuals()); + // TODO: add method to find datatypes } } @@ -264,11 +272,18 @@ // read in primitives for(OWLClass owlClass : classes) atomicConcepts.add(new NamedClass(owlClass.getURI().toString())); - for(OWLObjectProperty owlProperty : properties) + for(OWLObjectProperty owlProperty : owlObjectProperties) atomicRoles.add(new ObjectProperty(owlProperty.getURI().toString())); + for(OWLDataProperty owlProperty : owlDatatypeProperties) { + // empty ranges are returned for ames test positive +// Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); +// System.out.println(owlProperty); +// System.out.println(ranges); + datatypeProperties.add(new DatatypeProperty(owlProperty.getURI().toString())); + System.exit(0); + } for(OWLIndividual owlIndividual : owlIndividuals) individuals.add(new Individual(owlIndividual.getURI().toString())); - } /* (non-Javadoc) @@ -285,6 +300,11 @@ return atomicRoles; } + @Override + public Set<DatatypeProperty> getDatatypeProperties() { + return datatypeProperties; + } + /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getIndividuals() */ @@ -482,6 +502,31 @@ } } + @Override + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { + OWLObjectProperty prop = getOWLAPIDescription(atomicRole); + Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); + for(Individual i : individuals) { + OWLIndividual ind = factory.getOWLIndividual(URI.create(i.getName())); + + // get all related individuals via OWL API + Set<OWLIndividual> inds = null; + try { + inds = reasoner.getRelatedIndividuals(ind, prop); + } catch (OWLReasonerException e) { + e.printStackTrace(); + } + + // convert data back to DL-Learner structures + SortedSet<Individual> is = new TreeSet<Individual>(); + for(OWLIndividual oi : inds) + is.add(new Individual(oi.getURI().toString())); + map.put(i, is); + } + return map; + } + + // OWL API often returns a set of sets of classes, where each inner // set consists of equivalent classes; this method picks one class // from each inner set to flatten the set of sets @@ -561,8 +606,7 @@ } } - @Deprecated - public static OWLObjectProperty getOWLAPIDescription(ObjectProperty role) { + private static OWLObjectProperty getOWLAPIDescription(ObjectProperty role) { return staticFactory.getOWLObjectProperty(URI.create(role.getName())); } Modified: trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-24 19:29:04 UTC (rev 637) @@ -24,15 +24,31 @@ OWLOntology ontology = manager.createOntology(ontologyURI); OWLDataFactory factory = manager.getOWLDataFactory(); + // create a set of two individuals OWLIndividual a = factory.getOWLIndividual(URI.create(ontologyURI + "#a")); OWLIndividual b = factory.getOWLIndividual(URI.create(ontologyURI + "#b")); Set<OWLIndividual> inds = new HashSet<OWLIndividual>(); inds.add(a); inds.add(b); + // create a set of two classes + OWLClass c = factory.getOWLClass(URI.create(ontologyURI + "#c")); + OWLClass d = factory.getOWLClass(URI.create(ontologyURI + "#d")); + Set<OWLClass> classes = new HashSet<OWLClass>(); + classes.add(c); + classes.add(d); + + // state that a and b are different OWLAxiom axiom = factory.getOWLDifferentIndividualsAxiom(inds); AddAxiom addAxiom = new AddAxiom(ontology, axiom); manager.applyChange(addAxiom); + + // state that c and d are disjoint + OWLAxiom axiom2 = factory.getOWLDisjointClassesAxiom(classes); + AddAxiom addAxiom2 = new AddAxiom(ontology, axiom2); + manager.applyChange(addAxiom2); + + // save ontology manager.saveOntology(ontology); } catch (OWLException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |