From: <jen...@us...> - 2008-11-21 12:07:02
|
Revision: 1520 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1520&view=rev Author: jenslehmann Date: 2008-11-21 12:06:58 +0000 (Fri, 21 Nov 2008) Log Message: ----------- continued work on EL simulations Modified Paths: -------------- trunk/examples/carcinogenesis/train.conf 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/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java Modified: trunk/examples/carcinogenesis/train.conf =================================================================== --- trunk/examples/carcinogenesis/train.conf 2008-11-18 18:05:10 UTC (rev 1519) +++ trunk/examples/carcinogenesis/train.conf 2008-11-21 12:06:58 UTC (rev 1520) @@ -10,7 +10,7 @@ refexamples.writeSearchTree = false; refexamples.searchTreeFile = "log/carcinogenesis/searchTree.log"; -// store some default settings to make the experiment reproducable in the future +// store some settings to make the experiment reproducable in the future refexamples.negativeWeight = 0.8; refexamples.startNodeBonus = 1.0; refexamples.forceRefinementLengthIncrease = false; Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-18 18:05:10 UTC (rev 1519) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-21 12:06:58 UTC (rev 1520) @@ -58,7 +58,7 @@ // the reference tree for storing values, must not be null protected ELDescriptionTree tree; - protected TreeSet<NamedClass> label; + protected TreeSet<NamedClass> label = new TreeSet<NamedClass>(); protected List<ELDescriptionEdge> edges = new LinkedList<ELDescriptionEdge>(); @@ -111,7 +111,9 @@ } public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, TreeSet<NamedClass> label) { - this.label = label; +// this.label = label; + // we first need to add the edge and update the simulation and then add + // all classes iteratively to the label (each time updating the simulation again) this.edges = new LinkedList<ELDescriptionEdge>(); parent = parentNode; // the reference tree is the same as for the parent tree @@ -122,36 +124,63 @@ ELDescriptionEdge edge = new ELDescriptionEdge(parentProperty, this); parent.edges.add(edge); // we need to update the set of nodes on a particular level - tree.addNodeToLevel(this, level); + tree.addNodeToLevel(this, level); // simulation update // the nodes, which need to be updated - Set<ELDescriptionNode> update = new TreeSet<ELDescriptionNode>(); + Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>(); // loop over all nodes on the same level, which are not in the in set Set<ELDescriptionNode> nodes = tree.getNodesOnLevel(level); for(ELDescriptionNode w : nodes) { - if(w.label.size() == 0) { + // to save space, we do not add reflexive relations + if(w != this) { + // (w,v') is automatically added + tree.extendSimulation(w, this); - } - - if(inSC1.contains(w) && tree.checkSC2(this, w)) { - tree.extendSimulation(this, w); + // check conditions for (v',w) + boolean sc1 = false, sc2 = false; + + if(w.label.size() == 0) { + tree.extendSimulationSC1(this, w); + sc1 = true; + } + + if(w.edges.size() == 0) { + tree.extendSimulationSC2(this, w); + sc2 = true; + } + + if(sc1 && sc2) { + tree.extendSimulationSC12(this, w); + } + update.add(w.parent); } } + update.add(this.parent); +// if(inSC1.contains(w) && tree.checkSC2(this, w)) { +// tree.extendSimulation(this, w); +// update.add(w.parent); +// } + // loop over all nodes in out set - for(ELDescriptionNode w : out) { - if(!tree.checkSC1(this, w)) { - tree.shrinkSimulation(this, w); - update.add(w.parent); - } - } +// for(ELDescriptionNode w : out) { +// if(!tree.checkSC1(this, w)) { +// tree.shrinkSimulation(this, w); +// update.add(w.parent); +// } +// } // apply updates recursively top-down tree.updateSimulation(update); + // add all classes in label + for(NamedClass nc : label) { + extendLabel(nc); + } + } /** @@ -304,21 +333,25 @@ Set<ELDescriptionNode> update = new TreeSet<ELDescriptionNode>(); // loop over all nodes on the same level, which are not in the in set - Set<ELDescriptionNode> nodes = tree.getNodesOnLevel(level); - Set<ELDescriptionNode> tmp = Helper.difference(nodes, in); + Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level)); + tmp.removeAll(in); for(ELDescriptionNode w : tmp) { - // we only need to recompute SC2 - if(inSC1.contains(w) && tree.checkSC2(this, w)) { - tree.extendSimulation(this, w); - update.add(w.parent); + if(w != this) { + // we only need to recompute SC2 + if(inSC1.contains(w) && tree.checkSC2(this, w)) { + tree.extendSimulation(this, w); + update.add(w.parent); + } } } // loop over all nodes in out set for(ELDescriptionNode w : out) { - if(!tree.checkSC1(this, w)) { - tree.shrinkSimulation(this, w); - update.add(w.parent); + if(w != this) { + if(!tree.checkSC1(w, this)) { + tree.shrinkSimulation(w, this); + update.add(w.parent); + } } } @@ -330,24 +363,28 @@ edges.get(edgeNumber).setLabel(op); // compute the nodes, which need to be updated - Set<ELDescriptionNode> update = new TreeSet<ELDescriptionNode>(); + Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>(); // loop over all nodes on the same level, which are not in the in set - Set<ELDescriptionNode> nodes = tree.getNodesOnLevel(level); - Set<ELDescriptionNode> tmp = Helper.difference(nodes, in); + Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level)); + tmp.removeAll(in); for(ELDescriptionNode w : tmp) { - // we only need to recompute SC1 - if(inSC2.contains(w) && tree.checkSC1(this, w)) { - tree.extendSimulation(this, w); - update.add(w.parent); + if(w != this) { + // we only need to recompute SC1 + if(inSC2.contains(w) && tree.checkSC1(this, w)) { + tree.extendSimulation(this, w); + update.add(w.parent); + } } } // loop over all nodes in out set for(ELDescriptionNode w : out) { - if(!tree.checkSC2(this, w)) { - tree.shrinkSimulation(this, w); - update.add(w.parent); + if(w != this) { + if(!tree.checkSC2(this, w)) { + tree.shrinkSimulation(this, w); + update.add(w.parent); + } } } @@ -422,6 +459,32 @@ return str; } + private String toDescriptionString(Set<ELDescriptionNode> nodes) { + String str = ""; + // comma separated list of descriptions + for(ELDescriptionNode node : nodes) { + str += node.toDescriptionString() + ","; + } + // remove last comma + if(str.length() > 0) { + str = str.substring(0, str.length()-1); + } + return str; + } + + public String toSimulationString() { + String str = ""; + str += "in: " + toDescriptionString(in) + "\n"; + str += "inSC1: " + toDescriptionString(inSC1) + "\n"; + str += "inSC2: " + toDescriptionString(inSC2) + "\n"; + str += "out: " + toDescriptionString(out) + "\n"; + str += "outSC1: " + toDescriptionString(outSC1) + "\n"; + str += "outSC2: " + toDescriptionString(outSC2) + "\n"; + return str; + } + + + public ELDescriptionNode getParent() { return parent; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-18 18:05:10 UTC (rev 1519) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-21 12:06:58 UTC (rev 1520) @@ -234,17 +234,20 @@ // same level are tested before any node of a lower level is tested) ELDescriptionNode v = list.pollFirst(); // loop through all nodes on same level - for(ELDescriptionNode w : levelNodeMapping.get(v.getLevel())) { - if(!v.out.contains(w) && v.outSC1.contains(w) && checkSC2(v,w)) { - extendSimulation(v,w); - list.add(v.getParent()); - list.add(w.getParent()); + Set<ELDescriptionNode> sameLevel = levelNodeMapping.get(v.getLevel()); + for(ELDescriptionNode w : sameLevel) { + if(v != w) { + if(!v.out.contains(w) && v.outSC1.contains(w) && checkSC2(v,w)) { + extendSimulation(v,w); + list.add(v.getParent()); + list.add(w.getParent()); + } + if(!w.out.contains(v) && w.outSC1.contains(v) && checkSC2(w,v)) { + extendSimulation(w,v); + list.add(v.getParent()); + list.add(w.getParent()); + } } - if(!w.out.contains(v) && w.outSC1.contains(v) && checkSC2(w,v)) { - extendSimulation(w,v); - list.add(v.getParent()); - list.add(w.getParent()); - } } } } @@ -327,6 +330,21 @@ node2.inSC2.add(node1); } + public void extendSimulationSC1(ELDescriptionNode node1, ELDescriptionNode node2) { + node1.outSC1.add(node2); + node2.inSC1.add(node1); + } + + public void extendSimulationSC2(ELDescriptionNode node1, ELDescriptionNode node2) { + node1.outSC2.add(node2); + node2.inSC2.add(node1); + } + + public void extendSimulationSC12(ELDescriptionNode node1, ELDescriptionNode node2) { + node1.out.add(node2); + node2.in.add(node1); + } + // removes (node1,node2) from simulation, takes care of all helper sets public void shrinkSimulation(ELDescriptionNode node1, ELDescriptionNode node2) { node1.out.remove(node2); @@ -337,6 +355,21 @@ node2.inSC2.remove(node1); } + public void shrinkSimulationSC1(ELDescriptionNode node1, ELDescriptionNode node2) { + node1.outSC1.remove(node2); + node2.inSC1.remove(node1); + } + + public void shrinkSimulationSC2(ELDescriptionNode node1, ELDescriptionNode node2) { + node1.outSC2.remove(node2); + node2.inSC2.remove(node1); + } + + public void shrinkSimulationSC12(ELDescriptionNode node1, ELDescriptionNode node2) { + node1.out.remove(node2); + node2.in.remove(node1); + } + @Override @SuppressWarnings("unchecked") public ELDescriptionTree clone() { Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-18 18:05:10 UTC (rev 1519) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-21 12:06:58 UTC (rev 1520) @@ -49,7 +49,6 @@ import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; -import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; @@ -126,7 +125,7 @@ private RoleComparator roleComparator = new RoleComparator(); // private ClassHierarchy subsumptionHierarchy; // private ObjectPropertyHierarchy roleHierarchy; - private DatatypePropertyHierarchy datatypePropertyHierarchy; +// private DatatypePropertyHierarchy datatypePropertyHierarchy; // private Set<Description> allowedConceptsInSubsumptionHierarchy; // primitives Modified: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-11-18 18:05:10 UTC (rev 1519) +++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-11-21 12:06:58 UTC (rev 1520) @@ -71,12 +71,14 @@ // perform test with empty background knowledge and A1 AND EXISTS r1.TOP AND EXISTS r2.TOP ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.EMPTY); ELDescriptionTree tree = new ELDescriptionTree(rs); + NamedClass a1 = new NamedClass("a1"); ELDescriptionNode v1 = new ELDescriptionNode(tree); + v1.extendLabel(a1); ObjectProperty r1 = new ObjectProperty("r1"); ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, new TreeSet<NamedClass>()); ObjectProperty r2 = new ObjectProperty("r2"); ELDescriptionNode v3 = new ELDescriptionNode(v1, r2, new TreeSet<NamedClass>()); - + assertEmpty(v1); assertAll(v2, v3); assertAll(v3, v2); @@ -109,6 +111,11 @@ ObjectProperty r2 = new ObjectProperty("r2"); ELDescriptionNode v4 = new ELDescriptionNode(v1, r2, a1); + System.out.println("v1:\n" + v1.toSimulationString()); + System.out.println("v2:\n" + v2.toSimulationString()); + System.out.println("v3:\n" + v3.toSimulationString()); + System.out.println("v4:\n" + v4.toSimulationString()); + assertEmpty(v1); assertAllIn(v2, v3, v4); @@ -160,7 +167,8 @@ ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, a2, a3); ELDescriptionNode v3 = new ELDescriptionNode(v1, r1); ELDescriptionNode v4 = new ELDescriptionNode(v2, r1, a1); - ELDescriptionNode v5 = new ELDescriptionNode(v2, r2, a1, a2); + ELDescriptionNode v5 = new ELDescriptionNode(v2, r3, a1, a2); + v2.refineEdge(1, r2); ELDescriptionNode v6 = new ELDescriptionNode(v3, r3, a3); assertEmpty(v1); Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-11-18 18:05:10 UTC (rev 1519) +++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-11-21 12:06:58 UTC (rev 1520) @@ -56,7 +56,7 @@ kbString += "(human AND animal) = BOTTOM.\n"; } else if(ont.equals(TestOntology.SIMPLE2)) { kbString += "Subrole(r2,r3)."; - kbString += "a2 SUB a4"; + kbString += "a2 SUB a4."; } else if(ont.equals(TestOntology.R1SUBR2)) { kbString += "Subrole(r1,r2).\n"; } else if(ont.equals(TestOntology.DATA1)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |