From: <jen...@us...> - 2008-02-17 10:08:17
|
Revision: 586 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=586&view=rev Author: jenslehmann Date: 2008-02-17 02:08:08 -0800 (Sun, 17 Feb 2008) Log Message: ----------- partial fix for #1880138 Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/LearningProblemUnsupportedException.java Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-17 09:48:24 UTC (rev 585) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-17 10:08:08 UTC (rev 586) @@ -48,6 +48,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.OntologyFormat; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; @@ -215,7 +216,12 @@ else handleError("Unknown value in " + algorithmOption); - la = cm.learningAlgorithm(laClass, lp, rs); + try { + la = cm.learningAlgorithm(laClass, lp, rs); + } catch (LearningProblemUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } configureComponent(cm, la, componentPrefixMapping, parser); initComponent(cm, la); Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-02-17 09:48:24 UTC (rev 585) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-02-17 10:08:08 UTC (rev 586) @@ -316,7 +316,7 @@ } // automagically calls the right constructor for the given learning problem - public <T extends LearningAlgorithm> T learningAlgorithm(Class<T> laClass, LearningProblem lp, ReasoningService rs) { + public <T extends LearningAlgorithm> T learningAlgorithm(Class<T> laClass, LearningProblem lp, ReasoningService rs) throws LearningProblemUnsupportedException { if (!learningAlgorithms.contains(laClass)) System.err.println("Warning: learning algorithm " + laClass + " is not a registered learning algorithm component."); @@ -330,11 +330,12 @@ } if (constructorArgument == null) { - System.err.println("Warning: No suitable constructor registered for algorithm " - + laClass.getName() + " and problem " + lp.getClass().getName() - + ". Registered constructors for " + laClass.getName() + ": " - + algorithmProblemsMapping.get(laClass) + "."); - return null; + throw new LearningProblemUnsupportedException(lp.getClass(), laClass, algorithmProblemsMapping.get(laClass)); +// System.err.println("Warning: No suitable constructor registered for algorithm " +// + laClass.getName() + " and problem " + lp.getClass().getName() +// + ". Registered constructors for " + laClass.getName() + ": " +// + algorithmProblemsMapping.get(laClass) + "."); +// return null; } T la = invokeConstructor(laClass, new Class[] { constructorArgument, ReasoningService.class }, new Object[] { lp, rs }); Added: trunk/src/dl-learner/org/dllearner/core/LearningProblemUnsupportedException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblemUnsupportedException.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblemUnsupportedException.java 2008-02-17 10:08:08 UTC (rev 586) @@ -0,0 +1,48 @@ +/** + * 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; + +import java.util.Collection; + +/** + * Exception, which is thrown when an application tries to run + * a learning algorithm with a learning problem it does not + * support. + * + * @author Jens Lehmann + * + */ +public class LearningProblemUnsupportedException extends Exception { + + private static final long serialVersionUID = 177919265073997460L; + + public LearningProblemUnsupportedException(Class<? extends LearningProblem> problemClass, Class<? extends LearningAlgorithm> algorithmClass) { + super("Warning: No suitable constructor registered for algorithm " + + algorithmClass.getName() + " and problem " + problemClass.getClass().getName() + "."); + } + + public LearningProblemUnsupportedException(Class<? extends LearningProblem> problemClass, Class<? extends LearningAlgorithm> algorithmClass, Collection<Class<? extends LearningProblem>> supportedProblems) { + super("Warning: No suitable constructor registered for algorithm " + + algorithmClass.getName() + " and problem " + problemClass.getClass().getName() + + ". Registered constructors for " + algorithmClass.getName() + ": " + + supportedProblems + "."); + } + +} Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-17 09:48:24 UTC (rev 585) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-17 10:08:08 UTC (rev 586) @@ -28,6 +28,7 @@ import java.util.List; import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblemUnsupportedException; /** * LearningAlgorithmPanel, tab 4. Choose LearningAlgorithm, change Options and @@ -107,10 +108,15 @@ public void setLearningAlgorithm() { if (config.getLearningProblem() != null && config.getReasoningService() != null) { - config.setLearningAlgorithm(config.getComponentManager() - .learningAlgorithm(learners.get(choosenClassIndex), - config.getLearningProblem(), - config.getReasoningService())); + try { + config.setLearningAlgorithm(config.getComponentManager() + .learningAlgorithm(learners.get(choosenClassIndex), + config.getLearningProblem(), + config.getReasoningService())); + } catch (LearningProblemUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } updateOptionPanel(); } } Modified: trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-02-17 09:48:24 UTC (rev 585) +++ trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-02-17 10:08:08 UTC (rev 586) @@ -43,6 +43,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; @@ -163,7 +164,13 @@ // try the refinement operator based learning algorithm to solve // the problem - LearningAlgorithm la = cm.learningAlgorithm(ROLearner.class, lp, rs); + LearningAlgorithm la = null; + try { + la = cm.learningAlgorithm(ROLearner.class, lp, rs); + } catch (LearningProblemUnsupportedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } la.init(); la.start(); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-17 09:48:24 UTC (rev 585) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-17 10:08:08 UTC (rev 586) @@ -45,6 +45,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.NamedClass; @@ -248,7 +249,7 @@ } @WebMethod - public int setLearningAlgorithm(int id, String component) throws ClientNotKnownException, UnknownComponentException { + public int setLearningAlgorithm(int id, String component) throws ClientNotKnownException, UnknownComponentException, LearningProblemUnsupportedException { ClientState state = getState(id); Class<? extends LearningAlgorithm> laClass = learningAlgorithmMapping.get(component); if(laClass == null) Modified: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-02-17 09:48:24 UTC (rev 585) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-02-17 10:08:08 UTC (rev 586) @@ -28,6 +28,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.kb.OWLFile; @@ -77,7 +78,13 @@ lp.init(); // create the learning algorithm - LearningAlgorithm la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); + LearningAlgorithm la = null; + try { + la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); + } catch (LearningProblemUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } cm.applyConfigEntry(la, "numberOfTrees", 100); cm.applyConfigEntry(la, "maxDepth", 5); la.init(); Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2008-02-17 09:48:24 UTC (rev 585) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2008-02-17 10:08:08 UTC (rev 586) @@ -32,6 +32,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.OntologyFormat; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; @@ -237,7 +238,12 @@ // if(exampleNr==3 || exampleNr==5 || exampleNr == 6) // Config.percentPerLengthUnit = 0.002; // learningAlgorithm = new GP(learningProblem); - learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem, rs); + try { + learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem, rs); + } catch (LearningProblemUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } else if(algorithmNr==2) { // Config.algorithm = Algorithm.HYBRID_GP; // Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; @@ -255,7 +261,12 @@ // if(exampleNr == 3 || exampleNr==5 || exampleNr==6) // Config.percentPerLengthUnit = 0.002; // learningAlgorithm = new GP(learningProblem); - learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem, rs); + try { + learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem, rs); + } catch (LearningProblemUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } // rs.resetStatistics(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |