From: <jen...@us...> - 2008-11-11 17:07:12
|
Revision: 1508 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1508&view=rev Author: jenslehmann Date: 2008-11-11 17:06:49 +0000 (Tue, 11 Nov 2008) Log Message: ----------- refexamples can now handle ignored classes (again) without interfering with the reasoner (it keeps its own restricted view of the subsumption hierarchy to do this) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.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/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.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 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -45,6 +45,7 @@ import org.dllearner.core.options.IntegerConfigOption; 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.NamedClass; import org.dllearner.core.owl.ObjectProperty; @@ -356,10 +357,13 @@ } // prepare subsumption and role hierarchies, because they are needed - // during the run of the algorithm -// reasoner.prepareSubsumptionHierarchy(usedConcepts); + // during the run of the algorithm; + // in contrast to before, the learning algorithms have to maintain their + // own view on the class hierarchy + ClassHierarchy classHierarchy = reasoner.getClassHierarchy().cloneAndRestrict(usedConcepts); if(improveSubsumptionHierarchy) - reasoner.getClassHierarchy().thinOutSubsumptionHierarchy(); + classHierarchy.thinOutSubsumptionHierarchy(); + // reasoner.prepareRoleHierarchy(usedRoles); // prepare datatype hierarchy only if necessary // if(reasoner.hasDatatypeSupport()) @@ -369,6 +373,7 @@ // variables to it RhoDRDown operator = new RhoDRDown( reasoner, + classHierarchy, applyAllFilter, applyExistsFilter, useAllConstructor, Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -749,7 +749,7 @@ @Override public final SortedSet<Description> getSuperClasses(Description concept) { - return getClassHierarchy().getMoreGeneralConcepts(concept); + return getClassHierarchy().getSuperClasses(concept); } protected SortedSet<Description> getSuperClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { @@ -758,7 +758,7 @@ @Override public final SortedSet<Description> getSubClasses(Description concept) { - return getClassHierarchy().getMoreSpecialConcepts(concept); + return getClassHierarchy().getSubClasses(concept); } protected SortedSet<Description> getSubClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { @@ -819,15 +819,19 @@ TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, SortedSet<Description>>( conceptComparator); - // refinements of top + // parents/children of top ... SortedSet<Description> tmp = getSubClassesImpl(Thing.instance); - subsumptionHierarchyDown.put(new Thing(), tmp); + subsumptionHierarchyUp.put(Thing.instance, new TreeSet<Description>()); + subsumptionHierarchyDown.put(Thing.instance, tmp); - // refinements of bottom + + + // ... bottom ... tmp = getSuperClassesImpl(Nothing.instance); - subsumptionHierarchyUp.put(new Nothing(), tmp); + subsumptionHierarchyUp.put(Nothing.instance, tmp); + subsumptionHierarchyDown.put(Nothing.instance, new TreeSet<Description>()); - // refinements of atomic concepts + // ... and named classes Set<NamedClass> atomicConcepts = getNamedClasses(); for (NamedClass atom : atomicConcepts) { tmp = getSubClassesImpl(atom); @@ -845,6 +849,8 @@ subsumptionHierarchyUp.put(atom, tmp); } + + return new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); } Modified: trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -54,10 +54,12 @@ this.subsumptionHierarchyUp = subsumptionHierarchyUp; this.subsumptionHierarchyDown = subsumptionHierarchyDown; + + } - public SortedSet<Description> getMoreGeneralConcepts(Description concept) { + public SortedSet<Description> getSuperClasses(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"); @@ -68,7 +70,7 @@ return new TreeSet<Description>(result); } - public SortedSet<Description> getMoreSpecialConcepts(Description concept) { + public SortedSet<Description> getSubClasses(Description concept) { 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"); @@ -200,22 +202,31 @@ * 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. + * Currently, owl:Thing and owl:Nothing are always allowed for technical + * reasons. * @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) { + // currently TOP and BOTTOM are always allowed + // (TODO would be easier if Thing/Nothing were declared as named classes) + Set<Description> allowed = new TreeSet<Description>(conceptComparator); + allowed.addAll(allowedClasses); + allowed.add(Thing.instance); + allowed.add(Nothing.instance); + // create new maps TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUpNew - = new TreeMap<Description, SortedSet<Description>>(); + = new TreeMap<Description, SortedSet<Description>>(conceptComparator); TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDownNew - = new TreeMap<Description, SortedSet<Description>>(); + = new TreeMap<Description, SortedSet<Description>>(conceptComparator); for(Entry<Description, SortedSet<Description>> entry : subsumptionHierarchyUp.entrySet()) { Description key = entry.getKey(); // we only store mappings for allowed classes - if(allowedClasses.contains(key)) { + if(allowed.contains(key)) { // copy the set of all super classes (we consume them until // they are empty) TreeSet<Description> superClasses = new TreeSet<Description>(entry.getValue()); @@ -226,7 +237,7 @@ // pick and remove the first element Description d = superClasses.pollFirst(); // case 1: it is allowed, so we add it - if(allowedClasses.contains(d)) { + if(allowed.contains(d)) { newSuperClasses.add(d); // case 2: it is not allowed, so we try its super classes } else { @@ -241,13 +252,13 @@ // downward case is analogous for(Entry<Description, SortedSet<Description>> entry : subsumptionHierarchyDown.entrySet()) { Description key = entry.getKey(); - if(allowedClasses.contains(key)) { + if(allowed.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)) { + if(allowed.contains(d)) { newSubClasses.add(d); } else { subClasses.addAll(subsumptionHierarchyDown.get(d)); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -182,16 +182,17 @@ // private Map<NamedClass,Map<NamedClass,Boolean>> notABMeaningful = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); public RhoDRDown(ReasonerComponent reasoningService) { - this(reasoningService, true, true, true, true, true, 3, true, true, true, true, null); + this(reasoningService, reasoningService.getClassHierarchy(), true, true, true, true, true, 3, true, true, true, true, null); } // TODO constructor which takes a RhoDRDownConfigurator object; // this should be an interface implemented e.g. by ExampleBasedROLComponentConfigurator; // the goal is to use the configurator system while still being flexible enough to // use one refinement operator in several learning algorithms - public RhoDRDown(ReasonerComponent reasoningService, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, + public RhoDRDown(ReasonerComponent reasoningService, ClassHierarchy subHierarchy, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, boolean useExistsConstructor, boolean useHasValueConstructor, int valueFrequencyThreshold, boolean useCardinalityRestrictions,boolean useNegation, boolean useBooleanDatatypes, boolean useDoubleDatatypes, NamedClass startClass) { this.rs = reasoningService; + this.subHierarchy = subHierarchy; this.applyAllFilter = applyAllFilter; this.applyExistsFilter = applyExistsFilter; this.useAllConstructor = useAllConstructor; @@ -203,7 +204,7 @@ this.useBooleanDatatypes = useBooleanDatatypes; this.useDoubleDatatypes = useDoubleDatatypes; - subHierarchy = rs.getClassHierarchy(); +// subHierarchy = rs.getClassHierarchy(); // query reasoner for domains and ranges // (because they are used often in the operator) @@ -369,11 +370,11 @@ } else if(description instanceof Nothing) { // cannot be further refined } else if(description instanceof NamedClass) { - refinements.addAll(subHierarchy.getMoreSpecialConcepts(description)); + refinements.addAll(subHierarchy.getSubClasses(description)); refinements.remove(new Nothing()); } else if (description instanceof Negation && description.getChild(0) instanceof NamedClass) { - tmp = rs.getSuperClasses(description.getChild(0)); + tmp = subHierarchy.getSuperClasses(description.getChild(0)); for(Description c : tmp) { if(!(c instanceof Thing)) @@ -839,12 +840,12 @@ m.put(i, new TreeSet<Description>(conceptComparator)); } - SortedSet<Description> m1 = rs.getSubClasses(new Thing()); + SortedSet<Description> m1 = subHierarchy.getSubClasses(new Thing()); m.put(1,m1); SortedSet<Description> m2 = new TreeSet<Description>(conceptComparator); if(useNegation) { - Set<Description> m2tmp = rs.getSuperClasses(new Nothing()); + Set<Description> m2tmp = subHierarchy.getSuperClasses(new Nothing()); for(Description c : m2tmp) { m2.add(new Negation(c)); } @@ -919,7 +920,7 @@ mA.get(nc).put(i, new TreeSet<Description>(conceptComparator)); } - SortedSet<Description> m1 = rs.getSubClasses(nc); + SortedSet<Description> m1 = subHierarchy.getSubClasses(nc); mA.get(nc).put(1,m1); SortedSet<Description> m2 = new TreeSet<Description>(conceptComparator); @@ -930,7 +931,7 @@ // recursive method because for A subClassOf A' we have not A' // subClassOf A and thus: if A and B are disjoint then also A' // and B; if not A AND B = B then also not A' AND B = B - SortedSet<Description> m2tmp = rs.getSuperClasses(new Nothing()); + SortedSet<Description> m2tmp = subHierarchy.getSuperClasses(new Nothing()); for(Description c : m2tmp) { if(c instanceof Thing) Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -114,7 +114,7 @@ // there are 4 checks a class has to satisfy to get into the set; // for 2 of them we can stop further traversal in the subsumption // hierarchy - for(Description d : sh.getMoreSpecialConcepts(upperClass)) { + for(Description d : sh.getSubClasses(upperClass)) { // owl:Nothing is never a candidate (not in EL) if(!(d instanceof Nothing)) { NamedClass candidate = (NamedClass) d; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |