From: <lor...@us...> - 2011-09-08 09:30:00
|
Revision: 3245 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3245&view=rev Author: lorenz_b Date: 2011-09-08 09:29:51 +0000 (Thu, 08 Sep 2011) Log Message: ----------- Provided support for inference. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-07 17:09:48 UTC (rev 3244) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-08 09:29:51 UTC (rev 3245) @@ -78,6 +78,7 @@ private static final Logger logger = LoggerFactory.getLogger(SPARQLReasoner.class); private SparqlEndpointKS ks; + private ClassHierarchy hierarchy; public SPARQLReasoner(SparqlEndpointKS ks) { this.ks = ks; @@ -120,7 +121,8 @@ subsumptionHierarchyUp.put(atom, tmp); } logger.info("... done in {}ms", (System.currentTimeMillis()-startTime)); - return new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); + hierarchy = new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); + return hierarchy; } public Model loadSchema(){ Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-07 17:09:48 UTC (rev 3244) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-08 09:29:51 UTC (rev 3245) @@ -73,6 +73,7 @@ import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.AxiomLearningAlgorithm; @@ -189,6 +190,9 @@ private int nrOfAxiomsToLearn = 10; private double threshold = 0.7; + private boolean useInference; + private SPARQLReasoner reasoner; + // lists of algorithms to apply private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; @@ -203,11 +207,12 @@ SparqlKnowledgeSource ksCached; AbstractReasonerComponent rcCached; - public Enrichment(SparqlEndpoint se, Entity resource, double threshold, boolean verbose) { + public Enrichment(SparqlEndpoint se, Entity resource, double threshold, boolean useInference, boolean verbose) { this.se = se; this.resource = resource; this.verbose = verbose; this.threshold = threshold; + this.useInference = useInference; objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); @@ -251,6 +256,14 @@ SparqlEndpointKS ks = new SparqlEndpointKS(se); ks.init(); + if(useInference){ + reasoner = new SPARQLReasoner(ks); + System.out.print("Precomputing subsumption hierarchy ... "); + long startTime = System.currentTimeMillis(); + reasoner.prepareSubsumptionHierarchy(); + System.out.println("done in " + (System.currentTimeMillis() - startTime) + " ms"); + } + // common helper objects SPARQLTasks st = new SPARQLTasks(se); @@ -424,16 +437,20 @@ ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); learner.init(); + if(reasoner != null){ + ((AbstractAxiomLearningAlgorithm)learner).setReasoner(reasoner); + } String algName = AnnComponentManager.getName(learner); System.out.print("Applying " + algName + " on " + entity + " ... "); 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)."); - } + } else { + e.printStackTrace(); + } } long runtime = System.currentTimeMillis() - startTime; System.out.println("done in " + runtime + " ms"); @@ -727,6 +744,7 @@ System.exit(0); } + boolean useInference = (Boolean) options.valueOf("i"); // boolean verbose = (Boolean) options.valueOf("v"); double threshold = (Double) options.valueOf("t"); @@ -739,7 +757,7 @@ System.setOut(printStream); } - Enrichment e = new Enrichment(se, resource, threshold, false); + Enrichment e = new Enrichment(se, resource, threshold, useInference, false); e.start(); SparqlEndpointKS ks = new SparqlEndpointKS(se); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |