From: <jen...@us...> - 2010-02-18 12:41:15
|
Revision: 2064 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2064&view=rev Author: jenslehmann Date: 2010-02-18 12:40:38 +0000 (Thu, 18 Feb 2010) Log Message: ----------- graphical tree display for CELOE algorithm in GUI (feature request #2952829) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java trunk/src/dl-learner/org/dllearner/gui/EBNodeTreeModel.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/gui/SearchTree.java trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/algorithms/SearchTreeNode.java trunk/src/dl-learner/org/dllearner/gui/SearchTreeNodeCmpWrapper.java Added: trunk/src/dl-learner/org/dllearner/algorithms/SearchTreeNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SearchTreeNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/SearchTreeNode.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -0,0 +1,45 @@ +/** + * Copyright (C) 2007-2010, 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.algorithms; + +import java.util.Collection; + +import org.dllearner.core.owl.Description; + +/** + * Interface for search tree nodes, which are used in various algorithms. + * + * @author Jens Lehmann + * + */ +public interface SearchTreeNode { + + /** + * Gets the OWL 2 class expression at this search tree node. + * @return The expression at this node. + */ + public Description getExpression(); + + /** + * The children of this node. + * @return The children of this node. + */ + public Collection<? extends SearchTreeNode> getChildren(); +} Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2010-02-18 11:16:14 UTC (rev 2063) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -21,6 +21,7 @@ import java.util.Comparator; +import org.dllearner.algorithms.SearchTreeNode; import org.dllearner.utilities.owl.ConceptComparator; /** Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2010-02-18 11:16:14 UTC (rev 2063) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -23,6 +23,7 @@ import java.util.LinkedList; import java.util.List; +import org.dllearner.algorithms.SearchTreeNode; import org.dllearner.core.owl.Description; /** @@ -40,7 +41,7 @@ * @author Jens Lehmann * */ -public class OENode { +public class OENode implements SearchTreeNode { private Description description; @@ -84,6 +85,10 @@ return description; } + public Description getExpression() { + return getDescription(); + } + /** * @return the accuracy */ Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java 2010-02-18 11:16:14 UTC (rev 2063) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -25,6 +25,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.algorithms.SearchTreeNode; import org.dllearner.core.configurators.ROLComponent2Configurator; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -40,7 +41,7 @@ * @author Jens Lehmann * */ -public class ExampleBasedNode { +public class ExampleBasedNode implements SearchTreeNode { // public static long exampleMemoryCounter = 0; @@ -268,6 +269,10 @@ return concept; } + public Description getExpression() { + return getConcept(); + } + public QualityEvaluationMethod getQualityEvaluationMethod() { return qualityEvaluationMethod; } Modified: trunk/src/dl-learner/org/dllearner/gui/EBNodeTreeModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/EBNodeTreeModel.java 2010-02-18 11:16:14 UTC (rev 2063) +++ trunk/src/dl-learner/org/dllearner/gui/EBNodeTreeModel.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -19,17 +19,20 @@ */ package org.dllearner.gui; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.SortedSet; import java.util.TreeMap; +import java.util.TreeSet; import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import org.dllearner.algorithms.SearchTreeNode; import org.dllearner.algorithms.refinement2.ExampleBasedNode; import org.dllearner.algorithms.refinement2.NodeComparatorStable; @@ -45,20 +48,26 @@ public class EBNodeTreeModel implements TreeModel { // root of the search tree - private ExampleBasedNode rootNode; + private SearchTreeNode rootNode; // a mapping from nodes to their children; // the main problem is that example based nodes use sets instead // of lists, so we need to convert these sets to lists and store // them here - private Map<ExampleBasedNode, List<ExampleBasedNode>> childrenMap = new TreeMap<ExampleBasedNode, List<ExampleBasedNode>>( - new NodeComparatorStable()); + private Map<SearchTreeNode, List<SearchTreeNode>> childrenMap; + // = new TreeMap<SearchTreeNode, List<SearchTreeNode>>( + // new NodeComparatorStable()); + private Comparator<SearchTreeNode> nodeComparator; + // listeners for this model private List<TreeModelListener> treeModelListeners = new LinkedList<TreeModelListener>(); - public EBNodeTreeModel(ExampleBasedNode rootNode) { + public EBNodeTreeModel(SearchTreeNode rootNode, Comparator<SearchTreeNode> comparator) { this.rootNode = rootNode; + this.nodeComparator = comparator; + childrenMap = new TreeMap<SearchTreeNode, List<SearchTreeNode>>(comparator); + // new NodeComparatorStable()); } public void addTreeModelListener(TreeModelListener l) { @@ -66,15 +75,15 @@ } public Object getChild(Object parent, int index) { - return getChildren((ExampleBasedNode) parent).get(index); + return getChildren((SearchTreeNode) parent).get(index); } public int getChildCount(Object parent) { - return ((ExampleBasedNode) parent).getChildren().size(); + return ((SearchTreeNode) parent).getChildren().size(); } public int getIndexOfChild(Object parent, Object child) { - return getChildren((ExampleBasedNode) parent).indexOf(child); + return getChildren((SearchTreeNode) parent).indexOf(child); } public Object getRoot() { @@ -102,15 +111,16 @@ } // convert the set of children to a list and store it in this model - private List<ExampleBasedNode> getChildren(ExampleBasedNode node) { + private List<SearchTreeNode> getChildren(SearchTreeNode node) { // System.out.println("asking for children of " + node); - List<ExampleBasedNode> children = childrenMap.get(node); + List<SearchTreeNode> children = childrenMap.get(node); // if the children have not been cached or the list is outdated // (node has more children now) we do an update if (children == null || children.size() != node.getChildren().size()) { - SortedSet<ExampleBasedNode> childrenSet = node.getChildren(); - children = new LinkedList<ExampleBasedNode>(childrenSet); + SortedSet<SearchTreeNode> childrenSet = new TreeSet<SearchTreeNode>(nodeComparator); + childrenSet.addAll(node.getChildren()); + children = new LinkedList<SearchTreeNode>(childrenSet); // we need to ensure that the children are sorted correctly // children = new LinkedList<ExampleBasedNode>(); Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2010-02-18 11:16:14 UTC (rev 2063) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -52,6 +52,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; +import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.refinement2.ROLComponent2; import org.dllearner.core.EvaluatedDescription; import org.dllearner.learningproblems.PosNegLPStandard; @@ -419,8 +420,9 @@ // System.out.println("TEST"); // enable tree button - if((config.getLearningAlgorithm() instanceof ROLComponent2) - && (config.getLearningProblem() instanceof PosNegLPStandard)) { + if(((config.getLearningAlgorithm() instanceof ROLComponent2) + && (config.getLearningProblem() instanceof PosNegLPStandard)) + || (config.getLearningAlgorithm() instanceof CELOE )) { treeButton.setEnabled(true); } } Modified: trunk/src/dl-learner/org/dllearner/gui/SearchTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/SearchTree.java 2010-02-18 11:16:14 UTC (rev 2063) +++ trunk/src/dl-learner/org/dllearner/gui/SearchTree.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -21,6 +21,7 @@ import javax.swing.JTree; +import org.dllearner.algorithms.celoe.OENode; import org.dllearner.algorithms.refinement2.ExampleBasedNode; /** @@ -37,6 +38,13 @@ private int nrOfPositiveExamples; private String baseURI; + // CELOE constructor + public SearchTree(EBNodeTreeModel model, String baseURI) { + super(model); + this.baseURI = baseURI; + } + + // OCEL constructor public SearchTree(EBNodeTreeModel model, int nrOfPositiveExamples, int nrOfNegativeExamples, String baseURI) { super(model); this.nrOfPositiveExamples = nrOfPositiveExamples; @@ -52,8 +60,11 @@ boolean leaf, int row, boolean hasFocus) { - ExampleBasedNode node = (ExampleBasedNode) value; - return node.getShortDescriptionHTML(nrOfPositiveExamples, nrOfNegativeExamples, baseURI); -// return node.toString(); + if(value instanceof OENode) { + return ((OENode)value).getShortDescription(baseURI); + } else { + ExampleBasedNode node = (ExampleBasedNode) value; + return node.getShortDescriptionHTML(nrOfPositiveExamples, nrOfNegativeExamples, baseURI); + } } } Added: trunk/src/dl-learner/org/dllearner/gui/SearchTreeNodeCmpWrapper.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/SearchTreeNodeCmpWrapper.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/SearchTreeNodeCmpWrapper.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2007-2010, 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.gui; + +import java.util.Comparator; + +import org.dllearner.algorithms.SearchTreeNode; + +/** + * Takes a comparator for a specific search tree node type and generalises + * it to a comparator for all search tree nodes. + * + * @author Jens Lehmann + * + */ +public class SearchTreeNodeCmpWrapper implements Comparator<SearchTreeNode> { + + private Comparator<SearchTreeNode> cmp; + + @SuppressWarnings("unchecked") + public SearchTreeNodeCmpWrapper(Comparator<? extends SearchTreeNode> cmp) { + this.cmp = (Comparator<SearchTreeNode>) cmp; + } + + @Override + public int compare(SearchTreeNode o1, SearchTreeNode o2) { + return cmp.compare(o1, o2); + } + +} Modified: trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java 2010-02-18 11:16:14 UTC (rev 2063) +++ trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java 2010-02-18 12:40:38 UTC (rev 2064) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2008, Jens Lehmann + * Copyright (C) 2007-2010, Jens Lehmann * * This file is part of DL-Learner. * @@ -19,6 +19,7 @@ */ package org.dllearner.gui; +import java.util.Comparator; import java.util.Set; import javax.swing.JFrame; @@ -28,14 +29,18 @@ import javax.swing.event.TreeWillExpandListener; import javax.swing.tree.ExpandVetoException; -import org.dllearner.algorithms.refinement2.ExampleBasedNode; +import org.dllearner.algorithms.SearchTreeNode; +import org.dllearner.algorithms.celoe.CELOE; +import org.dllearner.algorithms.celoe.OEHeuristicRuntime; +import org.dllearner.algorithms.refinement2.NodeComparatorStable; import org.dllearner.algorithms.refinement2.ROLComponent2; import org.dllearner.learningproblems.PosNegLPStandard; /** - * TreeWindow + * Window, which displays the search tree. * * @author Tilo Hielscher + * @author Jens Lehmann */ public class TreeWindow extends JFrame implements TreeWillExpandListener { @@ -43,16 +48,18 @@ @SuppressWarnings("unused") private Config config; + private EBNodeTreeModel ebNodeModel; - private ExampleBasedNode rootNode; + + private SearchTreeNode rootNode; + private JTree tree; - - @SuppressWarnings("unchecked") + public TreeWindow(Config config) { this.config = config; this.setTitle("DL-Learner Tree"); this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); -// this.setLocationByPlatform(true); + // this.setLocationByPlatform(true); this.setSize(800, 600); // set icon @@ -61,49 +68,59 @@ this.getClass().getResource("icon.gif"))); // tree model + Comparator<SearchTreeNode> cmp = null; if (config.getLearningAlgorithm() instanceof ROLComponent2) { - ROLComponent2 ebrol = (ROLComponent2) config - .getLearningAlgorithm(); + ROLComponent2 ebrol = (ROLComponent2) config.getLearningAlgorithm(); this.rootNode = ebrol.getStartNode(); + cmp = new SearchTreeNodeCmpWrapper(new NodeComparatorStable()); + } else { + CELOE celoe = (CELOE) config.getLearningAlgorithm(); + this.rootNode = celoe.getSearchTreeRoot(); + cmp = new SearchTreeNodeCmpWrapper(new OEHeuristicRuntime()); + } + this.ebNodeModel = new EBNodeTreeModel(rootNode, cmp); -// System.out.println("childs1: " + rootNode.getChildren()); + // childrens to treeModel + // Object first = ebNodeModel.getChild(rootNode, 0); + // System.out.println("getIndexOfChild: " + + // ebNodeModel.getIndexOfChild(rootNode, first)); - this.ebNodeModel = new EBNodeTreeModel(rootNode); + // System.out.println("childs2: " + + // ebNodeModel.getChildren((ExampleBasedNode) first)); - // childrens to treeModel -// Object first = ebNodeModel.getChild(rootNode, 0); -// System.out.println("getIndexOfChild: " + ebNodeModel.getIndexOfChild(rootNode, first)); - - // System.out.println("childs2: " + - // ebNodeModel.getChildren((ExampleBasedNode) first)); - + String baseURI = config.getReasoner().getBaseURI(); + if (config.getLearningAlgorithm() instanceof ROLComponent2) { // collect some helper values for display and accuracy calculations PosNegLPStandard lp = (PosNegLPStandard) config.getLearningProblem(); Set<String> posExamples = lp.getConfigurator().getPositiveExamples(); Set<String> negExamples = lp.getConfigurator().getNegativeExamples(); - String baseURI = config.getReasoner().getBaseURI(); int nrOfPositiveExamples = posExamples.size(); int nrOfNegativeExamples = negExamples.size(); - + tree = new SearchTree(ebNodeModel, nrOfPositiveExamples, nrOfNegativeExamples, baseURI); - // we need to call this, otherwise the width of the elements below the root node - // corresponds to that of the toString() method on ExampleBasedNode, although we - // use a different method to create a string representation of a node - tree.updateUI(); -// ebNodeModel.nodeChanged(rootNode); -// tree.addTreeWillExpandListener(this); - this.add(new JScrollPane(tree)); + } else { + tree = new SearchTree(ebNodeModel, baseURI); } + + // we need to call this, otherwise the width of the elements below the + // root node + // corresponds to that of the toString() method on ExampleBasedNode, + // although we + // use a different method to create a string representation of a node + tree.updateUI(); + // ebNodeModel.nodeChanged(rootNode); + // tree.addTreeWillExpandListener(this); + this.add(new JScrollPane(tree)); - // } -// this.repaint(); setVisible(true); } /* * (non-Javadoc) * - * @see javax.swing.event.TreeWillExpandListener#treeWillCollapse(javax.swing.event.TreeExpansionEvent) + * @see + * javax.swing.event.TreeWillExpandListener#treeWillCollapse(javax.swing + * .event.TreeExpansionEvent) */ // @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { @@ -112,7 +129,9 @@ /* * (non-Javadoc) * - * @see javax.swing.event.TreeWillExpandListener#treeWillExpand(javax.swing.event.TreeExpansionEvent) + * @see + * javax.swing.event.TreeWillExpandListener#treeWillExpand(javax.swing.event + * .TreeExpansionEvent) */ // @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |