From: <jen...@us...> - 2011-08-11 12:56:51
|
Revision: 3031 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3031&view=rev Author: jenslehmann Date: 2011-08-11 12:56:45 +0000 (Thu, 11 Aug 2011) Log Message: ----------- improved formatting in enrichment script Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 11:40:11 UTC (rev 3030) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 12:56:45 UTC (rev 3031) @@ -26,6 +26,7 @@ import java.net.SocketTimeoutException; import java.net.URI; import java.net.URL; +import java.text.DecimalFormat; import java.util.LinkedList; import java.util.List; @@ -81,6 +82,7 @@ public class Enrichment { private static Logger logger = Logger.getLogger(Enrichment.class); + private DecimalFormat df = new DecimalFormat("##0.0"); // enrichment parameters private SparqlEndpoint se; @@ -161,7 +163,7 @@ maxExecutionTimeInSeconds); learner.init(); String algName = ComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + resource + " ... "); + System.out.print("Applying " + algName + " on " + resource + " ... "); long startTime = System.currentTimeMillis(); try { learner.start(); @@ -172,12 +174,10 @@ } } long runtime = System.currentTimeMillis() - startTime; - System.out.println("runtime: " + runtime + "ms"); + System.out.println("done in " + runtime + "ms"); List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - for (EvaluatedAxiom learnedAxiom : learnedAxioms) { - System.out.println("suggested axiom: " + learnedAxiom); - } + System.out.println(prettyPrint(learnedAxioms)); } } else if(resource instanceof DatatypeProperty) { for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { @@ -188,7 +188,7 @@ maxExecutionTimeInSeconds); learner.init(); String algName = ComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + resource + " ... "); + System.out.print("Applying " + algName + " on " + resource + " ... "); long startTime = System.currentTimeMillis(); try { learner.start(); @@ -199,12 +199,10 @@ } } long runtime = System.currentTimeMillis() - startTime; - System.out.println("runtime: " + runtime + "ms"); + System.out.println("done in " + runtime + "ms"); List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - for (EvaluatedAxiom learnedAxiom : learnedAxioms) { - System.out.println("suggested axiom: " + learnedAxiom); - } + System.out.println(prettyPrint(learnedAxioms)); } } else if(resource instanceof NamedClass) { throw new Error("not implemented"); @@ -214,13 +212,34 @@ } } + private String prettyPrint(List<EvaluatedAxiom> learnedAxioms) { + String str = "suggested axioms and their score in percent:\n"; + if(learnedAxioms.isEmpty()) { + return "no axiom suggested"; + } else { + for (EvaluatedAxiom learnedAxiom : learnedAxioms) { + str += " " + prettyPrint(learnedAxiom) + "\n"; + } + } + return str; + } + + private String prettyPrint(EvaluatedAxiom axiom) { + double acc = axiom.getScore().getAccuracy() * 100; + String accs = df.format(acc); + if(acc<10d) { accs = " " + accs; } + if(acc<100d) { accs = " " + accs; } + String str = accs + "%\t" + axiom.getAxiom().toManchesterSyntaxString(null, prefixes); + return str; + } + public static void main(String[] args) throws IOException, ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { SimpleLayout layout = new SimpleLayout(); ConsoleAppender consoleAppender = new ConsoleAppender(layout); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.setLevel(Level.WARN); + Logger.getRootLogger().removeAllAppenders(); + Logger.getRootLogger().addAppender(consoleAppender); + Logger.getRootLogger().setLevel(Level.WARN); OptionParser parser = new OptionParser(); parser.acceptsAll(asList("h", "?", "help"), "Show help."); @@ -277,6 +296,10 @@ } } + if(!options.hasArgument("endpoint")) { + System.out.println("Please specify a SPARQL endpoint (using the -e option)."); + } + boolean verbose = (Boolean) options.valueOf("v"); Enrichment e = new Enrichment(se, resource, verbose); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |