From: <jen...@us...> - 2009-02-19 15:25:50
|
Revision: 1618 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1618&view=rev Author: jenslehmann Date: 2009-02-19 15:25:44 +0000 (Thu, 19 Feb 2009) Log Message: ----------- OE algorithm ctd. Modified Paths: -------------- trunk/examples/family/father_oe.owl trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java trunk/src/dl-learner/org/dllearner/algorithms/refinement2/MultiHeuristic.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java Modified: trunk/examples/family/father_oe.owl =================================================================== --- trunk/examples/family/father_oe.owl 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/examples/family/father_oe.owl 2009-02-19 15:25:44 UTC (rev 1618) @@ -36,7 +36,10 @@ <!-- http://example.com/father#hasChild --> - <owl:ObjectProperty rdf:about="#hasChild"/> + <owl:ObjectProperty rdf:about="#hasChild"> + <rdfs:range rdf:resource="#person"/> + <rdfs:domain rdf:resource="#person"/> + </owl:ObjectProperty> @@ -62,6 +65,7 @@ <!-- http://example.com/father#female --> <owl:Class rdf:about="#female"> + <rdfs:subClassOf rdf:resource="#person"/> <owl:disjointWith rdf:resource="#male"/> </owl:Class> @@ -69,10 +73,26 @@ <!-- http://example.com/father#male --> - <owl:Class rdf:about="#male"/> + <owl:Class rdf:about="#male"> + <rdfs:subClassOf rdf:resource="#person"/> + </owl:Class> + <!-- http://example.com/father#person --> + + <owl:Class rdf:about="#person"> + <rdfs:subClassOf rdf:resource="&owl;Thing"/> + </owl:Class> + + + + <!-- http://www.w3.org/2002/07/owl#Thing --> + + <owl:Class rdf:about="&owl;Thing"/> + + + <!-- /////////////////////////////////////////////////////////////////////////////////////// // Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-19 15:25:44 UTC (rev 1618) @@ -42,11 +42,13 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Restriction; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.ConceptTransformation; import org.dllearner.utilities.owl.EvaluatedDescriptionSet; /** @@ -92,7 +94,8 @@ // utility variables private String baseURI; private Map<String, String> prefixes; - DecimalFormat dfPercent = new DecimalFormat("0.00%"); + private DecimalFormat dfPercent = new DecimalFormat("0.00%"); + private ConceptComparator descriptionComparator = new ConceptComparator(); @Override public Configurator getConfigurator() { @@ -249,7 +252,7 @@ // print solution(s) // logger.info("solution : " + bestDescriptionToString()); - logger.info(getSolutionString()); + logger.info("solutions:\n" + getSolutionString()); // System.out.println(startNode.toTreeString(baseURI)); @@ -300,10 +303,12 @@ nodes.add(node); // maybe add to best descriptions (method keeps set size fixed) - if(checkNode(node)) { - bestEvaluatedDescriptions.add(description, accuracy, learningProblem); +// if(checkNode(node)) { + Description niceDescription = rewriteNode(node); +// Description niceDescription = node.getDescription(); + bestEvaluatedDescriptions.add(niceDescription, accuracy, learningProblem); // System.out.println(bestEvaluatedDescriptions.toString()); - } +// } return true; } @@ -311,35 +316,60 @@ // checks whether the description is allowed private boolean isDescriptionAllowed(Description description) { if(isEquivalenceProblem) { - // for equivalence problems, we need to check that the class we are learning does - // not itself occur on the outermost level (property depth 0) - if(description instanceof NamedClass) { - if(description.equals(classToDescribe)) { + // the class to learn must not appear on the outermost property level + return !occursOnFirstLevel(description, classToDescribe); + } else { + // none of the superclasses of the class to learn must appear on the + // outermost property level + TreeSet<Description> toTest = new TreeSet<Description>(); + toTest.add(classToDescribe); + while(!toTest.isEmpty()) { + Description d = toTest.pollFirst(); + if(occursOnFirstLevel(description, d)) { return false; } - } else if(description.getChildren().size() > 1) { - for(Description child : description.getChildren()) { - if(child.equals(classToDescribe)) { - return false; - } - } + toTest.addAll(reasoner.getClassHierarchy().getSuperClasses(d)); } - } else { - + return true; } + } + + // determine whether a named class occurs on the outermost level, i.e. property depth 0 + // (it can still be at higher depth, e.g. if intersections are nested in unions) + private boolean occursOnFirstLevel(Description description, Description clazz) { + if(description instanceof NamedClass) { + if(description.equals(clazz)) { + return true; + } + } - 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 // (sufficient accuracy; minimal; rewriting steps?) - private boolean checkNode(OENode node) { + private Description rewriteNode(OENode node) { // what to do if super class occurs? either return false, but then it // does not make sense to expand it further; or rewrite but then we have to // take care of double occurrences + Description description = node.getDescription(); + // shorten description (syntactically) + Description niceDescription = ConceptTransformation.getShortConcept(description, descriptionComparator); + // replace \exists r.\top with \exists r.range(r) + ConceptTransformation.replaceRange(niceDescription, reasoner); - return true; + return niceDescription; } private boolean terminationCriteriaSatisfied() { Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2009-02-19 15:25:44 UTC (rev 1618) @@ -19,6 +19,8 @@ */ package org.dllearner.algorithms.celoe; +import org.dllearner.utilities.owl.ConceptComparator; + /** * Search algorithm heuristic for the ontology engineering algorithm. The heuristic * has a strong bias towards short descriptions (i.e. the algorithm is likely to be @@ -36,6 +38,8 @@ // penalty if a node has very many children since exploring such a node is // computationally very expensive private double nodeChildPenalty = 0.0005; + // syntactic comparison as final comparison criterion + private ConceptComparator conceptComparator = new ConceptComparator(); @Override public int compare(OENode node1, OENode node2) { @@ -45,7 +49,7 @@ else if(diff<0) return -1; else - return 0; + return conceptComparator.compare(node1.getDescription(), node2.getDescription()); } public double getNodeScore(OENode node) { Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/MultiHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/MultiHeuristic.java 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/MultiHeuristic.java 2009-02-19 15:25:44 UTC (rev 1618) @@ -121,8 +121,8 @@ else if(diff<0) return -1; else - // TODO: would it be OK to simply return 0 here (?) - // could improve performance a bit + // we cannot return 0 here otherwise different nodes/concepts with the + // same score may be ignored (not added to a set because an equal element exists) return conceptComparator.compare(node1.getConcept(), node2.getConcept()); } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-19 15:25:44 UTC (rev 1618) @@ -28,7 +28,6 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.ClassLearningProblemConfigurator; -import org.dllearner.core.configurators.PosNegLPStandardConfigurator; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-19 15:25:44 UTC (rev 1618) @@ -600,7 +600,7 @@ ObjectProperty op = (ObjectProperty) ope; Description child = description.getChild(0); Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); + SortedSet<Individual> targetSet = getIndividualsImpl(child); SortedSet<Individual> returnSet = new TreeSet<Individual>(); int number = ((ObjectCardinalityRestriction) description).getNumber(); Modified: trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-02-19 15:25:44 UTC (rev 1618) @@ -31,7 +31,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-19 15:25:44 UTC (rev 1618) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2008, Jens Lehmann + * Copyright (C) 2007-2009, Jens Lehmann * * This file is part of DL-Learner. * @@ -374,6 +374,12 @@ return concept; } + /** + * Tries to shorten a concept, e.g. male AND male is shortened to male. + * @param concept The input concepts. + * @param conceptComparator A comparator for concepts. + * @return A shortened version of the concept (equal to the input concept if it cannot be shortened). + */ public static Description getShortConcept(Description concept, ConceptComparator conceptComparator) { shorteningTimeNsStart = System.nanoTime(); // deep copy des Konzepts, da es nicht verändert werden darf Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-19 13:55:58 UTC (rev 1617) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-19 15:25:44 UTC (rev 1618) @@ -23,7 +23,6 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.SortedSet; import java.util.TreeSet; import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |