From: <lor...@us...> - 2012-04-30 09:04:18
|
Revision: 3669 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3669&view=rev Author: lorenz_b Date: 2012-04-30 09:04:11 +0000 (Mon, 30 Apr 2012) Log Message: ----------- Changed some queries. Set timeout to remaining execution time, so all algorithms should hopefully terminate after the given runtime independently from the endpoint runtime. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -97,7 +97,7 @@ while(newModel.size() != 0){ model.add(newModel); // get number of instances of s with <s p o> - query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -106,7 +106,7 @@ qs = rs.next(); total = qs.getLiteral("total").getInt(); } - query = "SELECT (COUNT(?s) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s.}"; + query = "SELECT (COUNT(*) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int symmetric = 0; @@ -128,7 +128,7 @@ } private void runSPARQL1_1_Mode(){ - String query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + String query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -137,7 +137,7 @@ qs = rs.next(); total = qs.getLiteral("total").getInt(); } - query = "SELECT (COUNT(?s) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s.}"; + query = "SELECT (COUNT(*) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int symmetric = 0; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -213,8 +213,9 @@ } public static void main(String[] args) throws Exception{ - DisjointObjectPropertyAxiomLearner l = new DisjointObjectPropertyAxiomLearner(new SparqlEndpointKS(new SparqlEndpoint( - new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())));//.getEndpointDBpediaLiveAKSW())); + SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); +// endpoint = new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); + DisjointObjectPropertyAxiomLearner l = new DisjointObjectPropertyAxiomLearner(new SparqlEndpointKS(endpoint));//.getEndpointDBpediaLiveAKSW())); l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/stateOfOrigin")); l.setMaxExecutionTimeInSeconds(10); l.init(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -116,7 +116,7 @@ offset += limit; - query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); newModel = executeConstructQuery(query); } @@ -184,7 +184,7 @@ public static void main(String[] args) throws Exception{ EquivalentDataPropertyAxiomLearner l = new EquivalentDataPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/birthDate")); - l.setMaxExecutionTimeInSeconds(100); + l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -110,7 +110,7 @@ all = qs.getLiteral("all").getInt(); } // get number of instances of s with <s p o> <s p o1> where o != o1 - query = "SELECT (COUNT(DISTINCT ?s1) AS ?noninversefunctional) WHERE {?s1 <%s> ?o. ?s2 <%s> ?o. FILTER(?s1 != ?s2) }"; + query = "SELECT (COUNT(DISTINCT ?o) AS ?noninversefunctional) WHERE {?s1 <%s> ?o. ?s2 <%s> ?o. FILTER(?s1 != ?s2) }"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int notInverseFunctional = 1; @@ -148,7 +148,7 @@ all = qs.getLiteral("all").getInt(); } // get number of instances of s with <s p o> <s p o1> where o != o1 - query = "SELECT (COUNT(DISTINCT ?s1) AS ?noninversefunctional) WHERE {?s1 <%s> ?o. ?s2 <%s> ?o. FILTER(?s1 != ?s2) }"; + query = "SELECT (COUNT(DISTINCT ?o) AS ?noninversefunctional) WHERE {?s1 <%s> ?o. ?s2 <%s> ?o. FILTER(?s1 != ?s2) }"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int notInverseFunctional = 1; @@ -168,8 +168,7 @@ } public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint( - new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); InverseFunctionalObjectPropertyAxiomLearner l = new InverseFunctionalObjectPropertyAxiomLearner(ks); l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/profession")); l.setMaxExecutionTimeInSeconds(10); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -96,7 +96,7 @@ while(newModel.size() != 0){ model.add(newModel); // get number of instances of s with <s p o> - query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -106,7 +106,7 @@ total = qs.getLiteral("total").getInt(); } - query = String.format("SELECT ?p (COUNT(?s) AS ?cnt) WHERE {?s <%s> ?o. ?o ?p ?s.} GROUP BY ?p", propertyToDescribe.getName()); + query = String.format("SELECT ?p (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o. ?o ?p ?s.} GROUP BY ?p", propertyToDescribe.getName()); rs = executeSelectQuery(query); while(rs.hasNext()){ qs = rs.next(); @@ -121,7 +121,7 @@ } private void runSPARQL1_1_Mode(){ - String query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + String query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -131,7 +131,7 @@ total = qs.getLiteral("total").getInt(); } - query = String.format("SELECT ?p (COUNT(?s) AS ?cnt) WHERE {?s <%s> ?o. ?o ?p ?s.} GROUP BY ?p", propertyToDescribe.getName()); + query = String.format("SELECT ?p (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o. ?o ?p ?s.} GROUP BY ?p", propertyToDescribe.getName()); rs = executeSelectQuery(query); while(rs.hasNext()){ qs = rs.next(); @@ -146,14 +146,10 @@ SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint( new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()));//.getEndpointDBpediaLiveAKSW())); - SPARQLReasoner reasoner = new SPARQLReasoner(ks); - reasoner.prepareSubsumptionHierarchy(); - InverseObjectPropertyAxiomLearner l = new InverseObjectPropertyAxiomLearner(ks); - l.setReasoner(reasoner); l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/officialLanguage")); - l.setMaxExecutionTimeInSeconds(10); + l.setMaxExecutionTimeInSeconds(100); // l.setReturnOnlyNewAxioms(true); l.init(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -97,7 +97,7 @@ while(newModel.size() != 0){ model.add(newModel); // get fraction of instances s with <s p s> - query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = "SELECT (COUNT(DISTINCT ?s) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -106,7 +106,7 @@ qs = rs.next(); total = qs.getLiteral("total").getInt(); } - query = "SELECT (COUNT(?s) AS ?reflexive) WHERE {?s <%s> ?s.}"; + query = "SELECT (COUNT(DISTINCT ?s) AS ?reflexive) WHERE {?s <%s> ?s.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int reflexive = 0; @@ -130,7 +130,7 @@ private void runSPARQL1_1_Mode() { // get fraction of instances s with <s p s> - String query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + String query = "SELECT (COUNT(DISTINCT ?s) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -139,7 +139,7 @@ qs = rs.next(); total = qs.getLiteral("total").getInt(); } - query = "SELECT (COUNT(?s) AS ?reflexive) WHERE {?s <%s> ?s.}"; + query = "SELECT (COUNT(DISTINCT ?s) AS ?reflexive) WHERE {?s <%s> ?s.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int reflexive = 0; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -96,7 +96,7 @@ while(newModel.size() != 0){ model.add(newModel); // get number of instances of s with <s p o> - query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -105,7 +105,7 @@ qs = rs.next(); total = qs.getLiteral("total").getInt(); } - query = "SELECT (COUNT(?s) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s}"; + query = "SELECT (COUNT(*) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int symmetric = 0; @@ -127,7 +127,7 @@ } private void runSPARQL1_1_Mode(){ - String query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + String query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -136,7 +136,7 @@ qs = rs.next(); total = qs.getLiteral("total").getInt(); } - query = "SELECT (COUNT(?s) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s}"; + query = "SELECT (COUNT(*) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int symmetric = 0; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -98,7 +98,7 @@ while(newModel.size() != 0){ model.add(newModel); // get number of instances of s with <s p o> - query = "SELECT (COUNT(?o) AS ?total) WHERE {?s <%s> ?o. ?o <%s> ?o1.}"; + query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o. ?o <%s> ?o1.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -107,7 +107,7 @@ qs = rs.next(); total = qs.getLiteral("total").getInt(); } - query = "SELECT (COUNT(?o) AS ?transitive) WHERE {?s <%s> ?o. ?o <%s> ?o1. ?s <%s> ?o1.}"; + query = "SELECT (COUNT(*) AS ?transitive) WHERE {?s <%s> ?o. ?o <%s> ?o1. ?s <%s> ?o1.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int transitive = 0; @@ -128,7 +128,7 @@ } private void runSPARQL1_1_Mode(){ - String query = "SELECT (COUNT(?o) AS ?total) WHERE {?s <%s> ?o. ?o <%s> ?o1.}"; + String query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o. ?o <%s> ?o1.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -137,7 +137,7 @@ qs = rs.next(); total = qs.getLiteral("total").getInt(); } - query = "SELECT (COUNT(?o) AS ?transitive) WHERE {?s <%s> ?o. ?o <%s> ?o1. ?s <%s> ?o1.}"; + query = "SELECT (COUNT(*) AS ?transitive) WHERE {?s <%s> ?o. ?o <%s> ?o1. ?s <%s> ?o1.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int transitive = 0; Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-04-29 18:39:37 UTC (rev 3668) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-04-30 09:04:11 UTC (rev 3669) @@ -19,6 +19,7 @@ package org.dllearner.core; +import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -53,7 +54,10 @@ import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; +import com.hp.hpl.jena.sparql.resultset.ResultSetMem; import com.hp.hpl.jena.util.iterator.Filter; import com.hp.hpl.jena.vocabulary.OWL2; import com.hp.hpl.jena.vocabulary.RDF; @@ -221,10 +225,19 @@ SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + queryExecution.setTimeout(getRemainingRuntimeInMilliSeconds()); queryExecution.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); queryExecution.setNamedGraphURIs(endpoint.getNamedGraphURIs()); - return queryExecution.execConstruct(); + try { + return queryExecution.execConstruct(); + } catch (QueryExceptionHTTP e) { + if(e.getCause() instanceof SocketTimeoutException){ + logger.warn("Got timeout", e); + } else { + logger.error("Exception executing query", e); + } + return ModelFactory.createDefaultModel(); + } } else { QueryExecution qexec = QueryExecutionFactory.create(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); return qexec.execConstruct(); @@ -237,10 +250,19 @@ SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + queryExecution.setTimeout(getRemainingRuntimeInMilliSeconds()); queryExecution.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); queryExecution.setNamedGraphURIs(endpoint.getNamedGraphURIs()); - return queryExecution.execSelect(); + try { + return queryExecution.execSelect(); + } catch (QueryExceptionHTTP e) { + if(e.getCause() instanceof SocketTimeoutException){ + logger.warn("Got timeout", e); + } else { + logger.error("Exception executing query", e); + } + return new ResultSetMem(); + } } else { return executeSelectQuery(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); } @@ -280,8 +302,12 @@ return entries; } + private long getRemainingRuntimeInMilliSeconds(){ + return Math.max(0, (maxExecutionTimeInSeconds * 1000) - (System.currentTimeMillis() - startTime)); + } + protected boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : getRemainingRuntimeInMilliSeconds() <= 0; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; return timeLimitExceeded || resultLimitExceeded; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |