From: <jen...@us...> - 2009-05-18 15:38:42
|
Revision: 1755 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1755&view=rev Author: jenslehmann Date: 2009-05-18 15:38:38 +0000 (Mon, 18 May 2009) Log Message: ----------- continued class matching ASK queries now work in combination with cache Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/scripts/matching/LearnOSMClasses.java trunk/src/dl-learner/org/dllearner/scripts/matching/Utility.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-05-18 14:15:08 UTC (rev 1754) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-05-18 15:38:38 UTC (rev 1755) @@ -36,7 +36,6 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.CELOEConfigurator; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.owl.ClassHierarchy; @@ -124,7 +123,7 @@ private int maxHorizExp = 0; @Override - public Configurator getConfigurator() { + public CELOEConfigurator getConfigurator() { return configurator; } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2009-05-18 14:15:08 UTC (rev 1754) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2009-05-18 15:38:38 UTC (rev 1755) @@ -312,6 +312,19 @@ return result; } + public boolean executeSparqlAskQuery(SparqlQuery query) { + String str = getCacheEntry(query.getSparqlQueryString()); + JamonMonitorLogger.increaseCount(Cache.class, "TotalQueries"); + if(str != null) { + JamonMonitorLogger.increaseCount(Cache.class, "SuccessfulHits"); + return Boolean.parseBoolean(str); + } else { + Boolean result = query.sendAsk(); + addToCache(query.getSparqlQueryString(), result.toString()); + return result; + } + } + /** * deletes all Files in the cacheDir, does not delete the cacheDir itself, * and can thus still be used without creating a new Cache Object Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2009-05-18 14:15:08 UTC (rev 1754) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2009-05-18 15:38:38 UTC (rev 1755) @@ -507,6 +507,15 @@ return jsonString; } + public boolean ask(String askQueryString) { + if(cache == null) { + SparqlQuery sq = new SparqlQuery(askQueryString, sparqlEndpoint); + return sq.sendAsk(); + } else { + return cache.executeSparqlAskQuery(new SparqlQuery(askQueryString, sparqlEndpoint)); + } + } + /** * a String Helper which constructs the limit clause of a sparql query. if * sparqlResultLimit is zero, returns nothing Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java 2009-05-18 14:15:08 UTC (rev 1754) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java 2009-05-18 15:38:38 UTC (rev 1755) @@ -31,6 +31,7 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.configurators.PosNegLPStandardConfigurator; import org.dllearner.core.configurators.PosOnlyLPConfigurator; import org.dllearner.core.options.CommonConfigMappings; import org.dllearner.core.options.ConfigEntry; @@ -66,6 +67,7 @@ public PosOnlyLP(ReasonerComponent reasoningService) { super(reasoningService); + configurator = new PosOnlyLPConfigurator(this); } /* Modified: trunk/src/dl-learner/org/dllearner/scripts/matching/LearnOSMClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/matching/LearnOSMClasses.java 2009-05-18 14:15:08 UTC (rev 1754) +++ trunk/src/dl-learner/org/dllearner/scripts/matching/LearnOSMClasses.java 2009-05-18 15:38:38 UTC (rev 1755) @@ -29,12 +29,14 @@ import java.util.zip.DataFormatException; import org.dllearner.algorithms.celoe.CELOE; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; +import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.reasoning.FastInstanceChecker; @@ -51,11 +53,11 @@ private static SparqlEndpoint dbpediaEndpoint = SparqlEndpoint.getEndpointLOCALDBpedia(); private static SparqlEndpoint geoDataEndpoint = SparqlEndpoint.getEndpointLOCALGeoData(); - public static void main(String args[]) throws IOException, DataFormatException, LearningProblemUnsupportedException { + public static void main(String args[]) throws IOException, DataFormatException, LearningProblemUnsupportedException, ComponentInitException { File matchesFile = new File("log/geodata/owlsameas_en.dat"); Map<URI,URI> matches = Utility.getMatches(matchesFile); -// SPARQLTasks st = new SPARQLTasks(dbpediaEndpoint); + SPARQLTasks dbpedia = new SPARQLTasks(new Cache("cache/matching"),dbpediaEndpoint); Set<String> positives = new TreeSet<String>(); Set<String> negatives = new TreeSet<String>(); @@ -65,8 +67,8 @@ URI lgdURI = match.getValue(); // test whether the dbpediaURI is a city String query = "ASK {<"+dbpediaURI+"> a <http://dbpedia.org/ontology/City>}"; - SparqlQuery sq = new SparqlQuery(query, dbpediaEndpoint); - boolean isCity = sq.sendAsk(); + boolean isCity = dbpedia.ask(query); +// System.out.println(isCity + " " + lgdURI); if(isCity) { positives.add(lgdURI.toString()); } else { @@ -78,18 +80,31 @@ instances.addAll(positives); instances.addAll(negatives); + System.out.println(instances.size() + " instances - " + positives.size() + " positive examples"); + // plug together DL-Learner components ComponentManager cm = ComponentManager.getInstance(); + SparqlKnowledgeSource ks = cm.knowledgeSource(SparqlKnowledgeSource.class); ks.getConfigurator().setInstances(instances); ks.getConfigurator().setPredefinedEndpoint("LOCALGEODATA"); + ks.getConfigurator().setSaveExtractedFragment(true); + ks.init(); + ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, ks); + reasoner.init(); + PosOnlyLP lp = cm.learningProblem(PosOnlyLP.class, reasoner); lp.getConfigurator().setPositiveExamples(positives); - CELOE algorithm = cm.learningAlgorithm(CELOE.class, lp, reasoner); + lp.init(); + CELOE celoe = cm.learningAlgorithm(CELOE.class, lp, reasoner); + celoe.getConfigurator().setUseHasValueConstructor(true); + celoe.getConfigurator().setValueFrequencyThreshold(3); + celoe.init(); + // execute algorithm - algorithm.start(); + celoe.start(); // Set<EvaluatedDescriptionPosOnly> solutions = (Set<EvaluatedDescriptionPosOnly>) algorithm.getCurrentlyBestEvaluatedDescriptions(); } Modified: trunk/src/dl-learner/org/dllearner/scripts/matching/Utility.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/matching/Utility.java 2009-05-18 14:15:08 UTC (rev 1754) +++ trunk/src/dl-learner/org/dllearner/scripts/matching/Utility.java 2009-05-18 15:38:38 UTC (rev 1755) @@ -28,6 +28,8 @@ import java.util.Map; import java.util.zip.DataFormatException; +import org.apache.log4j.Logger; + /** * Utility methods for creating/optimising matches between knowledge bases. * @@ -36,6 +38,8 @@ */ public final class Utility { + private static Logger logger = Logger.getLogger(Utility.class); + /** * Reads in a file containing known matches between knowledge bases. * @@ -59,9 +63,13 @@ if(tmp.length != 2) { throw new DataFormatException("Line " + lineCount + " incorrectly formatted."); } +// if(matches.containsKey(URI.create(tmp[1]))) { +// logger.warn("multiple key " + tmp[1] + " ... ignoring all but one value"); +// } matches.put(URI.create(tmp[1]), URI.create(tmp[0] + "#id")); lineCount++; } + logger.info("read " + lineCount + " lines"); return matches; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |