From: <jen...@us...> - 2008-07-31 14:30:06
|
Revision: 1034 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1034&view=rev Author: jenslehmann Date: 2008-07-31 14:29:56 +0000 (Thu, 31 Jul 2008) Log Message: ----------- - improved refinement operator interface - continued work on EL description trees Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -24,7 +24,12 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.UnsupportedLanguageException; /** * Represents an EL description tree, which corresponds to a @@ -86,6 +91,16 @@ } /** + * Constructs an EL description tree from an EL description. + * @param description A description + */ + public ELDescriptionTree(Description description) { + // TODO not implemented + // throw an exception if the description is not in EL + throw new UnsupportedLanguageException(description.toString(), "EL"); + } + + /** * Checks whether this node has a parent. If the parent link * is null, the node is considered to be a root node. * @return True of this is the root node and false otherwise. @@ -127,6 +142,33 @@ } /** + * This method transform the tree to an EL description. The + * node labels are transformed to an {@link Intersection} + * of {@link NamedClass}. Each edges is transformed to an + * {@link ObjectSomeRestriction}, where the property is the edge + * label and the child description the subtree the edge points + * to. Edges are also added to the intersection. If the intersection + * is empty, {@link Thing} is returned. + * @return The description corresponding to this EL description tree. + */ + public Description transformToDescription() { + if(label.size()==0 && edges.size()==0) { + return new Thing(); + } else { + Intersection is = new Intersection(); + for(NamedClass nc : label) { + is.addChild(nc); + } + for(Edge edge : edges) { + Description child = edge.getTree().transformToDescription(); + ObjectSomeRestriction osr = new ObjectSomeRestriction(edge.getLabel(),child); + is.addChild(osr); + } + return is; + } + } + + /** * @return The label of root node of this subtree. */ public SortedSet<NamedClass> getLabel() { Added: trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -0,0 +1,39 @@ +/** + * 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; + +/** + * This exception is thrown if an operation does not support + * the required language. For instance, if a description containing + * a disjunction is passed to a method, which is only designed to + * handle EL concepts, this exception can be thrown. + * + * @author Jens Lehmann + * + */ +public class UnsupportedLanguageException extends RuntimeException { + + private static final long serialVersionUID = -1271204878357422920L; + + public UnsupportedLanguageException(String unsupportedConstruct, String targetLanguage) { + super("Unsupported construct \"" + unsupportedConstruct + "\". The target language is \"" + targetLanguage + "\"."); + } + +} Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -19,9 +19,10 @@ */ package org.dllearner.refinementoperators; -import java.util.List; +import java.util.HashSet; import java.util.Set; +import org.dllearner.algorithms.el.ELDescriptionTree; import org.dllearner.core.owl.Description; /** @@ -42,24 +43,31 @@ * @author Jens Lehmann * */ -public class ELDown implements RefinementOperator { +public class ELDown extends RefinementOperatorAdapter { /* (non-Javadoc) * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description) */ @Override public Set<Description> refine(Description concept) { - // TODO Auto-generated method stub - return null; + ELDescriptionTree tree = new ELDescriptionTree(concept); + Set<ELDescriptionTree> refinementTrees = refine(tree); + Set<Description> refinements = new HashSet<Description>(); + for(ELDescriptionTree refinementTree : refinementTrees) { + refinements.add(refinementTree.transformToDescription()); + } + return refinements; } - - /* (non-Javadoc) - * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) + + /** + * Performs downward refinement for the given tree. The operator + * works directly on EL description trees (which differ from the + * the tree structures build by descriptions). + * + * @param tree Input EL description tree. + * @return Set of refined EL description trees. */ - @Override - public Set<Description> refine(Description concept, int maxLength, - List<Description> knownRefinements) { - // TODO Auto-generated method stub + public Set<ELDescriptionTree> refine(ELDescriptionTree tree) { return null; } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -34,7 +34,7 @@ * @author jl * */ -public class PsiDown implements RefinementOperator { +public class PsiDown extends RefinementOperatorAdapter { ConceptComparator conceptComparator = new ConceptComparator(); @@ -75,6 +75,7 @@ } } + @Override @SuppressWarnings("unchecked") public Set<Description> refine(Description concept) { @@ -236,6 +237,7 @@ } + @Override public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements) { throw new RuntimeException(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -22,7 +22,7 @@ import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.owl.ConceptComparator; -public class PsiUp implements RefinementOperator { +public class PsiUp extends RefinementOperatorAdapter { ConceptComparator conceptComparator = new ConceptComparator(); @@ -63,6 +63,7 @@ } } + @Override @SuppressWarnings("unchecked") public Set<Description> refine(Description concept) { @@ -212,6 +213,7 @@ return refinements; } + @Override public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements) { throw new RuntimeException(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -1,3 +1,22 @@ +/** + * 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.refinementoperators; import java.util.List; @@ -5,10 +24,45 @@ import org.dllearner.core.owl.Description; +/** + * Interface for all refinement operators based on OWL/Description Logics. + * A refinement operator + * maps a description to a set of descriptions. For downward refinement + * operators those descriptions are more special. For upward refinement + * operators, those descriptions are more general. + * + * @author Jens Lehmann + * + */ public interface RefinementOperator { - public Set<Description> refine(Description concept); - // SortedSet zu erzwingen ist nicht so elegant - public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements); + /** + * Standard refinement operation. + * @param description The description, which will be refined. + * @return A set of refinements. + */ + public Set<Description> refine(Description description); + /** + * Optional refinement operation, where the learning algorithm can + * specify an additional bound on the length of descriptions. + * + * @param description The description, which will be refined. + * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}. + * @return A set of refinements obeying the above restrictions. + */ + public Set<Description> refine(Description description, int maxLength); + + /** + * Optional refinement operation, where the learning algorithm can + * specify an additional bound on the length of descriptions and + * a list of known refinements, which do not need to be returned. + * + * @param description The description, which will be refined. + * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}. + * @param knownRefinements A collection of known refinements, which do not need to be returned. + * @return A set of refinements obeying the above restrictions. + */ + public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements); + } Added: trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -0,0 +1,58 @@ +/** + * 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.refinementoperators; + +import java.util.List; +import java.util.Set; + +import org.dllearner.core.owl.Description; + +/** + * Adapter for {@link RefinementOperator} interface. + * + * @author Jens Lehmann + * + */ +public abstract class RefinementOperatorAdapter implements RefinementOperator { + + /* (non-Javadoc) + * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description) + */ + @Override + public abstract Set<Description> refine(Description description); + + /* (non-Javadoc) + * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int) + */ + @Override + public Set<Description> refine(Description description, int maxLength) { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) + */ + @Override + public Set<Description> refine(Description description, int maxLength, + List<Description> knownRefinements) { + throw new UnsupportedOperationException(); + } + +} Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -73,7 +73,7 @@ * @author Jens Lehmann * */ -public class RhoDRDown implements RefinementOperator { +public class RhoDRDown extends RefinementOperatorAdapter { @SuppressWarnings({"unused"}) private static Logger logger = Logger @@ -259,6 +259,7 @@ /* (non-Javadoc) * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description) */ + @Override public Set<Description> refine(Description concept) { throw new RuntimeException(); } @@ -266,6 +267,7 @@ /* (non-Javadoc) * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) */ + @Override public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements) { return refine(description, maxLength, knownRefinements, startClass); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -59,7 +59,7 @@ * @author Jens Lehmann * */ -public class RhoDown implements RefinementOperator { +public class RhoDown extends RefinementOperatorAdapter { // private PosNegLP learningProblem; private ReasoningService rs; @@ -111,6 +111,7 @@ // rs = learningProblem.getReasoningService(); } + @Override public Set<Description> refine(Description concept) { throw new RuntimeException(); // TODO Auto-generated method stub @@ -123,6 +124,7 @@ // => als zweites wäre bei nicht ausreichendem Performancegewinn die Implementierung // von Minimallänge eine Möglichkeit (alle Refinements, auch improper, müssten // dann im Algorithmus gespeichert werden) + @Override @SuppressWarnings("unchecked") public SortedSet<Description> refine(Description concept, int maxLength, List<Description> knownRefinements) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |