From: <jen...@us...> - 2008-12-19 16:04:57
|
Revision: 1559 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1559&view=rev Author: jenslehmann Date: 2008-12-19 16:04:45 +0000 (Fri, 19 Dec 2008) Log Message: ----------- continued EL refinement operator - it now passes unit test 1 ! Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-12-17 15:20:27 UTC (rev 1558) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-12-19 16:04:45 UTC (rev 1559) @@ -188,7 +188,7 @@ Description conceptModForCache = ConceptTransformation.applyEquivalenceRules(conceptMod); - ConceptTransformation.transformToOrderedNegationNormalForm(conceptModForCache, conceptComparator); + ConceptTransformation.transformToOrderedForm(conceptModForCache, conceptComparator); Score score = program.getScore(); // Eval-Cache füllen @@ -207,7 +207,7 @@ /////////// TESTCODE: umwandeln des erhaltenen Konzepts // someTimeStart = System.nanoTime(); Description newConceptMod = ConceptTransformation.applyEquivalenceRules(newConcept); - ConceptTransformation.transformToOrderedNegationNormalForm(newConceptMod, conceptComparator); + ConceptTransformation.transformToOrderedForm(newConceptMod, conceptComparator); // someTime += System.nanoTime() - someTimeStart; /////////// Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-17 15:20:27 UTC (rev 1558) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-19 16:04:45 UTC (rev 1559) @@ -107,7 +107,7 @@ */ @Override public Set<Description> refine(Description concept) { - System.out.println("refining " + concept); + logger.trace("refining " + concept); ELDescriptionTree tree = new ELDescriptionTree(rs, concept); Set<ELDescriptionTree> refinementTrees = refine(tree); Set<Description> refinements = new HashSet<Description>(); @@ -126,7 +126,7 @@ * @return Set of refined EL description trees. */ public Set<ELDescriptionTree> refine(ELDescriptionTree tree) { - System.out.println("applying \\rho on " + tree.toDescriptionString()); + logger.trace("applying \\rho on " + tree.toDescriptionString()); Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); // loop over all nodes of the tree and perform one of the @@ -134,7 +134,7 @@ // the transformations can, of course, add new nodes) Set<ELDescriptionNode> nodes = new HashSet<ELDescriptionNode>(tree.getNodes()); for(ELDescriptionNode v : nodes) { - System.out.println("picked node v: " + v); + logger.trace("picked node v: " + v); // the position of the node within the tree (needed for getting // the corresponding node in a cloned tree) @@ -142,8 +142,8 @@ // perform operations refinements.addAll(extendLabel(tree, v, position)); -// refinements.addAll(refineLabel(tree, v, position)); -// refinements.addAll(refineEdge(tree, v, position)); + refinements.addAll(refineLabel(tree, v, position)); + refinements.addAll(refineEdge(tree, v, position)); refinements.addAll(attachSubtree(tree, v, position)); } @@ -255,7 +255,7 @@ // loop through most general roles for(ObjectProperty op : mgr) { - System.out.println("pick most general role: " + op); + logger.trace("pick most general role: " + op); // a list of subtrees (stored as edges i.e. role + root node which points to tree) LinkedList<ELDescriptionEdge> m = new LinkedList<ELDescriptionEdge>(); @@ -270,29 +270,35 @@ while(!m.isEmpty()) { // pick and remove first element ELDescriptionEdge edge = m.pollFirst(); - System.out.println("picked first element of M: " + edge); + logger.trace("picked first element of M: " + edge); ObjectProperty r = edge.getLabel(); // tp = t' in algorithm description (p stands for prime) ELDescriptionTree tp = edge.getNode().getTree(); // merge tree into main tree ELDescriptionTree mergedTree = mergeTrees(tree, v, position, r, tp); - ELDescriptionNode vClone = mergedTree.getNode(position); - System.out.println("merged to t_{C'}: \n" + mergedTree); + // the position of w is the position of v + #edges outgoing from v + int[] wPosition = new int[position.length+1]; + System.arraycopy(position, 0, wPosition, 0, position.length); + wPosition[position.length] = v.getEdges().size(); + ELDescriptionNode wClone = mergedTree.getNode(wPosition); + + logger.trace("merged to t_{C'}: \n" + mergedTree); + // System.out.println(mergedTree.toSimulationString()); // we check equivalence by a minimality test (TODO: can we still do this?) if(mergedTree.isMinimal()) { - System.out.println("Merged tree is minimal, i.e. not equivalent."); + logger.trace("Merged tree is minimal, i.e. not equivalent."); // it is not equivalent, i.e. we found a refinement refinements.add(mergedTree); } else { - System.out.println("Merged tree is not minimal, i.e. equivalent."); + logger.trace("Merged tree is not minimal, i.e. equivalent."); // perform complex check in merged tree - boolean check = asCheck(vClone); - System.out.println("Result of complex check: " + check); + boolean check = asCheck(wClone); + logger.trace("Result of complex check: " + check); if(check) { // refine property @@ -300,9 +306,9 @@ m.add(new ELDescriptionEdge(subRole, tp.getRootNode())); } // refine tree using recursive operator call - System.out.println("Recursive Call"); + logger.trace("Recursive Call"); Set<ELDescriptionTree> recRefs = refine(tp); - System.out.println("Recursive Call Done"); + logger.trace("Recursive Call Done"); for(ELDescriptionTree tpp : recRefs) { // System.out.println("aa " + tpp.toDescriptionString()); m.add(new ELDescriptionEdge(r, tpp.getRootNode())); @@ -310,7 +316,7 @@ } } - System.out.println("M: " + m); + logger.trace("M: " + m); } } @@ -366,15 +372,21 @@ return mergedTree; } + // TODO: variables have been renamed in article private boolean asCheck(ELDescriptionNode v) { +// System.out.println("asCheck: " + v.getTree().toSimulationString()); + // find all edges up to the root node List<ELDescriptionEdge> piVEdges = new LinkedList<ELDescriptionEdge>(); ELDescriptionNode tmp = v; while(!tmp.isRoot()) { +// System.out.println("blub"); piVEdges.add(tmp.getParentEdge()); tmp = tmp.getParent(); } +// System.out.println(piVEdges); + // go through all edges for(ELDescriptionEdge piVEdge : piVEdges) { // collect (w,r',w') @@ -382,12 +394,18 @@ ObjectProperty rp = piVEdge.getLabel(); ELDescriptionNode w = wp.getParent(); - // go through all (w,s,w'') - TODO: s or a new s' ? +// System.out.println(w); +// System.out.println(rp); +// System.out.println(wp); + + // go through all (w,s,w'') for(ELDescriptionEdge wEdge : w.getEdges()) { ObjectProperty rpp = wEdge.getLabel(); ELDescriptionNode wpp = wEdge.getNode(); if(wp != wpp && opHierarchy.isSubpropertyOf(rp, rpp)) { - if(wp.getIn().contains(wpp)) { +// System.out.println("wp: " + wp); +// System.out.println("wpp: " + wpp); + if(wp.getOut().contains(wpp)) { return false; } } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-12-17 15:20:27 UTC (rev 1558) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-12-19 16:04:45 UTC (rev 1559) @@ -779,7 +779,7 @@ // convert all concepts in ordered negation normal form for(Description concept : baseSet) { - ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator); + ConceptTransformation.transformToOrderedForm(concept, conceptComparator); } // apply the exists filter (throwing out all refinements with Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-12-17 15:20:27 UTC (rev 1558) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-12-19 16:04:45 UTC (rev 1559) @@ -460,7 +460,7 @@ // Umwandlung aller Konzepte in Negationsnormalform for(Description concept : baseSet) { - ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator); + ConceptTransformation.transformToOrderedForm(concept, conceptComparator); } if(applyExistsFilter) { Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-12-17 15:20:27 UTC (rev 1558) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-12-19 16:04:45 UTC (rev 1559) @@ -123,7 +123,8 @@ // not satisfied // check1: disjointness with index // check3: no superclass exists already - if(!isDisjoint(candidate,index) && checkSubClasses(existingClasses,candidate)) { + // check5: disjointness + if(!isDisjoint(candidate,index) && checkSubClasses(existingClasses,candidate) && checkDisjoints(existingClasses,candidate)) { // check whether the class is meaningful, i.e. adds something to the index // to do this, we need to make sure that the class is not a superclass of the // index (otherwise we get nothing new) @@ -162,6 +163,16 @@ return true; } + // returns false if any of the classes is disjoint with the new one; true otherwise + private boolean checkDisjoints(Set<NamedClass> existingClasses, NamedClass candidate) { + for(NamedClass nc : existingClasses) { + if(isDisjoint(nc, candidate)) + return false; + } + return true; + } + + public boolean isDisjoint(Description d1, Description d2) { // System.out.println("d1: " + d1); // System.out.println("d2: " + d2); Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-17 15:20:27 UTC (rev 1558) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-19 16:04:45 UTC (rev 1559) @@ -19,20 +19,25 @@ */ package org.dllearner.test.junit; +import static org.junit.Assert.*; + import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.Logger; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.owl.Description; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.refinementoperators.ELDown2; +import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.test.junit.TestOntologies.TestOntology; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; +import org.dllearner.utilities.statistics.Stat; import org.junit.Test; /** @@ -43,6 +48,8 @@ */ public class ELDownTests { + private static Logger logger = Logger.getLogger(ELDownTests.class); + /** * Implementation of test case created by Christoph Haase for * new operator. @@ -57,11 +64,11 @@ // input description Description input = KBParser.parseConcept("(human AND EXISTS has.animal)"); - System.out.println("refining: " + input); + System.out.println("refining: " + input.toString(KBParser.internalNamespace, null)); // TODO For this test, we need to turn instance based disjoints // off! (We do not have any instances here.) - ELDown2 operator = new ELDown2(rs); + RefinementOperator operator = new ELDown2(rs); // desired refinements as strings Set<String> desiredString = new TreeSet<String>(); @@ -71,7 +78,7 @@ desiredString.add("((human AND EXISTS hasPet.TOP) AND EXISTS has.animal)"); desiredString.add("((human AND EXISTS hasChild.TOP) AND EXISTS has.animal)"); desiredString.add("((human AND EXISTS hasPet.TOP) AND EXISTS has.animal)"); - desiredString.add("((human AND EXISTS has.person) AND EXISTS has.animal)"); + desiredString.add("((human AND EXISTS has.human) AND EXISTS has.animal)"); desiredString.add("((human AND EXISTS has.EXISTS has.TOP) AND EXISTS has.animal)"); desiredString.add("(human AND EXISTS has.(animal AND EXISTS has.TOP))"); @@ -81,29 +88,42 @@ Description tmp = KBParser.parseConcept(str); // eliminate conjunctions nested in other conjunctions ConceptTransformation.cleanConcept(tmp); + ConceptTransformation.transformToOrderedForm(tmp, cc); desired.add(tmp); - System.out.println("desired: " + tmp); + System.out.println("desired: " + tmp.toString(KBParser.internalNamespace, null)); } // perform refinement and compare solutions long startTime = System.nanoTime(); Set<Description> refinements = operator.refine(input); long runTime = System.nanoTime() - startTime; - System.out.println("Refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + "."); - startTime = System.nanoTime(); - refinements = operator.refine(input); - runTime = System.nanoTime() - startTime; - System.out.println("Identical 2nd refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + "."); - + logger.debug("Refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + "."); + boolean runStats = false; + if(runStats) { + Stat stat = new Stat(); + int runs = 100; + for(int run=0; run<runs; run++) { + startTime = System.nanoTime(); + refinements = operator.refine(input); + runTime = System.nanoTime() - startTime; + stat.addNumber(runTime/1000000); + } +// System.out.println("Identical 2nd refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + "."); + System.out.println("average over " + runs + " runs:"); + System.out.println(stat.prettyPrint("ms")); + } + // number of refinements has to be correct and each produced // refinement must be in the set of desired refinements -// assertTrue(refinements.size() == desired.size()); + assertTrue(refinements.size() == desired.size()); + System.out.println("\nproduced refinements and their unit test status (true = assertion satisfied):"); for(Description refinement : refinements) { boolean ok = desired.contains(refinement); - System.out.println(ok + ": " + refinement); -// assertTrue(desired.contains(refinement)); + System.out.println(ok + ": " + refinement.toString(KBParser.internalNamespace, null)); + assertTrue(desired.contains(refinement)); } + // generated by operator (and currently corresponding to its definition): // false (http://localhost/foo#human AND EXISTS http://localhost/foo#has.(http://localhost/foo#animal AND http://localhost/foo#human // false (http://localhost/foo#animal AND http://localhost/foo#human AND EXISTS http://localhost/foo#has.http://localhost/foo#animal Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-12-17 15:20:27 UTC (rev 1558) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-12-19 16:04:45 UTC (rev 1559) @@ -286,11 +286,11 @@ // wandelt ein Konzept in geordnete Negationsnormalform um; // es wird angenommen, dass das Eingabekonzept in Negationsnormalform und // "sauber" ist - public static void transformToOrderedNegationNormalForm(Description concept, Comparator<Description> conceptComparator) { + public static void transformToOrderedForm(Description concept, Comparator<Description> conceptComparator) { // alle Kinderkonzepte in geordnete Negationsnormalform bringen for(Description child : concept.getChildren()) { - transformToOrderedNegationNormalForm(child, conceptComparator); + transformToOrderedForm(child, conceptComparator); } onnfTimeNsStart = System.nanoTime(); Modified: trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java 2008-12-17 15:20:27 UTC (rev 1558) +++ trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java 2008-12-19 16:04:45 UTC (rev 1559) @@ -127,4 +127,21 @@ return max; } + public String prettyPrint(String unit) { + DecimalFormat df = new DecimalFormat(); + String str = "av. " + df.format(getMean()) + unit; + str += " (deviation " + df.format(getStandardDeviation()) + unit + "; "; + str += "min " + df.format(getMin()) + unit + "; "; + str += "max " + df.format(getMax()) + unit + ")"; + return str; + } + + public String prettyPrint(String unit, DecimalFormat df) { + String str = "av. " + df.format(getMean()) + unit; + str += " (deviation " + df.format(getStandardDeviation()) + unit + "; "; + str += "min " + df.format(getMin()) + unit + "; "; + str += "max " + df.format(getMax()) + unit + ")"; + return str; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |