From: <jen...@us...> - 2008-11-11 16:17:30
|
Revision: 1507 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1507&view=rev Author: jenslehmann Date: 2008-11-11 16:17:24 +0000 (Tue, 11 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN version should mostly be working again - subsumption hierarchy queries/caching has moved to ReasonerComponent (instead of the particular reasoner implementations) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -359,7 +359,7 @@ // during the run of the algorithm // reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) - reasoner.getClassHierarchy().improveSubsumptionHierarchy(); + reasoner.getClassHierarchy().thinOutSubsumptionHierarchy(); // reasoner.prepareRoleHierarchy(usedRoles); // prepare datatype hierarchy only if necessary // if(reasoner.hasDatatypeSupport()) Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -374,7 +374,7 @@ // during the run of the algorithm // reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) - reasoner.getClassHierarchy().improveSubsumptionHierarchy(); + reasoner.getClassHierarchy().thinOutSubsumptionHierarchy(); // reasoner.prepareRoleHierarchy(usedRoles); } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -38,11 +38,14 @@ import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.Thing; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.datastructures.SortedSetTuple; +import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.OWLVocabulary; /** @@ -366,12 +369,13 @@ handleExceptions(e); return null; } - } - - protected Set<NamedClass> getInconsistentClassesImpl() throws ReasoningMethodUnsupportedException { + } + + protected Set<NamedClass> getInconsistentClassesImpl() + throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); - } - + } + @Override public final boolean isSatisfiable() { reasoningStartTimeTmp = System.nanoTime(); @@ -743,18 +747,24 @@ throw new ReasoningMethodUnsupportedException(); } - - @Override public final SortedSet<Description> getSuperClasses(Description concept) { return getClassHierarchy().getMoreGeneralConcepts(concept); } + protected SortedSet<Description> getSuperClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + @Override public final SortedSet<Description> getSubClasses(Description concept) { return getClassHierarchy().getMoreSpecialConcepts(concept); } + protected SortedSet<Description> getSubClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + @Override public final SortedSet<ObjectProperty> getSuperProperties(ObjectProperty role) { return getObjectPropertyHierarchy().getMoreGeneralRoles(role); @@ -800,26 +810,54 @@ * called explicitly, it is called the first time, it is needed). * * @return The class hierarchy. - * @throws ReasoningMethodUnsupportedException - * Thrown if subsumption hierarchy creation is not supported by - * the reasoner. + * @throws ReasoningMethodUnsupportedException */ - public ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException( - "Subsumption hierarchy creation not supported by this reasoner."); + public final ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { + ConceptComparator conceptComparator = new ConceptComparator(); + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + + // refinements of top + SortedSet<Description> tmp = getSubClassesImpl(Thing.instance); + subsumptionHierarchyDown.put(new Thing(), tmp); + + // refinements of bottom + tmp = getSuperClassesImpl(Nothing.instance); + subsumptionHierarchyUp.put(new Nothing(), tmp); + + // refinements of atomic concepts + Set<NamedClass> atomicConcepts = getNamedClasses(); + for (NamedClass atom : atomicConcepts) { + tmp = getSubClassesImpl(atom); + // quality control: we explicitly check that no reasoner implementation returns null here + if(tmp == null) { + logger.error("Class hierarchy: getSubClasses returned null instead of empty set."); + } + subsumptionHierarchyDown.put(atom, tmp); + + tmp = getSuperClassesImpl(atom); + // quality control: we explicitly check that no reasoner implementation returns null here + if(tmp == null) { + logger.error("Class hierarchy: getSuperClasses returned null instead of empty set."); + } + subsumptionHierarchyUp.put(atom, tmp); + } + + return new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); } @Override public final ClassHierarchy getClassHierarchy() { - try { - if (subsumptionHierarchy == null) { + // class hierarchy is created on first invocation + if (subsumptionHierarchy == null) { + try { subsumptionHierarchy = prepareSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); } - // subsumptionHierarchy = getSubsumptionHierarchyImpl(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); } - return subsumptionHierarchy; } @@ -840,13 +878,15 @@ @Override public final ObjectPropertyHierarchy getObjectPropertyHierarchy() { - if (roleHierarchy == null) { - try { - prepareRoleHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); + + try { + if (roleHierarchy == null) { + roleHierarchy = prepareRoleHierarchy(); } + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); } + return roleHierarchy; } @@ -867,13 +907,15 @@ @Override public final DatatypePropertyHierarchy getDatatypePropertyHierarchy() { - if (datatypePropertyHierarchy == null) { - try { + + try { + if (datatypePropertyHierarchy == null) { prepareDatatypePropertyHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); } + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); } + return datatypePropertyHierarchy; } Modified: trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * @@ -23,98 +23,136 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.Map.Entry; +import org.apache.log4j.Logger; import org.dllearner.utilities.owl.ConceptComparator; /** * Represents a subsumption hierarchy (ignoring equivalent concepts). - * + * * @author Jens Lehmann - * + * */ public class ClassHierarchy { + public static Logger logger = Logger.getLogger(ClassHierarchy.class); + ConceptComparator conceptComparator = new ConceptComparator(); - TreeMap<Description,TreeSet<Description>> subsumptionHierarchyUp; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - TreeMap<Description,TreeSet<Description>> subsumptionHierarchyDown; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - Set<Description> allowedConceptsInSubsumptionHierarchy; + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUp; + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown; - public ClassHierarchy(Set<NamedClass> atomicConcepts, TreeMap<Description,TreeSet<Description>> subsumptionHierarchyUp , TreeMap<Description,TreeSet<Description>> subsumptionHierarchyDown) { + /** + * The arguments specify the superclasses and subclasses of each class. This + * is used to build the subsumption hierarchy. + * @param subsumptionHierarchyUp Contains super classes for each class. + * @param subsumptionHierarchyDown Contains sub classes for each class. + */ + public ClassHierarchy( + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUp, + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown) { + this.subsumptionHierarchyUp = subsumptionHierarchyUp; - this.subsumptionHierarchyDown = subsumptionHierarchyDown; - allowedConceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(atomicConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Thing()); - allowedConceptsInSubsumptionHierarchy.add(new Nothing()); + } + + public SortedSet<Description> getMoreGeneralConcepts(Description concept) { + SortedSet<Description> result = subsumptionHierarchyUp.get(concept); + if(result == null) { + logger.error("Query for super class of " + concept + " in subsumption hierarchy, but the class is not contained in the (upward) hierarchy"); + } - @SuppressWarnings("unchecked") - public SortedSet<Description> getMoreGeneralConcepts(Description concept) { - // we clone all concepts before returning them such that they cannot be + // we copy all concepts before returning them such that they cannot be // modified externally - return (TreeSet<Description>) subsumptionHierarchyUp.get(concept).clone(); + return new TreeSet<Description>(result); } - - @SuppressWarnings("unchecked") + public SortedSet<Description> getMoreSpecialConcepts(Description concept) { - if(subsumptionHierarchyDown==null) { return new TreeSet<Description>();} - else if( subsumptionHierarchyDown.get(concept)==null){ return new TreeSet<Description>();} - else {return (TreeSet<Description>) subsumptionHierarchyDown.get(concept).clone();} - } - - public void improveSubsumptionHierarchy() { - TreeMap<Description,TreeSet<Description>> hierarchyDownNew = new TreeMap<Description,TreeSet<Description>>(conceptComparator); - // hierarchyDownNew.put(new Top(), new TreeSet<Concept>(conceptComparator)); - TreeMap<Description,TreeSet<Description>> hierarchyUpNew = new TreeMap<Description,TreeSet<Description>>(conceptComparator); + SortedSet<Description> result = subsumptionHierarchyDown.get(concept); + if(result == null) { + logger.error("Query for sub class of " + concept + " in subsumption hierarchy, but the class is not contained in the (downward) hierarchy"); + } - // Einträge für alle Konzepte machen (init) - for(Description c : allowedConceptsInSubsumptionHierarchy) { - hierarchyDownNew.put(c, new TreeSet<Description>(conceptComparator)); - hierarchyUpNew.put(c, new TreeSet<Description>(conceptComparator)); + return new TreeSet<Description>(result); + + // commented out, because these hacks just worked around a problem +// if (subsumptionHierarchyDown == null) { +// return new TreeSet<Description>(); +// } else if (subsumptionHierarchyDown.get(concept) == null) { +// return new TreeSet<Description>(); +// } else { +// return (TreeSet<Description>) subsumptionHierarchyDown.get(concept).clone(); +// } + } + + /** + * This method modifies the subsumption hierarchy such that for each class, + * there is only a single path to reach it via upward and downward + * refinement respectively. + */ + public void thinOutSubsumptionHierarchy() { + TreeMap<Description, SortedSet<Description>> hierarchyDownNew = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + TreeMap<Description, SortedSet<Description>> hierarchyUpNew = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + + Set<Description> conceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); + conceptsInSubsumptionHierarchy.addAll(subsumptionHierarchyUp.keySet()); + conceptsInSubsumptionHierarchy.addAll(subsumptionHierarchyDown.keySet()); + + // add empty sets for each concept + for (Description c : conceptsInSubsumptionHierarchy) { + hierarchyDownNew.put(c, new TreeSet<Description>(conceptComparator)); + hierarchyUpNew.put(c, new TreeSet<Description>(conceptComparator)); } - - for(Description c : allowedConceptsInSubsumptionHierarchy) { - // schauen, ob es mehrere allgemeinere Nachbarn gibt + + for (Description c : conceptsInSubsumptionHierarchy) { + // look whether there are more general concepts + // (if yes, pick the first one) SortedSet<Description> moreGeneral = subsumptionHierarchyUp.get(c); - if(moreGeneral != null && moreGeneral.size() != 0) { + if (moreGeneral != null && moreGeneral.size() != 0) { Description chosenParent = moreGeneral.first(); hierarchyDownNew.get(chosenParent).add(c); } - } - - // for(Concept c : allowedConceptsInSubsumptionHierarchy) { - for(Description c : allowedConceptsInSubsumptionHierarchy) { + } + + for (Description c : conceptsInSubsumptionHierarchy) { SortedSet<Description> moreSpecial = subsumptionHierarchyDown.get(c); - if(moreSpecial != null && moreSpecial.size() != 0) { + if (moreSpecial != null && moreSpecial.size() != 0) { Description chosenParent = moreSpecial.first(); hierarchyUpNew.get(chosenParent).add(c); } - } + } subsumptionHierarchyDown = hierarchyDownNew; subsumptionHierarchyUp = hierarchyUpNew; } - + /** - * Implements a subsumption check using the hierarchy (no further - * reasoning checks are used). - * @param subClass The (supposedly) more special class. - * @param superClass The (supposedly) more general class. - * @return True if <code>subClass</code> is a subclass of <code>superclass</code>. + * Implements a subsumption check using the hierarchy (no further reasoning + * checks are used). + * + * @param subClass + * The (supposedly) more special class. + * @param superClass + * The (supposedly) more general class. + * @return True if <code>subClass</code> is a subclass of + * <code>superclass</code>. */ public boolean isSubclassOf(NamedClass subClass, NamedClass superClass) { - if(subClass.equals(superClass)) { + if (subClass.equals(superClass)) { return true; } else { - for(Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) { + for (Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) { // search the upper classes of the subclass - if(moreGeneralClass instanceof NamedClass) { - if(isSubclassOf((NamedClass)moreGeneralClass, superClass)) { + if (moreGeneralClass instanceof NamedClass) { + if (isSubclassOf((NamedClass) moreGeneralClass, superClass)) { return true; } - // we reached top, so we can return false (if top is a direct upper - // class, then no other upper classes can exist) + // we reached top, so we can return false (if top is a + // direct upper + // class, then no other upper classes can exist) } else { return false; } @@ -124,14 +162,14 @@ return false; } } - - @Override + + @Override public String toString() { return toString(false); } - + public String toString(boolean showUpwardHierarchy) { - if(showUpwardHierarchy) { + if (showUpwardHierarchy) { String str = "downward subsumption:\n"; str += toString(subsumptionHierarchyDown, new Thing(), 0); str += "upward subsumption:\n"; @@ -141,17 +179,85 @@ return toString(subsumptionHierarchyDown, new Thing(), 0); } } - - private String toString(TreeMap<Description,TreeSet<Description>> hierarchy, Description concept, int depth) { + + private String toString(TreeMap<Description, SortedSet<Description>> hierarchy, + Description concept, int depth) { String str = ""; - for(int i=0; i<depth; i++) + for (int i = 0; i < depth; i++) str += " "; str += concept.toString() + "\n"; Set<Description> tmp = hierarchy.get(concept); - if(tmp!=null) { - for(Description c : tmp) - str += toString(hierarchy, c, depth+1); + if (tmp != null) { + for (Description c : tmp) + str += toString(hierarchy, c, depth + 1); } return str; - } + } + + /** + * The method computes a new class hierarchy, which is a copy of this + * one, but only the specified classes are allowed to occur. For instance, + * if we have subclass relationships between 1sYearStudent, Student, and + * Person, but Student is not allowed, then there a is a subclass relationship + * between 1stYearStudent and Person. + * @param allowedClasses The classes, which are allowed to occur in the new + * class hierarchy. + * @return A copy of this hierarchy, which is restricted to a certain set + * of classes. + */ + public ClassHierarchy cloneAndRestrict(Set<NamedClass> allowedClasses) { + // create new maps + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUpNew + = new TreeMap<Description, SortedSet<Description>>(); + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDownNew + = new TreeMap<Description, SortedSet<Description>>(); + + for(Entry<Description, SortedSet<Description>> entry : subsumptionHierarchyUp.entrySet()) { + Description key = entry.getKey(); + // we only store mappings for allowed classes + if(allowedClasses.contains(key)) { + // copy the set of all super classes (we consume them until + // they are empty) + TreeSet<Description> superClasses = new TreeSet<Description>(entry.getValue()); + // storage for new super classes + TreeSet<Description> newSuperClasses = new TreeSet<Description>(entry.getValue()); + + while(!superClasses.isEmpty()) { + // pick and remove the first element + Description d = superClasses.pollFirst(); + // case 1: it is allowed, so we add it + if(allowedClasses.contains(d)) { + newSuperClasses.add(d); + // case 2: it is not allowed, so we try its super classes + } else { + superClasses.addAll(subsumptionHierarchyUp.get(d)); + } + } + + subsumptionHierarchyUpNew.put(key, newSuperClasses); + } + } + + // downward case is analogous + for(Entry<Description, SortedSet<Description>> entry : subsumptionHierarchyDown.entrySet()) { + Description key = entry.getKey(); + if(allowedClasses.contains(key)) { + TreeSet<Description> subClasses = new TreeSet<Description>(entry.getValue()); + TreeSet<Description> newSubClasses = new TreeSet<Description>(entry.getValue()); + + while(!subClasses.isEmpty()) { + Description d = subClasses.pollFirst(); + if(allowedClasses.contains(d)) { + newSubClasses.add(d); + } else { + subClasses.addAll(subsumptionHierarchyDown.get(d)); + } + } + + subsumptionHierarchyDownNew.put(key, newSubClasses); + } + } + + return new ClassHierarchy(subsumptionHierarchyUpNew, subsumptionHierarchyDownNew); + } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -47,13 +47,13 @@ import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.options.StringConfigOption; +import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; -import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; @@ -223,45 +223,45 @@ * Construct a subsumption hierarchy using DIG queries. After calling this * method one can ask for children or parents in the subsumption hierarchy. */ - public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { - allowedConceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(allowedConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Thing()); - allowedConceptsInSubsumptionHierarchy.add(new Nothing()); +// public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { +// allowedConceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); +// allowedConceptsInSubsumptionHierarchy.addAll(allowedConcepts); +// allowedConceptsInSubsumptionHierarchy.add(new Thing()); +// allowedConceptsInSubsumptionHierarchy.add(new Nothing()); +// +// TreeMap<Description, TreeSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, TreeSet<Description>>( +// conceptComparator); +// TreeMap<Description, TreeSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, TreeSet<Description>>( +// conceptComparator); +// +// // Subsumptionhierarchy berechnen +// // TODO: kann man effizienter auch in einer Abfrage machen +// +// // Refinements von Top +// TreeSet<Description> tmp = getMoreSpecialConceptsDIG(new Thing()); +// tmp.retainAll(allowedConceptsInSubsumptionHierarchy); +// subsumptionHierarchyDown.put(new Thing(), tmp); +// +// // Refinements von Bottom +// tmp = getMoreGeneralConceptsDIG(new Nothing()); +// tmp.retainAll(allowedConceptsInSubsumptionHierarchy); +// subsumptionHierarchyUp.put(new Nothing(), tmp); +// +// // Refinement atomarer Konzepte +// for (NamedClass atom : atomicConcepts) { +// tmp = getMoreSpecialConceptsDIG(atom); +// tmp.retainAll(allowedConceptsInSubsumptionHierarchy); +// subsumptionHierarchyDown.put(atom, tmp); +// +// tmp = getMoreGeneralConceptsDIG(atom); +// tmp.retainAll(allowedConceptsInSubsumptionHierarchy); +// subsumptionHierarchyUp.put(atom, tmp); +// } +// +// subsumptionHierarchy = new ClassHierarchy( +// subsumptionHierarchyUp, subsumptionHierarchyDown); +// } - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - - // Subsumptionhierarchy berechnen - // TODO: kann man effizienter auch in einer Abfrage machen - - // Refinements von Top - TreeSet<Description> tmp = getMoreSpecialConceptsDIG(new Thing()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(new Thing(), tmp); - - // Refinements von Bottom - tmp = getMoreGeneralConceptsDIG(new Nothing()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(new Nothing(), tmp); - - // Refinement atomarer Konzepte - for (NamedClass atom : atomicConcepts) { - tmp = getMoreSpecialConceptsDIG(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(atom, tmp); - - tmp = getMoreGeneralConceptsDIG(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(atom, tmp); - } - - subsumptionHierarchy = new ClassHierarchy(allowedConcepts, - subsumptionHierarchyUp, subsumptionHierarchyDown); - } - /** * Constructs a role hierarchy using DIG queries. After calling this method, * one can query parents or children of roles. @@ -481,7 +481,8 @@ // return roleHierarchy; // } - private TreeSet<Description> getMoreGeneralConceptsDIG(Description concept) { + @Override + protected TreeSet<Description> getSuperClassesImpl(Description concept) { String moreGeneralDIG = asksPrefix; moreGeneralDIG += "<parents id=\"query_parents\">"; moreGeneralDIG += DIGConverter.getDIGString(concept); @@ -520,7 +521,7 @@ // Konzept ist // (sonst wäre es weiter oben gefunden wurden) NamedClass ignoredAtomicConcept = new NamedClass(atoms[0].getName()); - resultsSet.addAll(getMoreGeneralConceptsDIG(ignoredAtomicConcept)); + resultsSet.addAll(getSuperClassesImpl(ignoredAtomicConcept)); } } @@ -528,7 +529,8 @@ return resultsSet; } - private TreeSet<Description> getMoreSpecialConceptsDIG(Description concept) { + @Override + protected TreeSet<Description> getSubClassesImpl(Description concept) { String moreSpecialDIG = asksPrefix; moreSpecialDIG += "<children id=\"query_children\">"; moreSpecialDIG += DIGConverter.getDIGString(concept); @@ -553,7 +555,7 @@ if (resultsSet.size() == 0 && atoms.length > 0) { NamedClass ignoredAtomicConcept = new NamedClass(atoms[0].getName()); - resultsSet.addAll(getMoreSpecialConceptsDIG(ignoredAtomicConcept)); + resultsSet.addAll(getSubClassesImpl(ignoredAtomicConcept)); } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -43,7 +43,6 @@ import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.BooleanValueRestriction; -import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; @@ -555,11 +554,6 @@ return ReasonerType.FAST_INSTANCE_CHECKER; } - @Override - public ClassHierarchy prepareSubsumptionHierarchy() { - return rc.prepareSubsumptionHierarchy(); - } - // @Override // public ClassHierarchy getClassHierarchy() { // return rc.getClassHierarchy(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -57,7 +57,6 @@ import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; -import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.TypedConstant; import org.dllearner.core.owl.UntypedConstant; @@ -124,10 +123,10 @@ private ConceptComparator conceptComparator = new ConceptComparator(); private RoleComparator roleComparator = new RoleComparator(); - private ClassHierarchy subsumptionHierarchy; +// private ClassHierarchy subsumptionHierarchy; private ObjectPropertyHierarchy roleHierarchy; private DatatypePropertyHierarchy datatypePropertyHierarchy; - private Set<Description> allowedConceptsInSubsumptionHierarchy; +// private Set<Description> allowedConceptsInSubsumptionHierarchy; // primitives Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); @@ -407,85 +406,24 @@ } @Override - public ClassHierarchy prepareSubsumptionHierarchy() { - - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - - // refinements of top - TreeSet<Description> tmp = getMoreSpecialConceptsImpl(new Thing()); - subsumptionHierarchyDown.put(new Thing(), tmp); - - // refinements of bottom - tmp = getMoreGeneralConceptsImpl(new Nothing()); - subsumptionHierarchyUp.put(new Nothing(), tmp); - - // refinements of atomic concepts - for (NamedClass atom : atomicConcepts) { - tmp = getMoreSpecialConceptsImpl(atom); - subsumptionHierarchyDown.put(atom, tmp); - - tmp = getMoreGeneralConceptsImpl(atom); - subsumptionHierarchyUp.put(atom, tmp); - } - - // create subsumption hierarchy - subsumptionHierarchy = new ClassHierarchy(atomicConcepts, - subsumptionHierarchyUp, subsumptionHierarchyDown); + public ObjectPropertyHierarchy prepareRoleHierarchy() { + // code copied from DIG reasoner - return subsumptionHierarchy; - } - - /* (non-Javadoc) - * @see org.dllearner.core.Reasoner#prepareSubsumptionHierarchy(java.util.Set) - */ - public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { - - // implementation almost identical to DIG reasoner - // except function calls - - allowedConceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(allowedConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Thing()); - allowedConceptsInSubsumptionHierarchy.add(new Nothing()); - - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - - // refinements of top - TreeSet<Description> tmp = getMoreSpecialConceptsImpl(new Thing()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(new Thing(), tmp); - - // refinements of bottom - tmp = getMoreGeneralConceptsImpl(new Nothing()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(new Nothing(), tmp); - - // refinements of atomic concepts - for (NamedClass atom : atomicConcepts) { - tmp = getMoreSpecialConceptsImpl(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(atom, tmp); - - tmp = getMoreGeneralConceptsImpl(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(atom, tmp); + TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( + roleComparator); + TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( + roleComparator); + + // refinement of atomic concepts + for (ObjectProperty role : atomicRoles) { + roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); + roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); } - // create subsumption hierarchy - subsumptionHierarchy = new ClassHierarchy(allowedConcepts, - subsumptionHierarchyUp, subsumptionHierarchyDown); + roleHierarchy = new ObjectPropertyHierarchy(atomicRoles, roleHierarchyUp, + roleHierarchyDown); + return roleHierarchy; } - -// @Override -// public ClassHierarchy getClassHierarchy() { -// return subsumptionHierarchy; -// } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#prepareRoleHierarchy(java.util.Set) @@ -546,7 +484,8 @@ } } - private TreeSet<Description> getMoreGeneralConceptsImpl(Description concept) { + @Override + protected TreeSet<Description> getSuperClassesImpl(Description concept) { Set<Set<OWLClass>> classes = null; try { classes = reasoner.getSuperClasses(OWLAPIDescriptionConvertVisitor.getOWLDescription(concept)); @@ -557,19 +496,17 @@ return getFirstClasses(classes); } - private TreeSet<Description> getMoreSpecialConceptsImpl(Description concept) { + @Override + protected TreeSet<Description> getSubClassesImpl(Description concept) { Set<Set<OWLClass>> classes = null; try { -// System.out.println(OWLAPIDescriptionConvertVisitor.getOWLDescription(concept)); -// System.out.println(getSubsumptionHierarchy()); -// System.out.println(reasoner); classes = reasoner.getSubClasses(OWLAPIDescriptionConvertVisitor.getOWLDescription(concept)); } catch (OWLReasonerException e) { e.printStackTrace(); throw new Error("OWL API classification error."); } return getFirstClasses(classes); - } + } private TreeSet<ObjectProperty> getMoreGeneralRolesImpl(ObjectProperty role) { Set<Set<OWLObjectProperty>> properties; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |