From: <jen...@us...> - 2009-04-16 18:12:12
|
Revision: 1708 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1708&view=rev Author: jenslehmann Date: 2009-04-16 18:12:06 +0000 (Thu, 16 Apr 2009) Log Message: ----------- - fixed bug occurring in KRK examples - added corresponding unit test Modified Paths: -------------- trunk/examples/krk/KRK_ONE_ZERO_fastInstance.conf trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java Modified: trunk/examples/krk/KRK_ONE_ZERO_fastInstance.conf =================================================================== --- trunk/examples/krk/KRK_ONE_ZERO_fastInstance.conf 2009-04-16 14:21:43 UTC (rev 1707) +++ trunk/examples/krk/KRK_ONE_ZERO_fastInstance.conf 2009-04-16 18:12:06 UTC (rev 1708) @@ -1,38 +1,23 @@ /* -DEBUG - --- loop 5279 started --- -INFO - best node EXISTS "hasPiece".EXISTS "hasLowerRankThan".("WRook" AND ALL "fileDistanceLessThan1"."WKing") [acc:100% h:0,853 q:0p-0n (REASONER), he:8 c:0] -INFO - -solutions: -INFO - EXISTS "http://www.test.de/test#hasPiece".EXISTS "http://www.test.de/test#hasLowerRankThan".("http://www.test.de/test#WRook" AND ALL "http://www.test.de/test#fileDistanceLessThan1"."http://www.test.de/test#WKing") (length 9, depth 5) -INFO - MANCHESTER: hasPiece some hasLowerRankThan some (WRook and fileDistanceLessThan1 only WKing) -DEBUG - size of candidate set: 50434 -DEBUG - properness tests (reasoner/short concept/too weak list): 0/3/56 -DEBUG - concept tests (reasoner/too weak list/overly general list/redundant concepts): 12609/56/38684/4153 -INFO - Algorithm terminated succesfully. -number of retrievals: 12 -retrieval reasoning time: 0ms ( 0ms per retrieval) -number of instance checks: 1232144 (0 multiple) -instance check reasoning time: 9s 613ms ( 0ms per instance check) -subsumption hierarchy queries: 14 -(complex) subsumption checks: 8 (0 multiple) -subsumption reasoning time: 17ms ( 2ms per subsumption check) -overall reasoning time: 9s 630ms (24,91% of overall runtime) -overall algorithm runtime: 38s 662ms + * Chess - King and Rook vs. lone King + * + * Here, we learn the difference between mate and mate in 1. + * + * Solutions: + * + * 1: hasPiece some hasLowerRankThan some (WRook and fileDistance0 only WKing) + * 2: hasPiece some hasLowerRankThan some (WRook and fileDistanceLessThan1 only WKing) + */ - - -*/ - import("KRK_ZERO_ONE.owl"); + refexamples.ignoredConcepts={ "http://www.test.de/test#ONE", "http://www.test.de/test#ZERO"}; - algorithm = refexamples; reasoner=fastInstanceChecker; - +"http://www.test.de/test#game100" +"http://www.test.de/test#game101" +"http://www.test.de/test#game102" Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java 2009-04-16 14:21:43 UTC (rev 1707) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java 2009-04-16 18:12:06 UTC (rev 1708) @@ -205,8 +205,6 @@ options.add(CommonConfigOptions.maxClassDescriptionTests()); options.add(CommonConfigOptions.getLogLevel()); options.add(new BooleanConfigOption("usePropernessChecks", "specifies whether to check for equivalence (i.e. discard equivalent refinements)",usePropernessChecksDefault)); - options.add(new IntegerConfigOption("maxPosOnlyExpansion", "specifies how often a node in the search tree of a posonly learning problem needs to be expanded before it is" + - " considered as solution candidate",maxPosOnlyExpansionDefault)); options.add(CommonConfigOptions.getNoisePercentage()); options.add(CommonConfigOptions.getTerminateOnNoiseReached()); options.add(new StringConfigOption("startClass", "the named class which should be used to start the algorithm (GUI: needs a widget for selecting a class)")); @@ -366,6 +364,9 @@ if(improveSubsumptionHierarchy) classHierarchy.thinOutSubsumptionHierarchy(); +// System.out.println(classHierarchy); +// System.exit(0); + // reasoner.prepareRoleHierarchy(usedRoles); // prepare datatype hierarchy only if necessary // if(reasoner.hasDatatypeSupport()) Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java 2009-04-16 14:21:43 UTC (rev 1707) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java 2009-04-16 18:12:06 UTC (rev 1708) @@ -44,8 +44,6 @@ import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.ScorePosNeg; -import org.dllearner.parser.KBParser; -import org.dllearner.parser.ParseException; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.Files; @@ -85,15 +83,6 @@ private double noise = 0.0; private int allowedMisclassifications = 0; - // positive only learning options: - // if no negatives are given, then one possible strategy is to find a very - // special concept still entailing all positive examples; - // this is realised by changing the termination criterion: a concept is a - // solution if it has been expanded x times (x is - // configurable) but no more special concept is found (all are either - // equivalent or too weak) - private int maxPosOnlyExpansion; - // search tree options private boolean writeSearchTree; private File searchTreeFile; @@ -266,7 +255,6 @@ this.usePropernessChecks = usePropernessChecks; baseURI = rs.getBaseURI(); prefixes = rs.getPrefixes(); - this.maxPosOnlyExpansion = maxPosOnlyExpansion; this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; this.minExecutionTimeInSeconds = minExecutionTimeInSeconds; this.guaranteeXgoodDescriptions = guaranteeXgoodDescriptions; @@ -467,38 +455,6 @@ Files.appendFile(searchTreeFile, treeString); } - // special situation for positive only learning: the expanded node - // can become a solution (see explanations - // for maxPosOnlyExpansion above) - - // DEPRECATED CODE - if (false - && bestNode.isPosOnlyCandidate() - && (bestNode.getHorizontalExpansion() - bestNode.getConcept().getLength() >= maxPosOnlyExpansion)) { - - boolean solution = checkSubtreePosOnly(bestNode); - - if (solution) { - solutions.add(bestNode); - ExampleBasedNode bestChild = bestNode.getChildren().last(); - System.out.println("solution: " + bestNode.getConcept()); - System.out.println("maxPosOnlyExpansion: " + maxPosOnlyExpansion); - System.out.println("best child of this node: " + bestChild); - if(bestNode.getChildConcepts().size()<100) { - System.out.println(bestNode.getChildConcepts()); - } - System.out.println("TODO: needs to be integrated with other stopping criteria"); - System.out - .println("You tried to use this algorithm for positive only learning, which is not recommended (yet)."); - // System.out.println("Exiting."); - // System.exit(0); - } else { - // tag as non-candidate so we do not need to search again - bestNode.setPosOnlyCandidate(false); - } - - } - // Anzahl Schleifendurchläufe loop++; }// end while @@ -571,6 +527,7 @@ // System.out.println("node: " + node); // System.out.println("concept: " + concept); +// System.out.println("max length: " + maxLength); // do not execute methods if algorithm has been stopped (this means that // the algorithm @@ -896,26 +853,6 @@ // System.out.println("node " + node); // System.out.println("refinement " + refinement); - /* - try { - Description c = KBParser.parseConcept("EXISTS \"http://www.test.de/test#hasPiece\".EXISTS \"http://www.test.de/test#hasLowerRankThan\".\"http://www.test.de/test#WRook\""); - if(conceptComparator.compare(c, node.getConcept()) == 0) { - System.out.println("TEST"); - Set<Description> refs = operator.refine(c, 8, null); - for(Description d : refs) { - System.out.println(" " + d); - } - System.out.println(); - System.exit(0); - } - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - */ - - - extendNodeProper(node, refinement, maxLength, recDepth + 1); } @@ -1322,45 +1259,9 @@ public ExampleBasedNode getStartNode() { return startNode; } - - // returns true if there is any meaningful node in the subtree - private boolean checkSubtreePosOnly(ExampleBasedNode node) { - for (ExampleBasedNode refinement : node.getChildren()) { - - if (!node.isTooWeak()) { - // refinement meaningful - if (isPosOnlyRefinementMeaningful(node, refinement)) - return true; - - // subtree with refinement as root contains a meaningful node - if (checkSubtreePosOnly(refinement)) - return true; - } - - } - return false; - } - - // returns whether the refinement is "meaningful", i.e. the refinement - // actually represents a different concept - // than its parent; this is needed to determine when a positive only - // learning algorithm should stop (when a node - // has been expaned x times without yielding any meaningful refinements, it - // is considered a possible solution) - private boolean isPosOnlyRefinementMeaningful(ExampleBasedNode node, ExampleBasedNode refinement) { - Description d1 = node.getConcept(); - Description d2 = refinement.getConcept(); - // check whether d2 can be shortened, e.g. male AND male => male - Description shortConcept = ConceptTransformation.getShortConcept(d2, conceptComparator); - if (conceptComparator.compare(d1, shortConcept) != 0) - return false; - return true; - } - - /** - * In this function it is calculated if the algorithm should stop. + * In this function it is calculated whether the algorithm should stop. * This is not always depends whether an actual solution was found * The algorithm stops if: * 1. the object attribute stop is set to true (possibly by an outside source) Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java 2009-04-16 14:21:43 UTC (rev 1707) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java 2009-04-16 18:12:06 UTC (rev 1708) @@ -31,7 +31,7 @@ * automatically generated, do not edit manually. * run org.dllearner.scripts.ConfigJavaGenerator to update **/ -public class ROLComponent2Configurator implements Configurator { +public class ROLComponent2Configurator extends RefinementOperatorConfigurator implements Configurator { private boolean reinitNecessary = false; @SuppressWarnings("unused") Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-04-16 14:21:43 UTC (rev 1707) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-04-16 18:12:06 UTC (rev 1708) @@ -372,7 +372,7 @@ public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements, Description currDomain) { -// logger.trace(description + " " + currDomain + " " + maxLength); +// System.out.println("|- " + description + " " + currDomain + " " + maxLength); // actions needing to be performed if this is the first time the // current domain is used @@ -399,7 +399,6 @@ } refinements = (TreeSet<Description>) topARefinementsCumulative.get(currDomain).get(maxLength).clone(); } - // refinements.addAll(subHierarchy.getMoreSpecialConcepts(description)); } else if(description instanceof Nothing) { // cannot be further refined @@ -881,7 +880,9 @@ if(useNegation) { Set<Description> m2tmp = subHierarchy.getSuperClasses(new Nothing()); for(Description c : m2tmp) { - m2.add(new Negation(c)); + if(!(c instanceof Thing)) { + m2.add(new Negation(c)); + } } } @@ -968,9 +969,11 @@ SortedSet<Description> m2tmp = subHierarchy.getSuperClasses(new Nothing()); for(Description c : m2tmp) { - if(c instanceof Thing) - m2.add(c); - else { +// if(c instanceof Thing) +// m2.add(c); +// else { + // we obviously do not add \top (\top refines \top does not make sense) + if(!(c instanceof Thing)) { NamedClass a = (NamedClass) c; if(!isNotADisjoint(a, nc) && isNotAMeaningful(a, nc)) m2.add(new Negation(a)); Modified: trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-04-16 14:21:43 UTC (rev 1707) +++ trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-04-16 18:12:06 UTC (rev 1708) @@ -39,6 +39,7 @@ import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.CELOEConfigurator; +import org.dllearner.core.configurators.ROLComponent2Configurator; import org.dllearner.core.configurators.ROLearnerConfigurator; import org.dllearner.core.configurators.RefinementOperatorConfigurator; import org.dllearner.core.options.ConfigOption; @@ -65,6 +66,7 @@ private static final SortedSet<String> EXTENDSREFINEMENTOPERATOR = new TreeSet<String>(Arrays.asList(new String[]{ ROLearnerConfigurator.class.getSimpleName(), + ROLComponent2Configurator.class.getSimpleName(), CELOEConfigurator.class.getSimpleName(), })); Modified: trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java 2009-04-16 14:21:43 UTC (rev 1707) +++ trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java 2009-04-16 18:12:06 UTC (rev 1708) @@ -24,18 +24,27 @@ import java.io.File; import java.net.MalformedURLException; import java.util.Set; +import java.util.TreeSet; +import org.dllearner.algorithms.refinement2.ROLComponent2; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.reasoning.OWLAPIReasoner; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.test.junit.TestOntologies.TestOntology; +import org.dllearner.utilities.Helper; import org.junit.Test; /** @@ -115,6 +124,56 @@ assertTrue(results.size()==desiredResultSize); } + @Test + public void rhoDRDownTest3() throws ParseException, LearningProblemUnsupportedException { + ReasonerComponent reasoner = TestOntologies.getTestOntology(TestOntology.KRK_ZERO_ONE); + baseURI = reasoner.getBaseURI(); + + // create learning algorithm in order to test under similar conditions than + // within a learning algorithm + ComponentManager cm = ComponentManager.getInstance(); + LearningProblem lp = cm.learningProblem(PosNegLPStandard.class, reasoner); + ROLComponent2 la = cm.learningAlgorithm(ROLComponent2.class, lp, reasoner); + + Set<NamedClass> ignoredConcepts = new TreeSet<NamedClass>(); + ignoredConcepts.add(new NamedClass("http://www.test.de/test#ZERO")); + ignoredConcepts.add(new NamedClass("http://www.test.de/test#ONE")); + Set<NamedClass> usedConcepts = Helper.computeConceptsUsingIgnoreList(reasoner, ignoredConcepts); + + ClassHierarchy classHierarchy = reasoner.getClassHierarchy().cloneAndRestrict(usedConcepts); + classHierarchy.thinOutSubsumptionHierarchy(); + RhoDRDown op = new RhoDRDown( + reasoner, + classHierarchy, + Thing.instance, + la.getConfigurator() + ); + + Description concept = KBParser.parseConcept("EXISTS \"http://www.test.de/test#hasPiece\".EXISTS \"http://www.test.de/test#hasLowerRankThan\".(\"http://www.test.de/test#WRook\" AND TOP)"); + Set<Description> results = op.refine(concept,8); + + for(Description result : results) { + System.out.println(result.toString("http://www.test.de/test#",null)); + } + + int desiredResultSize = 8; + if(results.size() != desiredResultSize) { + System.out.println(results.size() + " results found, but should be " + desiredResultSize + "."); + } + + // the 8 refinements found on 2009/04/16 are as follows: + // EXISTS hasPiece.EXISTS hasLowerRankThan.(BKing AND WRook) + // EXISTS hasPiece.EXISTS hasLowerRankThan.(WKing AND WRook) + // EXISTS hasPiece.EXISTS hasLowerRankThan.(WRook AND WRook) + // EXISTS hasPiece.EXISTS hasLowerRankThan.(WRook AND (NOT BKing)) + // EXISTS hasPiece.EXISTS hasLowerRankThan.(WRook AND (NOT WKing)) + // EXISTS hasPiece.EXISTS hasLowerRankThan.(WRook AND (NOT WRook)) + // EXISTS hasPiece.>= 2 hasLowerRankThan.(WRook AND TOP) + // >= 2 hasPiece.EXISTS hasLowerRankThan.(WRook AND TOP) + + assertTrue(results.size()==desiredResultSize); + } + private String uri(String name) { return "\""+baseURI+name+"\""; } Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-04-16 14:21:43 UTC (rev 1707) +++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-04-16 18:12:06 UTC (rev 1708) @@ -41,7 +41,7 @@ */ public final class TestOntologies { - public enum TestOntology { EMPTY, SIMPLE, SIMPLE_NO_DR, SIMPLE_NO_DISJOINT, SIMPLE_NO_DR_DISJOINT, SIMPLE2, SIMPLE3, R1SUBR2, DATA1, FIVE_ROLES, FATHER_OE, CARCINOGENESIS, EPC_OE }; + public enum TestOntology { EMPTY, SIMPLE, SIMPLE_NO_DR, SIMPLE_NO_DISJOINT, SIMPLE_NO_DR_DISJOINT, SIMPLE2, SIMPLE3, R1SUBR2, DATA1, FIVE_ROLES, FATHER_OE, CARCINOGENESIS, EPC_OE, KRK_ZERO_ONE }; public static ReasonerComponent getTestOntology(TestOntology ont) { String kbString = ""; @@ -115,7 +115,9 @@ owlFile = "examples/carcinogenesis/carcinogenesis.owl"; } else if(ont.equals(TestOntology.EPC_OE)) { owlFile = "examples/epc/sap_epc_oe.owl"; - } + } else if(ont.equals(TestOntology.KRK_ZERO_ONE)) { + owlFile = "examples/krk/KRK_ZERO_ONE.owl"; + } try { ComponentManager cm = ComponentManager.getInstance(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |