From: <jen...@us...> - 2008-12-08 13:06:51
|
Revision: 1545 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1545&view=rev Author: jenslehmann Date: 2008-12-08 13:06:44 +0000 (Mon, 08 Dec 2008) Log Message: ----------- continued EL simulation updates (now all 4 unit tests pass) 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/core/owl/ClassHierarchy.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java trunk/src/dl-learner/org/dllearner/core/owl/ObjectProperty.java trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -66,4 +66,9 @@ return tree; } + @Override + public String toString() { + return "--" + label + "--> " + tree.toDescriptionString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -174,7 +174,7 @@ // } // } - System.out.println(update); +// System.out.println(update); // apply updates recursively top-down tree.updateSimulation(update); @@ -335,13 +335,42 @@ // compute the nodes, which need to be updated Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>(); + Set<ELDescriptionNode> tmp = tree.getNodesOnLevel(level); + for(ELDescriptionNode w : tmp) { + if(w != this) { + // SC1(v,w) can only change from false to true + if(!inSC1.contains(w) && tree.checkSC1(this, w)) { + tree.extendSimulationSC1(this, w); + if(inSC2.contains(w)) { + tree.extendSimulationSC12(this, w); + } + update.add(w.getParent()); + } + // SC1(w,v) can only change from true to false + if(outSC1.contains(w) && !tree.checkSC1(w, this)) { + tree.shrinkSimulationSC1(w, this); + if(outSC2.contains(w)) { + tree.shrinkSimulationSC12(w, this); + } + if(!update.contains(w.getParent())) { + update.add(w.getParent()); + } + } + } + } + if(parent != null) { + update.add(parent); + } + + /* // loop over all nodes on the same level, which are not in the in set Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level)); tmp.removeAll(in); for(ELDescriptionNode w : tmp) { if(w != this) { - // we only need to recompute SC2 + // we only need to recompute SC1 if(inSC1.contains(w) && tree.checkSC2(this, w)) { + System.out.println("satisfied"); tree.extendSimulation(this, w); update.add(w.parent); } @@ -361,6 +390,7 @@ } } } + */ // apply updates recursively top-down tree.updateSimulation(update); @@ -371,7 +401,9 @@ // compute the nodes, which need to be updated Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>(); + update.add(this); + /* // loop over all nodes on the same level, which are not in the in set Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level)); tmp.removeAll(in); @@ -394,7 +426,10 @@ } } } + */ +// update.add(this.parent); + // apply updates recursively top-down tree.updateSimulation(update); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -237,6 +237,42 @@ Set<ELDescriptionNode> sameLevel = levelNodeMapping.get(v.getLevel()); for(ELDescriptionNode w : sameLevel) { if(v != w) { + +// System.out.println(v); +// System.out.println(w); + + // we update if SC2 did not hold but does now + if(!v.inSC2.contains(w) && checkSC2(v,w)) { +// System.out.println("extend sim. after update"); + + extendSimulationSC2(v,w); + if(v.inSC1.contains(w)) { + extendSimulationSC12(v,w); + } + if(!list.contains(v.getParent())) { + list.add(v.getParent()); + } + if(!list.contains(w.getParent())) { + list.add(w.getParent()); + } + } + + // similar case, but now possibly shrinking the simulation + if(w.inSC2.contains(v) && !checkSC2(w,v)) { +// System.out.println("shrink sim. after update"); + + shrinkSimulationSC2(w,v); + if(w.inSC1.contains(v)) { + shrinkSimulationSC12(w,v); + } + if(!list.contains(v.getParent())) { + list.add(v.getParent()); + } + if(!list.contains(w.getParent())) { + list.add(w.getParent()); + } + } + /* if(!v.out.contains(w) ) { System.out.println("test"); if(checkSC2(v,w) && v.outSC1.contains(w)) { @@ -257,6 +293,7 @@ shrinkSimulationSC2(w,v); } } + */ } } } @@ -297,9 +334,10 @@ List<ELDescriptionEdge> edges1 = node1.getEdges(); List<ELDescriptionEdge> edges2 = node2.getEdges(); - for(ELDescriptionEdge edge : edges1) { - // try to find an edge satisfying SC2 in the set - if(!checkSC2Edge(edge, edges2)) { + for(ELDescriptionEdge superEdge : edges2) { + // try to find an edge satisfying SC2 in the set, + // i.e. detect whether superEdge is indeed more general + if(!checkSC2Edge(superEdge, edges1)) { return false; } } @@ -308,16 +346,16 @@ } // check whether edges contains an element satisfying SC2 - private boolean checkSC2Edge(ELDescriptionEdge edge, List<ELDescriptionEdge> edges) { - ObjectProperty op1 = edge.getLabel(); - ELDescriptionNode node1 = edge.getTree(); + private boolean checkSC2Edge(ELDescriptionEdge superEdge, List<ELDescriptionEdge> edges) { + ObjectProperty superOP = superEdge.getLabel(); + ELDescriptionNode node1 = superEdge.getTree(); - for(ELDescriptionEdge edge2 : edges) { - ObjectProperty op2 = edge2.getLabel(); + for(ELDescriptionEdge edge : edges) { + ObjectProperty op = edge.getLabel(); // we first check the condition on the properties - if(roleHierarchy.isSubpropertyOf(op1, op2)) { + if(roleHierarchy.isSubpropertyOf(op, superOP)) { // check condition on simulations of referred nodes - ELDescriptionNode node2 = edge2.getTree(); + ELDescriptionNode node2 = edge.getTree(); if(node1.in.contains(node2) || node2.in.contains(node1)) { // we found a node satisfying the condition, so we can return return true; @@ -371,10 +409,10 @@ } public void shrinkSimulationSC2(ELDescriptionNode node1, ELDescriptionNode node2) { - System.out.println(node2.outSC2); +// System.out.println(node2.outSC2); node1.inSC2.remove(node2); node2.outSC2.remove(node1); - System.out.println(node2.outSC2); +// System.out.println(node2.outSC2); } public void shrinkSimulationSC12(ELDescriptionNode node1, ELDescriptionNode node2) { Modified: trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -147,6 +147,7 @@ return true; } else { for (Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) { + // search the upper classes of the subclass if (moreGeneralClass instanceof NamedClass) { if (isSubclassOf((NamedClass) moreGeneralClass, superClass)) { Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -69,4 +69,22 @@ public int compareTo(DatatypeProperty o) { return name.compareTo(o.name); } + + @Override + public boolean equals(Object nc) { + // standard equals code - always return true for object identity and + // false if classes differ + if(nc == this) { + return true; + } else if(getClass() != nc.getClass()) { + return false; + } + // compare on URIs + return ((DatatypeProperty)nc).name.equals(name); + } + + @Override + public int hashCode() { + return name.hashCode(); + } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -32,7 +32,7 @@ */ public class NamedClass extends Description implements Entity, NamedKBElement, Comparable<NamedClass> { - String name; + private String name; public NamedClass(String name) { this.name = name; @@ -82,4 +82,22 @@ public int compareTo(NamedClass o) { return name.compareTo(o.name); } + + @Override + public boolean equals(Object nc) { + // standard equals code - always return true for object identity and + // false if classes differ + if(nc == this) { + return true; + } else if(getClass() != nc.getClass()) { + return false; + } + // compare on URIs + return ((NamedClass)nc).name.equals(name); + } + + @Override + public int hashCode() { + return name.hashCode(); + } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectProperty.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ObjectProperty.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectProperty.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -60,4 +60,22 @@ public int compareTo(ObjectProperty o) { return name.compareTo(o.name); } + + @Override + public boolean equals(Object nc) { + // standard equals code - always return true for object identity and + // false if classes differ + if(nc == this) { + return true; + } else if(getClass() != nc.getClass()) { + return false; + } + // compare on URIs + return ((ObjectProperty)nc).name.equals(name); + } + + @Override + public int hashCode() { + return name.hashCode(); + } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -74,6 +74,7 @@ if(subProperty.equals(superProperty)) { return true; } else { +// System.out.println("oph: " + subProperty + " " + superProperty); for(ObjectProperty moreGeneralProperty : roleHierarchyUp.get(subProperty)) { if(isSubpropertyOf(moreGeneralProperty, superProperty)) { return true; Modified: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -200,14 +200,19 @@ ELDescriptionNode v4 = new ELDescriptionNode(v2, r1, a1); nodeNames.put(v4, "v4"); log("v4 added", tree, nodeNames); - ELDescriptionNode v5 = new ELDescriptionNode(v2, r3, a1, a2); + ELDescriptionNode v5 = new ELDescriptionNode(v2, r3); nodeNames.put(v5, "v5"); + log("tmp 1", tree, nodeNames); + v5.extendLabel(a1); + log("tmp 2", tree, nodeNames); + v5.extendLabel(a2); log("v5 added", tree, nodeNames); v2.refineEdge(1, r2); log("edge refined", tree, nodeNames); - ELDescriptionNode v6 = new ELDescriptionNode(v3, r3, a3); + ELDescriptionNode v6 = new ELDescriptionNode(v3, r3); nodeNames.put(v6, "v6"); - log("v6 added", tree, nodeNames); + log("v6 added", tree, nodeNames); + v6.extendLabel(a3); log("tree 4", tree, nodeNames); assertEmpty(v1); @@ -233,9 +238,50 @@ assertInSC1(v6); assertIn(v6); assertOut(v6,v5); - assertOutSC1(v6,v5); + assertOutSC1(v6,v5); } + /** + * v_1 + * / \ + * r_2 r_1 + * / \ + * v_2 v_3 + * / | | \ + * r_1 r_1 r_1 r_2 + * / | | \ + * v_4 v_5 v_6 v_7 + * / | | \ | | + * r_2 r_1 r_2 r_2 r_1 r_2 + * / | | | | | + * v_8 v_9 v_10 v_11 v_12 v_13 + * A_1 A_2 A_2 A_1 A_2 A_2 + * + * + * inSC1: + * (v_8,{v_9,..,v_13}), (v_9,{v_10,v_12,v_13}),... (Pattern wiederholt sich dann fuer die A_1 bzw A_2 Blaetter), (v_4,{v_5,v_6,v_7}),... (selbiges hier) (v_2,{v_3}), (v_3,{v_2}) + * + * outSC1: + * (v_8,{v_11}), v_9,{v_8, v_10,...v_13}),... Pattern wiederholt sich + * fuer restliche Knoten gilt inSC1=outSC1 + * + * inSC2: + * {v_8,...,v_13}2, (v_4,{v_5, v_6, v_7}), (v_5,{v_7}), (v_6,{v_7}) + * (v_2,{v_3}) + * + * outSC2: + * {v_8,...,v_13}2, (v_5,{v_4}), (v_6,{v_4}), (v_7,{v_5, v_6}), (v_3,{v_2}) + * + * Baum ist nicht minimal. + */ + @Test + public void test5() { + ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE3); + ELDescriptionTree tree = new ELDescriptionTree(rs); + Map<ELDescriptionNode,String> nodeNames = new LinkedHashMap<ELDescriptionNode,String>(); + + } + private void log(String message, ELDescriptionTree tree, Map<ELDescriptionNode,String> nodeNames) { // print underlined message System.out.println(message); Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-12-07 22:42:39 UTC (rev 1544) +++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-12-08 13:06:44 UTC (rev 1545) @@ -36,7 +36,7 @@ */ public final class TestOntologies { - public enum TestOntology { EMPTY, SIMPLE, SIMPLE2, R1SUBR2, DATA1 }; + public enum TestOntology { EMPTY, SIMPLE, SIMPLE2, SIMPLE3, R1SUBR2, DATA1 }; public static ReasonerComponent getTestOntology(TestOntology ont) { String kbString = ""; @@ -55,9 +55,13 @@ kbString += "cat SUB animal.\n"; kbString += "(human AND animal) = BOTTOM.\n"; } else if(ont.equals(TestOntology.SIMPLE2)) { - kbString += "Subrole(r1,r2).\n"; + kbString += "Subrole(r2,r3).\n"; kbString += "a1 SUB TOP.\n"; kbString += "a2 SUB a3.\n"; + kbString += "r1(a,b).\n"; // we have to declare r1 + } else if(ont.equals(TestOntology.SIMPLE3)) { + kbString += "a1 SUB a2.\n"; + kbString += "Subrole(r1,r2).\n"; } else if(ont.equals(TestOntology.R1SUBR2)) { kbString += "Subrole(r1,r2).\n"; kbString += "a1 SUB TOP.\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |