From: <jen...@us...> - 2008-08-08 14:02:50
|
Revision: 1059 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1059&view=rev Author: jenslehmann Date: 2008-08-08 14:02:47 +0000 (Fri, 08 Aug 2008) Log Message: ----------- EL downward refinement operator continued Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-08-08 11:38:27 UTC (rev 1058) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-08-08 14:02:47 UTC (rev 1059) @@ -46,6 +46,13 @@ } /** + * @param label the label to set + */ + public void setLabel(ObjectProperty label) { + this.label = label; + } + + /** * @return The label of this edge. */ public ObjectProperty getLabel() { Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-08 11:38:27 UTC (rev 1058) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-08 14:02:47 UTC (rev 1059) @@ -177,14 +177,35 @@ } /** - * Each node is assigned a number within the tree. - * TODO add explanation how this is done + * Gets a list describing the position of this node within the + * tree. If the list is e.g. [2,5,1], then the node can be reached + * by picking the second child of the root node, then picking the + * 5th child of this node and finally selecting the first child of + * the previous node. * @return The position number of this node within the tree as described above. */ - public int getCurrentPositionNumber() { - return 0; + public int[] getCurrentPosition() { + int[] position = new int[level]; + ELDescriptionNode root = this; + while(root.parent != null) { + position[root.level-1] = getChildNumber(); + root = parent; + } + return position; } + // returns the child number of this node, i.e. whether it is + // the first, second, third etc. child + private int getChildNumber() { + int count = 0; + for(ELDescriptionEdge edge : parent.edges) { + if(edge.getTree() == this) { + return count; + } + } + throw new RuntimeException("Inconsistent tree. Child tree not reachable from parent."); + } + /** * Replaces an entry in the node label. * @param oldClass Class to remove from label. @@ -196,7 +217,16 @@ } /** - * Gets the label of this node. Do not modify the returned object. + * Adds an entry to the node label. + * @param newClass Class to add to label. + */ + public void extendLabel(NamedClass newClass) { + label.add(newClass); + } + + /** + * Gets the label of this node. Do not modify the returned object, + * but use the provided methods instead! * @return The label of root node of this subtree. */ public SortedSet<NamedClass> getLabel() { @@ -204,14 +234,16 @@ } /** - * @return The outgoing edges of this subtree. Do not modify the - * returned object. + * Gets the edges of this node. Do not modify the + * returned object, but use the provided methods instead! + * @return The outgoing edges of this subtree. */ public List<ELDescriptionEdge> getEdges() { return edges; } /** + * Gets the level (distance from root) of this node. * @return The level of the (root node of) this subtree in the overall tree. */ public int getLevel() { Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-08 11:38:27 UTC (rev 1058) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-08 14:02:47 UTC (rev 1059) @@ -113,36 +113,20 @@ } /** - * Selects a sub tree. - * @param positionNumber A position in the tree. Positions are iteratively given to nodes - * by leftmost depth-first search. This allows efficient selection of subtrees. - * (TODO: Implementation does not work if any node has more than two children - * like conjunction and disjunction.) - * @return The selected subtree. + * Gets the node at the given position. The list is processed + * as follows: Starting with the root node, the first element i of + * list is read and the i-th child of root node is selected. This + * node is set as current node and the next element j of the list + * is read and the j-th child of the i-th child of the root node + * selected etc. + * @return The node at the specified position. */ - public Description getNode(int positionNumber) { -// if (children.size() == 0) -// return this; -// else if (children.size() == 1) { -// if (positionNumber == 0) -// return this; -// else -// return children.get(0).getSubtree(positionNumber - 1); -// } -// // arity 2 -// else { -// // we have found it -// if (positionNumber == 0) -// return this; -// // left subtree -// int leftTreeNodes = children.get(0).getNumberOfNodes(); -// if (positionNumber <= leftTreeNodes) -// return children.get(0).getSubtree(positionNumber - 1); -// // right subtree -// else -// return children.get(1).getSubtree(positionNumber - leftTreeNodes - 1); -// } - return null; + public ELDescriptionNode getNode(int[] position) { + ELDescriptionNode currentNode = rootNode; + for(int i=0; i<position.length; i++) { + currentNode = currentNode.getEdges().get(position[i]).getTree(); + } + return currentNode; } @Override Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-08 11:38:27 UTC (rev 1058) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-08 14:02:47 UTC (rev 1059) @@ -22,8 +22,11 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.SortedSet; import java.util.TreeMap; +import java.util.TreeSet; +import org.dllearner.algorithms.el.ELDescriptionEdge; import org.dllearner.algorithms.el.ELDescriptionNode; import org.dllearner.algorithms.el.ELDescriptionTree; import org.dllearner.core.ReasoningService; @@ -118,11 +121,21 @@ } private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index) { - Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); + // the set of all refinements, which we will return + Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); + // the position of the node within the tree (needed for getting + // the corresponding node in a cloned tree) + int[] position = node.getCurrentPosition(); + // option 1: label extension Set<NamedClass> candidates = utility.getClassCandidates(index, node.getLabel()); for(NamedClass nc : candidates) { - + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + ELDescriptionNode clonedNode = clonedTree.getNode(position); + // extend label + clonedNode.extendLabel(nc); + refinements.add(clonedTree); } // option 2: label refinement // loop through all classes in label @@ -130,22 +143,50 @@ // find all more special classes for the given label for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) { if(moreSpecial instanceof NamedClass) { - // create refinements by replacing class - ELDescriptionTree tmp = tree.clone(); - // TODO we need to find a way to get this node in - // the cloned tree -// tmp.replaceInLabel(nc, (NamedClass) moreSpecial); - refinements.add(tmp); + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + ELDescriptionNode clonedNode = clonedTree.getNode(position); + // create refinements by replacing class + clonedNode.replaceInLabel(nc, (NamedClass) moreSpecial); + refinements.add(clonedTree); } } } // option 3: new edge + // TODO incomplete, it is still open how to construct this refinement !! + SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index); + Set<ObjectProperty> mgr = utility.computeMgr(appOPs); + for(ObjectProperty op : mgr) { + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + ELDescriptionNode clonedNode = clonedTree.getNode(position); + // add a new node and edge + ELDescriptionNode newNode = new ELDescriptionNode(clonedNode, op, new TreeSet<NamedClass>()); + refinements.add(clonedTree); + } // option 4: edge refinement + for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) { + ELDescriptionEdge edge = node.getEdges().get(edgeNumber); + ObjectProperty op = edge.getLabel(); + // find all more special properties + for(ObjectProperty op2 : rs.getMoreSpecialRoles(op)) { + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + // find cloned edge and replace its label + ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber); + clonedEdge.setLabel(op2); + } + } // option 5: child refinement - + for(ELDescriptionEdge edge : node.getEdges()) { + // recursive call on child node and property range as index + Description range = rs.getRange(edge.getLabel()); + refinements.addAll(refine(tree, edge.getTree(), range)); + } + return refinements; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |