From: <jen...@us...> - 2008-07-31 11:46:03
|
Revision: 1033 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1033&view=rev Author: jenslehmann Date: 2008-07-31 11:45:59 +0000 (Thu, 31 Jul 2008) Log Message: ----------- EL description trees continued Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.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 10:15:31 UTC (rev 1032) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 11:45:59 UTC (rev 1033) @@ -34,7 +34,10 @@ * of named classes and the edges are labelled with a property. * * In the documentation below "this node" refers to the root node - * of this EL description (sub-)tree. + * of this EL description (sub-)tree. One tree cannot be reused, + * i.e. used as subtree in several description trees, as some of + * the associated variables (level, simulation) depend on the overall + * tree. * * @author Jens Lehmann * @@ -45,16 +48,23 @@ private List<Edge> edges; + private int level; + // parent node in the tree; // null indicates that this node is a root node private ELDescriptionTree parent = null; + // to simplify equivalence checks and minimisation, we + // attach a simulation relation to the description tree + private Simulation simulation; + /** * Constructs an empty EL description tree with the empty set * as root label and an empty set of outgoing edges. */ public ELDescriptionTree() { this(new TreeSet<NamedClass>(), new LinkedList<Edge>()); + simulation = new Simulation(); } /** @@ -100,11 +110,13 @@ /** * Traverses the tree until the root node and counts how * many edges are traversed. If this node does not have a parent, - * zero is returned. + * zero is returned. This method is used for checking the integrity + * of the tree in unit tests. Use {@link #getLevel()} to get the + * level of the tree. * @return The level of this node (or more specifically the root * node of this subtree) within the overall EL description tree. */ - public int getLevel() { + public int computeLevel() { ELDescriptionTree root = this; int level = 0; while(root.parent != null) { @@ -127,5 +139,12 @@ public List<Edge> getEdges() { return edges; } + + /** + * @return The level of the (root node of) this subtree in the overall tree. + */ + public int getLevel() { + return level; + } } Added: trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java 2008-07-31 11:45:59 UTC (rev 1033) @@ -0,0 +1,109 @@ +/** + * 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.algorithms.el; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Represents a simulation relation between EL description trees. + * + * @author Jens Lehmann + * + */ +public class Simulation { + + // the simulation relation S itself + private List<TreeTuple> relation; + + // { w | (v,w) \in S } for all w + private Map<ELDescriptionTree,List<ELDescriptionTree>> in; + + // { v | (v,w) \in S } for all v + private Map<ELDescriptionTree,List<ELDescriptionTree>> out; + + public Simulation() { + relation = new LinkedList<TreeTuple>(); + in = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>(); + out = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>(); + } + + /** + * Adds a tuple to the simulation. + * + * @param tuple The new tuple. + * @see java.util.List#add(java.lang.Object) + */ + public void addTuple(TreeTuple tuple) { + relation.add(tuple); + + if(in.containsKey(tuple.getTree2())) { + in.get(tuple.getTree2()).add(tuple.getTree1()); + } else { + List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>(); + list.add(tuple.getTree1()); + in.put(tuple.getTree2(), list); + } + + if(out.containsKey(tuple.getTree1())) { + out.get(tuple.getTree1()).add(tuple.getTree2()); + } else { + List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>(); + list.add(tuple.getTree2()); + out.put(tuple.getTree1(), list); + } + } + + /** + * Removes a tuple from the simulation. + * + * @param tuple The new tuple. + * @see java.util.List#add(java.lang.Object) + */ + public void removeTuple(TreeTuple tuple) { + relation.remove(tuple); + + in.get(tuple.getTree2()).remove(tuple.getTree1()); + if(in.get(tuple.getTree2()).isEmpty()) + in.remove(tuple.getTree2()); + + out.get(tuple.getTree1()).remove(tuple.getTree2()); + if(out.get(tuple.getTree1()).isEmpty()) + out.remove(tuple.getTree1()); + } + + /** + * Gets the complete simulation relation. + * @return the relation + */ + public List<TreeTuple> getRelation() { + return relation; + } + + public List<ELDescriptionTree> in(ELDescriptionTree tree) { + return in.get(tree); + } + + public List<ELDescriptionTree> out(ELDescriptionTree tree) { + return out.get(tree); + } +} Added: trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java 2008-07-31 11:45:59 UTC (rev 1033) @@ -0,0 +1,55 @@ +/** + * 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.algorithms.el; + +/** + * A tuple of two EL description trees. + * + * @author Jens Lehmann + * + */ +public class TreeTuple { + + private ELDescriptionTree tree1; + + private ELDescriptionTree tree2; + + public TreeTuple(ELDescriptionTree tree1, ELDescriptionTree tree2) { + this.tree1 = tree1; + this.tree2 = tree2; + } + + /** + * Gets first tree. + * @return - first tree + */ + public ELDescriptionTree getTree1() { + return tree1; + } + + /** + * Gets second tree. + * @return - second tree + */ + public ELDescriptionTree getTree2() { + return tree2; + } + +} Added: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-07-31 11:45:59 UTC (rev 1033) @@ -0,0 +1,49 @@ +/** + * 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.test.junit; + +import static org.junit.Assert.*; + +import org.dllearner.algorithms.el.ELDescriptionTree; +import org.dllearner.algorithms.el.Simulation; +import org.dllearner.algorithms.el.TreeTuple; +import org.junit.Test; + +/** + * Tests related to EL description tree including operations on + * them, simulations, equivalence checks, minimisation etc. + * + * @author Jens Lehmann + * + */ +public final class ELDescriptionTreeTests { + + @Test + public void simulationTest() { + Simulation s = new Simulation(); + ELDescriptionTree t1 = new ELDescriptionTree(); + ELDescriptionTree t2 = new ELDescriptionTree(); + TreeTuple tuple1 = new TreeTuple(t1,t2); + s.addTuple(tuple1); + assertTrue(s.in(t2).size() == 1); + assertTrue(s.out(t2).size() == 0); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |