From: <jen...@us...> - 2011-08-11 14:34:12
|
Revision: 3036 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3036&view=rev Author: jenslehmann Date: 2011-08-11 14:34:06 +0000 (Thu, 11 Aug 2011) Log Message: ----------- improvements of 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 14:33:45 UTC (rev 3035) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 14:34:06 UTC (rev 3036) @@ -156,53 +156,11 @@ } else { if(resource instanceof ObjectProperty) { for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { - AxiomLearningAlgorithm learner = algorithmClass.getConstructor( - SparqlEndpointKS.class).newInstance(ks); - ConfigHelper.configure(learner, "propertyToDescribe", resource); - ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); - learner.init(); - String algName = ComponentManager.getName(learner); - System.out.print("Applying " + algName + " on " + resource + " ... "); - long startTime = System.currentTimeMillis(); - try { - learner.start(); - } catch (Exception e) { - e.printStackTrace(); - if(e.getCause() instanceof SocketTimeoutException){ - System.out.println("Query timed out (endpoint possibly too slow)."); - } - } - long runtime = System.currentTimeMillis() - startTime; - System.out.println("done in " + runtime + "ms"); - List<EvaluatedAxiom> learnedAxioms = learner - .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - System.out.println(prettyPrint(learnedAxioms)); + applyLearningAlgorithm(algorithmClass, ks); } } else if(resource instanceof DatatypeProperty) { for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { - AxiomLearningAlgorithm learner = algorithmClass.getConstructor( - SparqlEndpointKS.class).newInstance(ks); - ConfigHelper.configure(learner, "propertyToDescribe", resource); - ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); - learner.init(); - String algName = ComponentManager.getName(learner); - System.out.print("Applying " + algName + " on " + resource + " ... "); - long startTime = System.currentTimeMillis(); - try { - learner.start(); - } catch (Exception e) { - e.printStackTrace(); - if(e.getCause() instanceof SocketTimeoutException){ - System.out.println("Query timed out (endpoint possibly too slow)."); - } - } - long runtime = System.currentTimeMillis() - startTime; - System.out.println("done in " + runtime + "ms"); - List<EvaluatedAxiom> learnedAxioms = learner - .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - System.out.println(prettyPrint(learnedAxioms)); + applyLearningAlgorithm(algorithmClass, ks); } } else if(resource instanceof NamedClass) { throw new Error("not implemented"); @@ -212,10 +170,36 @@ } } + private List<EvaluatedAxiom> applyLearningAlgorithm(Class<? extends AxiomLearningAlgorithm> algorithmClass, SparqlEndpointKS ks) throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { + AxiomLearningAlgorithm learner = algorithmClass.getConstructor( + SparqlEndpointKS.class).newInstance(ks); + ConfigHelper.configure(learner, "propertyToDescribe", resource); + ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", + maxExecutionTimeInSeconds); + learner.init(); + String algName = ComponentManager.getName(learner); + System.out.print("Applying " + algName + " on " + resource + " ... "); + long startTime = System.currentTimeMillis(); + try { + learner.start(); + } catch (Exception e) { + e.printStackTrace(); + if(e.getCause() instanceof SocketTimeoutException){ + System.out.println("Query timed out (endpoint possibly too slow)."); + } + } + long runtime = System.currentTimeMillis() - startTime; + System.out.println("done in " + runtime + "ms"); + List<EvaluatedAxiom> learnedAxioms = learner + .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + System.out.println(prettyPrint(learnedAxioms)); + return learnedAxioms; + } + private String prettyPrint(List<EvaluatedAxiom> learnedAxioms) { String str = "suggested axioms and their score in percent:\n"; if(learnedAxioms.isEmpty()) { - return "no axiom suggested"; + return " no axiom suggested"; } else { for (EvaluatedAxiom learnedAxiom : learnedAxioms) { str += " " + prettyPrint(learnedAxiom) + "\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |