From: <ku...@us...> - 2008-04-23 08:04:01
|
Revision: 816 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=816&view=rev Author: kurzum Date: 2008-04-23 01:03:44 -0700 (Wed, 23 Apr 2008) Log Message: ----------- new options loglevel and stopping for ROLLearner and refexamples Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Info.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java Modified: trunk/src/dl-learner/org/dllearner/Info.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Info.java 2008-04-22 18:11:28 UTC (rev 815) +++ trunk/src/dl-learner/org/dllearner/Info.java 2008-04-23 08:03:44 UTC (rev 816) @@ -3,6 +3,6 @@ package org.dllearner; public class Info { - public static final String build = "2008-03-31"; + public static final String build = "2008-04-23"; } \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-04-22 18:11:28 UTC (rev 815) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-04-23 08:03:44 UTC (rev 816) @@ -26,6 +26,8 @@ import java.util.List; import java.util.Set; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -75,6 +77,9 @@ // actual algorithm private ExampleBasedROLearner algorithm; + private static Logger logger = Logger + .getLogger(ExampleBasedROLearner.class); + private String logLevel = CommonConfigOptions.logLevelDefault; // learning problem to solve and background knowledge private ReasoningService rs; @@ -172,6 +177,7 @@ options.add(CommonConfigOptions.maxExecutionTimeInSeconds()); options.add(CommonConfigOptions.minExecutionTimeInSeconds()); options.add(CommonConfigOptions.guaranteeXgoodDescriptions()); + options.add(CommonConfigOptions.getLogLevel()); DoubleConfigOption noisePercentage = new DoubleConfigOption("noisePercentage", "the (approximated) percentage of noise within the examples"); noisePercentage.setLowerLimit(0); noisePercentage.setUpperLimit(100); @@ -239,6 +245,8 @@ minExecutionTimeInSeconds = (Integer) entry.getValue(); }else if(name.equals("guaranteeXgoodDescriptions")) { guaranteeXgoodDescriptions = (Integer) entry.getValue(); + } else if(name.equals("logLevel")) { + logLevel = ((String)entry.getValue()).toUpperCase(); } } @@ -247,7 +255,8 @@ */ @Override public void init() { - + + logger.setLevel(Level.toLevel(logLevel,Level.toLevel(CommonConfigOptions.logLevelDefault))); if(searchTreeFile == null) searchTreeFile = new File(defaultSearchTreeFile); @@ -308,7 +317,7 @@ rs, applyAllFilter, applyExistsFilter, - useAllConstructor, + useAllConstructor, useExistsConstructor, useCardinalityRestrictions, useNegation, @@ -380,10 +389,10 @@ } - public void printBestSolutions(int nrOfSolutions){ + /*public void printBestSolutions(int nrOfSolutions){ algorithm.printBestSolutions(nrOfSolutions); - } + }*/ Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-04-22 18:11:28 UTC (rev 815) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-04-23 08:03:44 UTC (rev 816) @@ -75,8 +75,9 @@ public class ExampleBasedROLearner { private static Logger logger = Logger - .getLogger(ExampleBasedROLearner.class); + .getLogger(ExampleBasedROLearner.class); + // basic setup: learning problem and reasoning service private ReasoningService rs; private PosNegLP learningProblem; @@ -221,6 +222,7 @@ int minExecutionTimeInSeconds, int guaranteeXgoodDescriptions ) { + if(learningProblem instanceof PosNegLP) { PosNegLP lp = (PosNegLP) learningProblem; this.learningProblem = lp; @@ -257,6 +259,7 @@ this.minExecutionTimeInSeconds=minExecutionTimeInSeconds; this.guaranteeXgoodDescriptions = guaranteeXgoodDescriptions; + // logger.setLevel(Level.DEBUG); } @@ -424,7 +427,9 @@ show++; } } + logger.debug("size of candidate set: " + candidates.size()); + printBestSolutions(0); printStatistics(true); if(stop) @@ -774,9 +779,9 @@ // searchTree += bestNodeString + "\n"; logger.debug(bestNodeString); - logger.debug(startNode.getStats(nrOfPositiveExamples, nrOfNegativeExamples)); + logger.trace(startNode.getStats(nrOfPositiveExamples, nrOfNegativeExamples)); logger.debug(bestNodeStringKBSyntax); - if(bestNode.getCoveredNegatives().size()<=3)logger.debug("covered negs: "+bestNode.getCoveredNegatives()); + if(bestNode.getCoveredNegatives().size()<=5)logger.trace("covered negs: "+bestNode.getCoveredNegatives()); String expandedNodeString = "next expanded node: " + candidates.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI); // searchTree += expandedNodeString + "\n"; logger.debug(expandedNodeString); @@ -1023,10 +1028,10 @@ public void printBestSolutions(int nrOfSolutions){ - + if(nrOfSolutions==0)nrOfSolutions=candidatesStable.size(); int i=0; for(ExampleBasedNode n : candidatesStable.descendingSet()) { - System.out.println(n.getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); + logger.trace(n.getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); if(i==nrOfSolutions) return ; i++; @@ -1060,12 +1065,7 @@ if(maxExecutionTimeInSeconds==0)return false; if(maxExecutionTimeShown)return true; long needed = System.currentTimeMillis()- this.runtime; - //millisec /100 - //seconds /1000 long maxMilliSeconds = maxExecutionTimeInSeconds *1000 ; - //System.out.println("max"+maxMilliSeconds); - //System.out.println(needed); - if(maxMilliSeconds<needed){ logger.info("Maximum time reached, stopping now..."); maxExecutionTimeShown=true; @@ -1080,14 +1080,8 @@ */ private boolean minExecutionTimeReached(){ if(minExecutionTimeShown)return true; - //if(minExecutionTimeInSeconds==0)return true; long needed = System.currentTimeMillis()- this.runtime; - //millisec /100 - //seconds /1000 long minMilliSeconds = minExecutionTimeInSeconds *1000 ; - //System.out.println("min"+minMilliSeconds); - //System.out.println(needed); - if(minMilliSeconds<needed){ logger.info("Minimum time reached, stopping when next solution is found"); minExecutionTimeShown=true; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-04-22 18:11:28 UTC (rev 815) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-04-23 08:03:44 UTC (rev 816) @@ -12,6 +12,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; @@ -25,12 +26,12 @@ import org.dllearner.core.config.DoubleConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.config.StringConfigOption; -import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Intersection; -import org.dllearner.core.owl.Union; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.Union; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; import org.dllearner.refinementoperators.RhoDown; @@ -44,6 +45,8 @@ private static Logger logger = Logger .getLogger(LearningAlgorithm.class); + private String logLevel = CommonConfigOptions.logLevelDefault; + public enum Heuristic { LEXICOGRAPHIC, FLEXIBLE } // configuration options @@ -71,6 +74,15 @@ private boolean useNegation = true; private boolean useBooleanDatatypes = false; + //extended Options + private int maxExecutionTimeInSeconds = CommonConfigOptions.maxExecutionTimeInSecondsDefault; + private boolean maxExecutionTimeShown=false; + private int minExecutionTimeInSeconds = CommonConfigOptions.minExecutionTimeInSecondsDefault; + private boolean minExecutionTimeShown=false; + private int guaranteeXgoodDescriptions = CommonConfigOptions.guaranteeXgoodDescriptionsDefault; + private boolean guaranteeXgoodShown=false; + + private boolean quiet = false; private boolean stop = false; @@ -151,6 +163,7 @@ private int conceptTestsReasoner = 0; // Zeitvariablen + private long runtime; private long algorithmStartTime; private long propernessCalcTimeNs = 0; private long propernessCalcReasoningTimeNs = 0; @@ -217,6 +230,10 @@ options.add(CommonConfigOptions.useExistsConstructor()); options.add(CommonConfigOptions.useNegation()); options.add(CommonConfigOptions.useBooleanDatatypes()); + options.add(CommonConfigOptions.maxExecutionTimeInSeconds()); + options.add(CommonConfigOptions.minExecutionTimeInSeconds()); + options.add(CommonConfigOptions.guaranteeXgoodDescriptions()); + options.add(CommonConfigOptions.getLogLevel()); return options; } @@ -269,6 +286,14 @@ useNegation = (Boolean) entry.getValue(); } else if(name.equals("useBooleanDatatypes")) { useBooleanDatatypes = (Boolean) entry.getValue(); + }else if(name.equals("maxExecutionTimeInSeconds")) { + maxExecutionTimeInSeconds = (Integer) entry.getValue(); + }else if(name.equals("minExecutionTimeInSeconds")) { + minExecutionTimeInSeconds = (Integer) entry.getValue(); + }else if(name.equals("guaranteeXgoodDescriptions")) { + guaranteeXgoodDescriptions = (Integer) entry.getValue(); + } else if(name.equals("logLevel")) { + logLevel = ((String)entry.getValue()).toUpperCase(); } } @@ -278,6 +303,7 @@ */ @Override public void init() { + logger.setLevel(Level.toLevel(logLevel,Level.toLevel(CommonConfigOptions.logLevelDefault))); if(searchTreeFile == null) searchTreeFile = new File(defaultSearchTreeFile); @@ -351,7 +377,7 @@ @Override @SuppressWarnings("unchecked") public void start() { - + runtime=System.currentTimeMillis(); // Suche wird mit Top-Konzept gestartet Thing top = new Thing(); Node topNode = new Node(top); @@ -490,6 +516,11 @@ } + if(maxExecutionTimeReached()) { stop=true;} + solutionFound = (guaranteeXgoodDescriptions() ); + solutionFound = (minExecutionTimeReached()&& solutionFound); + + // Suchbaum in Datei schreiben // if(writeSearchTree) // Files.createFile(searchTreeFile, searchTree); @@ -1017,5 +1048,46 @@ public Node getStartNode() { return startNode; } + + private boolean guaranteeXgoodDescriptions(){ + if(guaranteeXgoodShown)return true; + if(solutions.size()>guaranteeXgoodDescriptions){ + logger.info("Minimum number of good descriptions reached, stopping now..."); + guaranteeXgoodShown=true; + return true;} + else return false; + + } + + + private boolean maxExecutionTimeReached(){ + if(maxExecutionTimeInSeconds==0)return false; + if(maxExecutionTimeShown)return true; + long needed = System.currentTimeMillis()- this.runtime; + long maxMilliSeconds = maxExecutionTimeInSeconds *1000 ; + if(maxMilliSeconds<needed){ + logger.info("Maximum time reached, stopping now..."); + maxExecutionTimeShown=true; + return true;} + else return false; + + } + + /** + * true if minExecutionTime reached + * @return true + */ + private boolean minExecutionTimeReached(){ + if(minExecutionTimeShown)return true; + long needed = System.currentTimeMillis()- this.runtime; + long minMilliSeconds = minExecutionTimeInSeconds *1000 ; + if(minMilliSeconds<needed){ + logger.info("Minimum time reached, stopping when next solution is found"); + minExecutionTimeShown=true; + return true;} + else return false; + + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java 2008-04-22 18:11:28 UTC (rev 815) +++ trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java 2008-04-23 08:03:44 UTC (rev 816) @@ -43,6 +43,7 @@ public static int maxExecutionTimeInSecondsDefault = 0; public static int minExecutionTimeInSecondsDefault = 0; public static int guaranteeXgoodDescriptionsDefault = 1; + public static String logLevelDefault = "DEBUG"; //public static double noisePercentageDefault = 0.0; @@ -119,5 +120,9 @@ public static IntegerConfigOption guaranteeXgoodDescriptions() { return new IntegerConfigOption("guaranteeXgoodDescriptions", "algorithm will run until X good (100%) concept descritpions are found",guaranteeXgoodDescriptionsDefault); - } + } + + public static StringConfigOption getLogLevel() { + return new StringConfigOption("logLevel", "determines the logLevel for this component, can be {TRACE, DEBUG, INFO}",logLevelDefault); + } } Modified: trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java 2008-04-22 18:11:28 UTC (rev 815) +++ trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java 2008-04-23 08:03:44 UTC (rev 816) @@ -11,7 +11,6 @@ import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import org.dllearner.utilities.AutomaticExampleFinderSPARQL; import org.dllearner.utilities.ConfWriter; -import org.dllearner.utilities.LearnSparql; import org.dllearner.utilities.SimpleClock; public class SPARQLMassLearning { @@ -34,6 +33,11 @@ try { + //System.out.println(logger.setLevel(TRACE)); + System.out.println(Level.DEBUG.getClass()); + System.out.println(Level.toLevel("INFO")); + System.out.println(Level.INFO); + System.exit(0); SimpleClock sc=new SimpleClock(); SortedSet<String> concepts = new TreeSet<String>(); //concepts.add("\"http://dbpedia.org/class/yago/Person100007846\""); @@ -57,7 +61,7 @@ // new ConfWriter().writeSPARQL("aaa.conf", posExamples, negExamples, url, new TreeSet<String>()); - new LearnSparql().learn(posExamples, negExamples, "http://dbpedia.openlinksw.com:8890/sparql", new TreeSet<String>()); + //new LearnSparql().learn(posExamples, negExamples, "http://dbpedia.openlinksw.com:8890/sparql", new TreeSet<String>()); sc.printAndSet("Finished"); } catch (Exception e) { Modified: trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java 2008-04-22 18:11:28 UTC (rev 815) +++ trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java 2008-04-23 08:03:44 UTC (rev 816) @@ -72,6 +72,7 @@ cm.applyConfigEntry(la,"minExecutionTimeInSeconds",0); cm.applyConfigEntry(la,"maxExecutionTimeInSeconds",900); cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",999999); + cm.applyConfigEntry(la,"logLevel","TRACE"); //cm.applyConfigEntry(la,"quiet",false); if(ignoredConcepts.size()>0) @@ -82,7 +83,7 @@ la.start(); //System.out.println("best"+la(20)); - ((ExampleBasedROLComponent)la).printBestSolutions(10000); + //((ExampleBasedROLComponent)la).printBestSolutions(10000); }catch (Exception e) {e.printStackTrace();} //System.out.println( la.getBestSolution());; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |