From: <jen...@us...> - 2009-04-20 10:21:14
|
Revision: 1716 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1716&view=rev Author: jenslehmann Date: 2009-04-20 10:21:12 +0000 (Mon, 20 Apr 2009) Log Message: ----------- - added possibility to query for algorithms supporting a given learning problem in component manager - GUI: when selecting class learning problem, the option classToDescribe is now mandatory - GUI: made sure that only appropriate learning algorithms wrt. a given learning problem can be selected - GUI: files ending with nt or rdf are now selectable by default Modified Paths: -------------- trunk/build.xml trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/ExampleFileChooser.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelURL.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/datastructures/Maps.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2009-04-19 16:38:14 UTC (rev 1715) +++ trunk/build.xml 2009-04-20 10:21:12 UTC (rev 1716) @@ -4,7 +4,7 @@ <!-- directory settings --> <property name="lib_dir" value="lib" /> <property name="source_dir" value="src/dl-learner" /> - <property name="protege_dir" value="C:\Program Files\Protege_4.0_beta\plugins" /> + <property name="protege_dir" value="/home/jl/programme/Protege_4.0_beta/plugins" /> <property name="class_dir" value="classes" /> <property name="php_client_dir" value="src/php-client" /> Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2009-04-19 16:38:14 UTC (rev 1715) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2009-04-20 10:21:12 UTC (rev 1716) @@ -40,6 +40,7 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import java.util.Map.Entry; import org.apache.log4j.Logger; import org.dllearner.cli.ConfMapper; @@ -48,6 +49,7 @@ import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.utilities.Files; +import org.dllearner.utilities.datastructures.Maps; /** * Central manager class for DL-Learner. There are currently four types of @@ -85,7 +87,8 @@ private static Map<Class<? extends Component>, List<ConfigOption<?>>> componentOptions; private static Map<Class<? extends Component>, Map<String, ConfigOption<?>>> componentOptionsByName; private static Map<Class<? extends LearningAlgorithm>, Collection<Class<? extends LearningProblem>>> algorithmProblemsMapping; - + private static Map<Class<? extends LearningProblem>, Collection<Class<? extends LearningAlgorithm>>> problemAlgorithmsMapping; + private ConfMapper confMapper = new ConfMapper(); // list of default values of config options @@ -116,7 +119,7 @@ learningProblems = new TreeSet<Class<? extends LearningProblem>>(classComparator); learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithm>>(classComparator); algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithm>, Collection<Class<? extends LearningProblem>>>( - classComparator); + classComparator); // create classes from strings for (String componentString : componentsString) { @@ -143,13 +146,14 @@ e.printStackTrace(); } } + problemAlgorithmsMapping = Maps.revertCollectionMap(algorithmProblemsMapping); componentNames = new HashMap<Class<? extends Component>, String>(); // read in all configuration options componentOptions = new HashMap<Class<? extends Component>, List<ConfigOption<?>>>(); componentOptionsByName = new HashMap<Class<? extends Component>, Map<String, ConfigOption<?>>>(); // configOptionDefaults = new HashMap<ConfigOption<?>,Object>(); - + for (Class<? extends Component> component : components) { String name = (String) invokeStaticMethod(component, "getName"); @@ -169,8 +173,6 @@ } - // System.out.println(components); - // System.out.println(learningProblems); } /** @@ -683,6 +685,23 @@ } /** + * Returns the set of learning algorithms, which support the given learning problem type. + * @param learningProblem A learning problem type. + * @return The set of learning algorithms applicable for this learning problem. + */ + public List<Class<? extends LearningAlgorithm>> getApplicableLearningAlgorithms(Class<? extends LearningProblem> learningProblem) { + List<Class<? extends LearningAlgorithm>> algorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); + for(Entry<Class<? extends LearningProblem>,Collection<Class<? extends LearningAlgorithm>>> entry : problemAlgorithmsMapping.entrySet()) { + Class<? extends LearningProblem> prob = entry.getKey(); + if(prob.isAssignableFrom(learningProblem)) { + algorithms.addAll(entry.getValue()); + } + } +// System.out.println(learningProblem + ": " + algorithms); + return algorithms; + } + + /** * Returns a list of all available learning algorithms in this instance * of <code>ComponentManager</code>. * @return the components A list of learning algorithm classes available in this Modified: trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java 2009-04-19 16:38:14 UTC (rev 1715) +++ trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java 2009-04-20 10:21:12 UTC (rev 1716) @@ -29,12 +29,15 @@ import javax.swing.JComboBox; import javax.swing.JPanel; +import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.core.Component; 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.learningproblems.ClassLearningProblem; +import org.dllearner.learningproblems.PosOnlyLP; /** * Class displaying a component (and its options). @@ -107,7 +110,8 @@ } else if (panelClass == LearningProblem.class) { selectableComponents.addAll(config.getComponentManager().getLearningProblems()); } else if (panelClass == LearningAlgorithm.class) { - selectableComponents.addAll(config.getComponentManager().getLearningAlgorithms()); +// selectableComponents.addAll(config.getComponentManager().getLearningAlgorithms()); + selectableComponents.addAll(config.getComponentManager().getApplicableLearningAlgorithms(config.getLearningProblem().getClass())); } // set default component class (move it to first position) @@ -151,6 +155,16 @@ // change component and update option panel Class<? extends Component> c = selectableComponents.get(comboBox.getSelectedIndex()); currentComponent = changeInstance(c); + // we may have to change the learning algorithm depending on the learning problem + if(c.equals(ClassLearningProblem.class) || c.equals(PosOnlyLP.class)) { + try { + config.changeLearningAlgorithm(CELOE.class); + } catch (LearningProblemUnsupportedException e1) { + // cannot happend since CELOE supports class learning problem + e1.printStackTrace(); + } + } + updateOptionPanel(); // if the component does not have mandatory values, we can // enable the following tabs @@ -201,6 +215,21 @@ */ public void panelActivated() { // hook method, which does nothing yet + if(panelClass.equals(LearningAlgorithm.class)) { + // update selectable components + selectableComponents.clear(); + selectableComponents.addAll(config.getComponentManager().getApplicableLearningAlgorithms(config.getLearningProblem().getClass())); + // clear combo box and add selectable items to it + comboBox.removeActionListener(this); + comboBox.removeAllItems(); + // recreate combo box + for (int i = 0; i < selectableComponents.size(); i++) { + comboBox.addItem(config.getComponentManager().getComponentName( + selectableComponents.get(i))); + } + comboBox.addActionListener(this); + update(); + } } // creates an instance of the specified component class Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2009-04-19 16:38:14 UTC (rev 1715) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2009-04-20 10:21:12 UTC (rev 1716) @@ -41,7 +41,9 @@ import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.parser.ParseException; /** @@ -548,6 +550,16 @@ .size() == 0) { return false; } + } else if (component instanceof PosOnlyLP) { + if (cm.getConfigOptionValue(component, "positiveExamples") == null + || ((Set<String>) cm.getConfigOptionValue(component, "positiveExamples")) + .size() == 0) { + return false; + } + } else if (component instanceof ClassLearningProblem) { + if (cm.getConfigOptionValue(component, "classToDescribe") == null) { + return false; + } } else if (component instanceof SparqlKnowledgeSource) { if (cm.getConfigOptionValue(component, "instances") == null || ((Set<String>) cm.getConfigOptionValue(component, "instances")).size() == 0) { Modified: trunk/src/dl-learner/org/dllearner/gui/ExampleFileChooser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ExampleFileChooser.java 2009-04-19 16:38:14 UTC (rev 1715) +++ trunk/src/dl-learner/org/dllearner/gui/ExampleFileChooser.java 2009-04-20 10:21:12 UTC (rev 1716) @@ -34,20 +34,36 @@ private static final long serialVersionUID = 1566010391199697892L; - public ExampleFileChooser(final String fileEnding) { + private final String description; + + // public ExampleFileChooser(final String fileEnding) { + public ExampleFileChooser(final String ... fileEndings) { super(new File("examples/")); + String display = ""; + for(String fileEnding : fileEndings) { + display += "*."+ fileEnding + " "; + } + display += "files"; + description = display; + FileFilter filter = new FileFilter() { @Override public boolean accept(File f) { - if (f.isDirectory()) + if (f.isDirectory()) { return true; - return f.getName().toLowerCase().endsWith("." + fileEnding); + } + for(String fileEnding : fileEndings) { + if(f.getName().toLowerCase().endsWith("." + fileEnding)) { + return true; + } + } + return false; } @Override public String getDescription() { - return fileEnding + " files"; // name for filter + return description; } }; Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelURL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelURL.java 2009-04-19 16:38:14 UTC (rev 1715) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelURL.java 2009-04-20 10:21:12 UTC (rev 1716) @@ -70,7 +70,7 @@ if (e.getSource() == chooseLocalButton) { JFileChooser fc; if (component instanceof OWLFile) { - fc = new ExampleFileChooser("owl"); + fc = new ExampleFileChooser("owl","rdf","nt"); } else { fc = new ExampleFileChooser("kb"); } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-04-19 16:38:14 UTC (rev 1715) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-04-20 10:21:12 UTC (rev 1716) @@ -76,7 +76,7 @@ Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringConfigOption("classToDescribe", "class of which a description should be learned", null, true, false)); StringConfigOption type = new StringConfigOption("type", "Whether to learn an equivalence class or super class axiom or domain/range of a property.","equivalence"); - type.setAllowedValues(new String[] {"equivalence", "superClass", "domain", "range"}); + type.setAllowedValues(new String[] {"equivalence", "superClass"}); // , "domain", "range"}); options.add(type); return options; } Added: trunk/src/dl-learner/org/dllearner/utilities/datastructures/Maps.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/Maps.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/Maps.java 2009-04-20 10:21:12 UTC (rev 1716) @@ -0,0 +1,78 @@ +/** + * 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.datastructures; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +/** + * @author Jens Lehmann + * + */ +public class Maps { + + /** + * Reverts a map, i.e. if the map contains an entry x => y, then the + * returned map contains an entry y => x. (The minimal map with this + * property is returned.) + * + * @param <X> + * Type of map keys. + * @param <Y> + * Type of map values + * @param map + * The map to invert. + * @return A reverted map. + */ + public static <X, Y> Map<Y, Collection<X>> revert(Map<X, Y> map) { + Map<Y, Collection<X>> result = new HashMap<Y, Collection<X>>(); + + for (Map.Entry<X, Y> entry : map.entrySet()) { + X x = entry.getKey(); + Y y = entry.getValue(); + Collection<X> s = result.get(y); + if (s == null) { + result.put(y, s = new HashSet<X>()); + } + s.add(x); + } + return result; + } + + public static <X, Y> Map<Y, Collection<X>> revertCollectionMap(Map<X, Collection<Y>> map) { + Map<Y, Collection<X>> result = new HashMap<Y, Collection<X>>(); + + for (Map.Entry<X, Collection<Y>> entry : map.entrySet()) { + X x = entry.getKey(); + Collection<Y> y = entry.getValue(); + for (Y value : y) { + Collection<X> s = result.get(value); + if (s == null) { + result.put(value, s = new HashSet<X>()); + } + s.add(x); + } + } + return result; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |