From: <jen...@us...> - 2008-03-03 07:47:55
|
Revision: 674 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=674&view=rev Author: jenslehmann Date: 2008-03-02 23:45:57 -0800 (Sun, 02 Mar 2008) Log Message: ----------- - improved datatype support - continued refinement operator implementation Modified Paths: -------------- 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/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-03-03 07:45:57 UTC (rev 674) @@ -27,6 +27,7 @@ import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -52,6 +53,7 @@ // (siehe einfacher Traversal in Diplomarbeit) public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts); public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) throws ReasoningMethodUnsupportedException; + public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedDatatypeProperties) throws ReasoningMethodUnsupportedException; public boolean subsumes(Description superConcept, Description subConcept) throws ReasoningMethodUnsupportedException; @@ -69,6 +71,8 @@ public ObjectPropertyHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException; + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> retrieval(Description concept) throws ReasoningMethodUnsupportedException; public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) throws ReasoningMethodUnsupportedException; Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-03-03 07:45:57 UTC (rev 674) @@ -30,6 +30,7 @@ import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -186,10 +187,18 @@ throw new ReasoningMethodUnsupportedException(); } + public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedDatatypeProperties) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + public ObjectPropertyHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + public Set<NamedClass> getConcepts(Individual i) 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-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-03 07:45:57 UTC (rev 674) @@ -29,6 +29,7 @@ import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -328,6 +329,44 @@ return getRoleHierarchy().getMostSpecialRoles(); } + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) + * @param role Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<DatatypeProperty> getMoreGeneralDatatypeProperties(DatatypeProperty role) { + return getDatatypePropertyHierarchy().getMoreGeneralRoles(role); + } + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) + * @param role Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<DatatypeProperty> getMoreSpecialDatatypeProperties(DatatypeProperty role) { + return getDatatypePropertyHierarchy().getMoreSpecialRoles(role); + } + + /** + * @see ObjectPropertyHierarchy#getMostGeneralRoles() + * @return The most general roles. + */ + public TreeSet<DatatypeProperty> getMostGeneralDatatypeProperties() { + return getDatatypePropertyHierarchy().getMostGeneralRoles(); + } + + /** + * @see ObjectPropertyHierarchy#getMostSpecialRoles() + * @return The most special roles. + */ + public TreeSet<DatatypeProperty> getMostSpecialDatatypeProperties() { + return getDatatypePropertyHierarchy().getMostSpecialRoles(); + } + public void prepareSubsumptionHierarchy() { reasoner.prepareSubsumptionHierarchy(getAtomicConcepts()); } @@ -367,6 +406,27 @@ } } + public void prepareDatatypePropertyHierarchy() { + prepareDatatypePropertyHierarchy(getDatatypeProperties()); + } + + public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedRoles) { + try { + reasoner.prepareDatatypePropertyHierarchy(allowedRoles); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + } + + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { + try { + return reasoner.getDatatypePropertyHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + public boolean isSatisfiable() { reasoningStartTimeTmp = System.nanoTime(); boolean result; Added: trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java 2008-03-03 07:45:57 UTC (rev 674) @@ -0,0 +1,110 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.owl; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.dllearner.utilities.RoleComparator; + +/** + * Represents a hierarchy of datatype properties. + * + * @todo. Currently, the role hierarchy pruning algorithm (analogous to the + * subsumption hierarchy) is not implemented. + * + * @author Jens Lehmann + * + */ +public class DatatypePropertyHierarchy { + + RoleComparator rc = new RoleComparator(); + TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyUp; + TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyDown; + TreeSet<DatatypeProperty> mostGeneralRoles = new TreeSet<DatatypeProperty>(rc); + TreeSet<DatatypeProperty> mostSpecialRoles = new TreeSet<DatatypeProperty>(rc); + + public DatatypePropertyHierarchy(Set<DatatypeProperty> atomicRoles, TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyUp , TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyDown) { + this.roleHierarchyUp = roleHierarchyUp; + this.roleHierarchyDown = roleHierarchyDown; + + // find most general and most special roles + for(DatatypeProperty role : atomicRoles) { + if(getMoreGeneralRoles(role).size()==0) + mostGeneralRoles.add(role); + if(getMoreSpecialRoles(role).size()==0) + mostSpecialRoles.add(role); + } + } + + @SuppressWarnings("unchecked") + public SortedSet<DatatypeProperty> getMoreGeneralRoles(DatatypeProperty role) { + // we clone all concepts before returning them such that they cannot be + // modified externally + return (TreeSet<DatatypeProperty>) roleHierarchyUp.get(role).clone(); + } + + @SuppressWarnings("unchecked") + public SortedSet<DatatypeProperty> getMoreSpecialRoles(DatatypeProperty role) { + return (TreeSet<DatatypeProperty>) roleHierarchyDown.get(role).clone(); + } + + + + @Override + public String toString() { + String str = ""; + for(DatatypeProperty role : mostGeneralRoles) { + str += toString(roleHierarchyDown, role, 0); + } + return str; + } + + private String toString(TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> hierarchy, DatatypeProperty role, int depth) { + String str = ""; + for(int i=0; i<depth; i++) + str += " "; + str += role.toString() + "\n"; + Set<DatatypeProperty> tmp = hierarchy.get(role); + if(tmp!=null) { + for(DatatypeProperty c : tmp) + str += toString(hierarchy, c, depth+1); + } + return str; + } + + /** + * @return The most general roles. + */ + public TreeSet<DatatypeProperty> getMostGeneralRoles() { + return mostGeneralRoles; + } + + /** + * @return The most special roles. + */ + public TreeSet<DatatypeProperty> getMostSpecialRoles() { + return mostSpecialRoles; + } + + +} Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-03 07:45:57 UTC (rev 674) @@ -38,6 +38,7 @@ import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; @@ -359,6 +360,16 @@ } @Override + public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedRoles) { + rs.prepareDatatypePropertyHierarchy(allowedRoles); + } + + @Override + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { + return rs.getDatatypePropertyHierarchy(); + } + + @Override public boolean subsumes(Description superConcept, Description subConcept) { // Negation neg = new Negation(subConcept); // Intersection c = new Intersection(neg,superConcept); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-03 07:45:57 UTC (rev 674) @@ -46,6 +46,7 @@ import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.EquivalentClassesAxiom; import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; @@ -129,6 +130,7 @@ private RoleComparator roleComparator = new RoleComparator(); private SubsumptionHierarchy subsumptionHierarchy; private ObjectPropertyHierarchy roleHierarchy; + private DatatypePropertyHierarchy datatypePropertyHierarchy; private Set<Description> allowedConceptsInSubsumptionHierarchy; // primitives @@ -430,6 +432,30 @@ } @Override + public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedRoles) { + // code copied from DIG reasoner + + TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> datatypePropertyHierarchyUp = new TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>>( + roleComparator); + TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> datatypePropertyHierarchyDown = new TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>>( + roleComparator); + + // refinement of atomic concepts + for (DatatypeProperty role : datatypeProperties) { + datatypePropertyHierarchyDown.put(role, getMoreSpecialDatatypeProperties(role)); + datatypePropertyHierarchyUp.put(role, getMoreGeneralDatatypeProperties(role)); + } + + datatypePropertyHierarchy = new DatatypePropertyHierarchy(allowedRoles, datatypePropertyHierarchyUp, + datatypePropertyHierarchyDown); + } + + @Override + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { + return datatypePropertyHierarchy; + } + + @Override public boolean subsumes(Description superConcept, Description subConcept) { try { return reasoner.isSubClassOf(OWLAPIDescriptionConvertVisitor.getOWLDescription(subConcept), OWLAPIDescriptionConvertVisitor.getOWLDescription(superConcept)); @@ -469,7 +495,7 @@ e.printStackTrace(); throw new Error("OWL API classification error."); } - return getFirstProperties(properties); + return getFirstObjectProperties(properties); } private TreeSet<ObjectProperty> getMoreSpecialRoles(ObjectProperty role) { @@ -480,9 +506,31 @@ e.printStackTrace(); throw new Error("OWL API classification error."); } - return getFirstProperties(properties); + return getFirstObjectProperties(properties); } + private TreeSet<DatatypeProperty> getMoreGeneralDatatypeProperties(DatatypeProperty role) { + Set<Set<OWLDataProperty>> properties; + try { + properties = reasoner.getSuperProperties(getOWLAPIDescription(role)); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("OWL API classification error."); + } + return getFirstDatatypeProperties(properties); + } + + private TreeSet<DatatypeProperty> getMoreSpecialDatatypeProperties(DatatypeProperty role) { + Set<Set<OWLDataProperty>> properties; + try { + properties = reasoner.getSubProperties(getOWLAPIDescription(role)); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("OWL API classification error."); + } + return getFirstDatatypeProperties(properties); + } + @Override public boolean instanceCheck(Description concept, Individual individual) { OWLDescription d = getOWLAPIDescription(concept); @@ -681,7 +729,7 @@ return concepts; } - private TreeSet<ObjectProperty> getFirstProperties(Set<Set<OWLObjectProperty>> setOfSets) { + private TreeSet<ObjectProperty> getFirstObjectProperties(Set<Set<OWLObjectProperty>> setOfSets) { TreeSet<ObjectProperty> roles = new TreeSet<ObjectProperty>(roleComparator); for(Set<OWLObjectProperty> innerSet : setOfSets) { // take one element from the set and ignore the rest @@ -692,6 +740,15 @@ return roles; } + private TreeSet<DatatypeProperty> getFirstDatatypeProperties(Set<Set<OWLDataProperty>> setOfSets) { + TreeSet<DatatypeProperty> roles = new TreeSet<DatatypeProperty>(roleComparator); + for(Set<OWLDataProperty> innerSet : setOfSets) { + OWLDataProperty property = innerSet.iterator().next(); + roles.add(new DatatypeProperty(property.getURI().toString())); + } + return roles; + } + @SuppressWarnings({"unused"}) private Set<Description> owlClassesToAtomicConcepts(Set<OWLClass> owlClasses) { Set<Description> concepts = new HashSet<Description>(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-03 07:45:57 UTC (rev 674) @@ -103,6 +103,9 @@ private Map<NamedClass, Set<DatatypeProperty>> appBD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); private Map<NamedClass, Set<DatatypeProperty>> appDD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + // most general applicable properties + private Map<NamedClass,Set<ObjectProperty>> mgr = new TreeMap<NamedClass,Set<ObjectProperty>>(); + // comparator für Konzepte private ConceptComparator conceptComparator = new ConceptComparator(); @@ -328,6 +331,23 @@ mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; } + private void computeMgr(NamedClass domain) { + // compute the applicable properties if this has not been done yet + if(appOP.get(domain) == null) + computeApp(domain); + Set<ObjectProperty> mostGeneral = rs.getMostGeneralRoles(); + computeMgrRecursive(domain, mostGeneral, mgr.get(domain)); + } + + private void computeMgrRecursive(NamedClass domain, Set<ObjectProperty> currProperties, Set<ObjectProperty> mgrTmp) { + for(ObjectProperty prop : currProperties) { + if(appOP.get(domain).contains(prop)) + mgrTmp.add(prop); + else + computeMgrRecursive(domain, rs.getMoreSpecialRoles(prop), mgrTmp); + } + } + // computes the set of applicable properties for a given class private void computeApp(NamedClass domain) { // TODO: also implement this for boolean/double datatype properties This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |