From: <jen...@us...> - 2008-08-20 12:13:52
|
Revision: 1106 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1106&view=rev Author: jenslehmann Date: 2008-08-20 12:13:48 +0000 (Wed, 20 Aug 2008) Log Message: ----------- * changed command line logging: - one appender writes to console with log level info - a second appender writes to a file log/log.txt with log level debug * console output cleaned up a bit Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.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/cli/Start.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-08-20 11:21:37 UTC (rev 1105) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-08-20 12:13:48 UTC (rev 1106) @@ -206,6 +206,15 @@ return (coveredPositives.size() + nrOfNegativeExamples - coveredNegatives.size())/(double)(nrOfPositiveExamples+nrOfNegativeExamples); } + /** + * Used to detect whether one node is more accurate than another one + * with calculating accuracy itself. + * @return Number of covered positives minus number of covered negatives. + */ + public int getCovPosMinusCovNeg() { + return coveredPositives.size() - coveredNegatives.size(); + } + public Set<Individual> getCoveredPositives() { return coveredPositives; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-08-20 11:21:37 UTC (rev 1105) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-08-20 12:13:48 UTC (rev 1106) @@ -275,11 +275,15 @@ @Override public void init() throws ComponentInitException { + // exit with a ComponentInitException if the reasoner is unsupported for this learning algorithm if(rs.getReasonerType() == ReasonerType.DIG) { throw new ComponentInitException("DIG does not support the inferences needed in the selected learning algorithm component: " + getName()); } - logger.setLevel(Level.toLevel(logLevel,Level.toLevel(CommonConfigOptions.logLevelDefault))); + // set log level if the option has been set + if(!logLevel.equals(CommonConfigOptions.logLevelDefault)) + logger.setLevel(Level.toLevel(logLevel,Level.toLevel(CommonConfigOptions.logLevelDefault))); + if(searchTreeFile == null) searchTreeFile = new File(defaultSearchTreeFile); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-08-20 11:21:37 UTC (rev 1105) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-08-20 12:13:48 UTC (rev 1106) @@ -26,6 +26,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.NavigableSet; import java.util.Set; import java.util.SortedSet; @@ -118,9 +119,9 @@ //extended Options private long maxExecutionTimeInSeconds; private boolean maxExecutionTimeShown=false; - private long minExecutionTimeInSeconds; + private long minExecutionTimeInSeconds = 0; private boolean minExecutionTimeShown=false; - private int guaranteeXgoodDescriptions; + private int guaranteeXgoodDescriptions = 1; private boolean guaranteeXgoodShown=false; // if set to false we do not test properness; this may seem wrong @@ -217,6 +218,7 @@ // prefixes private String baseURI; + private Map<String,String> prefixes; public ExampleBasedROLearner( LearningProblem learningProblem, @@ -277,7 +279,8 @@ this.useOverlyGeneralList = useOverlyGeneralList; this.useShortConceptConstruction = useShortConceptConstruction; this.usePropernessChecks = usePropernessChecks; - this.baseURI = rs.getBaseURI(); + baseURI = rs.getBaseURI(); + prefixes = rs.getPrefixes(); this.maxPosOnlyExpansion = maxPosOnlyExpansion; this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; this.minExecutionTimeInSeconds = minExecutionTimeInSeconds; @@ -292,7 +295,7 @@ runtime=System.currentTimeMillis(); JamonMonitorLogger.getTimeMonitor(ExampleBasedROLComponent.class, "totalLearningTime").start(); // TODO: write a JUnit test for this problem (long-lasting or infinite loops because - // redundant children of a node are called recursively after when the node is extended + // redundant children of a node are called recursively when a node is extended // twice) /* // String conceptStr = "(\"http://dl-learner.org/carcinogenesis#Compound\" AND (>= 2 \"http://dl-learner.org/carcinogenesis#hasStructure\".\"http://dl-learner.org/carcinogenesis#Ar_halide\" OR ((\"http://dl-learner.org/carcinogenesis#amesTestPositive\" IS TRUE) AND >= 5 \"http://dl-learner.org/carcinogenesis#hasBond\". TOP)))"; @@ -350,6 +353,7 @@ candidatesStable.add(startNode); ExampleBasedNode bestNode = startNode; + ExampleBasedNode bestNodeStable = startNode; int loop = 0; @@ -386,7 +390,14 @@ } -// System.out.println("next expanded: " + candidates.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); +// System.out.println("next expanded: " + candidates.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); + + // we record when a more accurate node is found and log it + if(bestNodeStable.getCovPosMinusCovNeg() < candidatesStable.last().getCovPosMinusCovNeg()) { + logger.info("more accurate node found: " + candidatesStable.last()); + bestNodeStable = candidatesStable.last(); + } + // chose best node according to heuristics bestNode = candidates.last(); // extend best node @@ -456,21 +467,23 @@ if(solutionFound ) { + int solutionLimit = 20; logger.info("best node " + candidatesStable.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); - logger.info("\nsolutions ( top 5 ):"); + logger.info("solutions (at most " + solutionLimit + " are shown):"); int show=1; String manchester="MANCHESTER:\n"; - String KBSyntax="KBSyntax:\n"; + String kbSyntax="KBSyntax:\n"; for(Description c : solutions) { logger.info(show+": " + c.toString(baseURI,null) + " (length " + c.getLength() +", depth " + c.getDepth() + ")"); - manchester+=show+": "+c.toManchesterSyntaxString(baseURI, new HashMap<String,String>())+"\n"; - KBSyntax+=show+": " + c.toKBSyntaxString()+"\n"; - if(show>=5){break;} show++; + manchester+=show+": "+c.toManchesterSyntaxString(baseURI, prefixes)+"\n"; + kbSyntax+=show+": " + c.toKBSyntaxString()+"\n"; + if(show >= solutionLimit) { + break; + } + show++; } logger.debug(manchester); - logger.debug(KBSyntax); - - + logger.debug(kbSyntax); } logger.debug("size of candidate set: " + candidates.size()); @@ -1189,7 +1202,9 @@ private boolean guaranteeXgoodDescriptions(){ if(guaranteeXgoodShown)return true; if(solutions.size()>guaranteeXgoodDescriptions){ - logger.info("Minimum number ("+guaranteeXgoodDescriptions+") of good descriptions reached, stopping now..."); + if(guaranteeXgoodDescriptions != 1) { + logger.info("Minimum number ("+guaranteeXgoodDescriptions+") of good descriptions reached, stopping now."); + } guaranteeXgoodShown=true; return true;} else return false; @@ -1218,8 +1233,10 @@ if(minExecutionTimeShown)return true; long needed = System.currentTimeMillis()- this.runtime; long minMilliSeconds = minExecutionTimeInSeconds *1000 ; - if(minMilliSeconds<needed){ - logger.info("Minimum time ("+minExecutionTimeInSeconds+" seconds) reached, stopping when next solution is found"); + if(minMilliSeconds<needed) { + if(minExecutionTimeInSeconds != 0) { + logger.info("Minimum time ("+minExecutionTimeInSeconds+" seconds) reached, stopping when next solution is found"); + } minExecutionTimeShown=true; return true;} else return false; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-08-20 11:21:37 UTC (rev 1105) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-08-20 12:13:48 UTC (rev 1106) @@ -36,8 +36,11 @@ import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; +import org.apache.log4j.Layout; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.Priority; import org.apache.log4j.SimpleLayout; import org.dllearner.algorithms.BruteForceLearner; import org.dllearner.algorithms.RandomGuesser; @@ -118,20 +121,28 @@ if (args.length > 1 && args[0].equals("-q")) inQueryMode = true; - // create logger (a simple logger which outputs + // create loggers (a simple logger which outputs // its messages to the console and a log file) - SimpleLayout layout = new SimpleLayout(); + // logger 1 is the console, where we print only info messages; + // the logger is plain, i.e. does not output log level etc. + Layout layout = new PatternLayout(); ConsoleAppender consoleAppender = new ConsoleAppender(layout); + consoleAppender.setThreshold(Level.INFO); + + // logger 2 is writes to a file; it records all debug messages + // and includes the log level + Layout layout2 = new SimpleLayout(); FileAppender fileAppenderNormal = null; File f = new File("log/sparql.txt"); try { - fileAppenderNormal = new FileAppender(layout, "log/log.txt", false); + fileAppenderNormal = new FileAppender(layout2, "log/log.txt", false); f.delete(); f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } +// fileAppenderNormal.setThreshold(Level.DEBUG); logger.removeAllAppenders(); logger.addAppender(consoleAppender); Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-08-20 11:21:37 UTC (rev 1105) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-08-20 12:13:48 UTC (rev 1106) @@ -222,7 +222,7 @@ } long dematDuration = System.currentTimeMillis() - dematStartTime; - logger.info("TBox dematerialised in " + dematDuration + " ms"); + logger.debug("TBox dematerialised in " + dematDuration + " ms"); } catch (ReasoningMethodUnsupportedException e) { throw new ComponentInitException( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |