From: <jen...@us...> - 2009-02-27 11:39:38
|
Revision: 1637 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1637&view=rev Author: jenslehmann Date: 2009-02-27 11:39:32 +0000 (Fri, 27 Feb 2009) Log Message: ----------- extended CELOE such that the all quantifier is not suggested in some unreasonable cases, e.g. \exists r.\forall s.\top cannot (from a human point of view) be a preferred solution if none of the instances of the considered class has an r-filler which has an s-filler Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/owl/PropertyContext.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-26 19:03:36 UTC (rev 1636) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-27 11:39:32 UTC (rev 1637) @@ -41,6 +41,7 @@ import org.dllearner.core.options.ConfigOption; import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; @@ -53,6 +54,7 @@ import org.dllearner.utilities.owl.ConceptTransformation; import org.dllearner.utilities.owl.DescriptionMinimizer; import org.dllearner.utilities.owl.EvaluatedDescriptionSet; +import org.dllearner.utilities.owl.PropertyContext; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -93,6 +95,7 @@ private EvaluatedDescriptionSet bestEvaluatedDescriptions; private NamedClass classToDescribe; + private Set<Individual> classInstances; private boolean isEquivalenceProblem; private long nanoStartTime; @@ -160,6 +163,8 @@ ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone(); classHierarchy.thinOutSubsumptionHierarchy(); + classInstances = reasoner.getIndividuals(classToDescribe); + minimizer = new DescriptionMinimizer(reasoner); // start class: intersection of super classes for definitions (since it needs to @@ -338,19 +343,10 @@ } // check whether the description is allowed - if(!isDescriptionAllowed(description)) { + if(!isDescriptionAllowed(description, parentNode)) { return false; } - // perform forall sanity tests (TODO: move to separate method) - if(parentNode != null && ConceptTransformation.getForallOccurences(description) > ConceptTransformation.getForallOccurences(parentNode.getDescription())) { - // we have an additional \forall construct, so we now fetch the contexts - // in which it occurs - List<List<ObjectProperty>> contexts = ConceptTransformation.getForallContexts(description); - List<List<ObjectProperty>> parentContexts = ConceptTransformation.getForallContexts(parentNode.getDescription()); - - } - // quality of description (return if too weak) double accuracy = learningProblem.getAccuracyOrTooWeak(description, minAcc); descriptionTests++; @@ -405,10 +401,12 @@ } // checks whether the description is allowed - private boolean isDescriptionAllowed(Description description) { + private boolean isDescriptionAllowed(Description description, OENode parentNode) { if(isEquivalenceProblem) { // the class to learn must not appear on the outermost property level - return !occursOnFirstLevel(description, classToDescribe); + if(occursOnFirstLevel(description, classToDescribe)) { + return false; + } } else { // none of the superclasses of the class to learn must appear on the // outermost property level @@ -423,10 +421,42 @@ } } + // perform forall sanity tests + if(parentNode != null && ConceptTransformation.getForallOccurences(description) > ConceptTransformation.getForallOccurences(parentNode.getDescription())) { + // we have an additional \forall construct, so we now fetch the contexts + // in which it occurs + SortedSet<PropertyContext> contexts = ConceptTransformation.getForallContexts(description); + SortedSet<PropertyContext> parentContexts = ConceptTransformation.getForallContexts(parentNode.getDescription()); + contexts.removeAll(parentContexts); +// System.out.println("parent description: " + parentNode.getDescription()); +// System.out.println("description: " + description); +// System.out.println("contexts: " + contexts); + // we now have to perform sanity checks: if \forall is used, then there + // should be at least on class instance which has a filler at the given context + for(PropertyContext context : contexts) { + // transform [r,s] to \exists r.\exists s.\top + Description existentialContext = context.toExistentialContext(); + boolean fillerFound = false; + for(Individual instance : classInstances) { + if(reasoner.hasType(existentialContext, instance)) { +// System.out.println(instance + " " + existentialContext); + fillerFound = true; + break; + } + } + // if we do not find a filler, this means that putting \forall at + // that position is not meaningful + if(!fillerFound) { + return false; + } + } + } + // we do not want to have negations of sibling classes on the outermost level // (they are expressed more naturally by saying that the siblings are disjoint, // so it is reasonable not to include them in solutions) - Set<Description> siblingClasses = reasoner.getClassHierarchy().getSiblingClasses(classToDescribe); +// Set<Description> siblingClasses = reasoner.getClassHierarchy().getSiblingClasses(classToDescribe); +// for now, we just disable negation return true; } @@ -453,26 +483,6 @@ return false; } - private boolean occursNegatedOnFirstLevel(Description description, Description clazz) { - if(description instanceof NamedClass) { - if(description.equals(clazz)) { - return true; - } - } - - if(description instanceof Restriction) { - return false; - } - - for(Description child : description.getChildren()) { - if(occursOnFirstLevel(child, clazz)) { - return true; - } - } - - return false; - } - // check whether the node is a potential solution candidate private Description rewriteNode(OENode node) { Description description = node.getDescription(); Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-26 19:03:36 UTC (rev 1636) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-27 11:39:32 UTC (rev 1637) @@ -583,11 +583,11 @@ return count; } - public static List<List<ObjectProperty>> getForallContexts(Description description) { - return getForallContexts(description, new LinkedList<ObjectProperty>()); + public static SortedSet<PropertyContext> getForallContexts(Description description) { + return getForallContexts(description, new PropertyContext()); } - private static List<List<ObjectProperty>> getForallContexts(Description description, List<ObjectProperty> currentContext) { + private static SortedSet<PropertyContext> getForallContexts(Description description, PropertyContext currentContext) { // the context changes if we have a restriction if(description instanceof Restriction) { ObjectProperty op = (ObjectProperty) ((Restriction)description).getRestrictedPropertyExpression(); @@ -595,7 +595,7 @@ // if we have an all-restriction, we return it; otherwise we only change the context // and call the method on the child if(description instanceof ObjectAllRestriction) { - List<List<ObjectProperty>> contexts = new LinkedList<List<ObjectProperty>>(); + TreeSet<PropertyContext> contexts = new TreeSet<PropertyContext>(); contexts.add(currentContext); contexts.addAll(getForallContexts(description.getChild(0), currentContext)); return contexts; @@ -604,7 +604,7 @@ } // for non-restrictions, we collect contexts over all children } else { - List<List<ObjectProperty>> contexts = new LinkedList<List<ObjectProperty>>(); + TreeSet<PropertyContext> contexts = new TreeSet<PropertyContext>(); for(Description child : description.getChildren()) { contexts.addAll(getForallContexts(child, currentContext)); } Added: trunk/src/dl-learner/org/dllearner/utilities/owl/PropertyContext.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/PropertyContext.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/PropertyContext.java 2009-02-27 11:39:32 UTC (rev 1637) @@ -0,0 +1,76 @@ +/** + * Copyright (C) 2007-2009, 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.utilities.owl; + +import java.util.LinkedList; + +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Thing; + +/** + * A property context is a utility class which specifies the + * position of constructs with respect to properties of a + * construct in a class description. For instance, the A + * in \exists r.\exists s.A occurs in property context [r,s]. + * + * @author Jens Lehmann + * + */ +public class PropertyContext extends LinkedList<ObjectProperty> implements Comparable<PropertyContext> { + + private static final long serialVersionUID = -4403308689522524077L; + + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(PropertyContext context) { + // we first distinguish on size - simpler contexts come first + int diff = context.size() - size(); + if(diff != 0) { + return diff; + } + + for(int i=0; i<size(); i++) { + int cmp = get(i).getName().compareTo(context.get(i).getName()); + if(cmp != 0) { + return cmp; + } + } + + return 0; + } + + /** + * Transforms context [r,s] to \exists r.\exists s.\top. + * @return A description with existential quantifiers and \top corresponding + * to the context. + */ + public Description toExistentialContext() { + Description d = Thing.instance; + for(int i = size()-1; i>=0; i--) { + d = new ObjectSomeRestriction(get(i), d); + } + return d; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |