From: <lor...@us...> - 2011-08-25 08:52:39
|
Revision: 3120 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3120&view=rev Author: lorenz_b Date: 2011-08-25 08:52:30 +0000 (Thu, 25 Aug 2011) Log Message: ----------- Some code cleanup. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.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/EquivalentObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.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/config/ConfigHelper.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -20,20 +20,17 @@ package org.dllearner.algorithms; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.SortedSet; import java.util.TreeSet; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ClassExpressionLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.config.ConfigOption; @@ -44,11 +41,9 @@ import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,14 +65,9 @@ @ConfigOption(name="classToDescribe", description="", propertyEditorClass=NamedClassEditor.class) private NamedClass classToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedDescription> currentlyBestEvaluatedDescriptions; private long startTime; private int fetchedRows; @@ -137,7 +127,7 @@ while(!terminationCriteriaSatisfied() && repeat){ query = String.format(queryTemplate, classToDescribe, limit, offset); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; repeat = false; while(rs.hasNext()){ @@ -161,13 +151,7 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - } - - @Override public List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions) { List<Description> bestDescriptions = new ArrayList<Description>(); for(EvaluatedDescription evDesc : getCurrentlyBestEvaluatedDescriptions(nrOfDescriptions)){ @@ -236,52 +220,12 @@ return evalDescs; } - /* - * Returns the entries of the map sorted by value. - */ - private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ - SortedSet<Entry<NamedClass, Integer>> sortedSet = new TreeSet<Map.Entry<NamedClass,Integer>>(new Comparator<Entry<NamedClass, Integer>>() { - - @Override - public int compare(Entry<NamedClass, Integer> value1, Entry<NamedClass, Integer> value2) { - if(value1.getValue() > value2.getValue()){ - return 1; - } else if(value2.getValue() > value1.getValue()){ - return -1; - } else { - return value1.getKey().compareTo(value2.getKey()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } - private boolean terminationCriteriaSatisfied(){ boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; return timeLimitExceeded || resultLimitExceeded; } - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } - public static void main(String[] args) throws Exception{ DisjointClassesLearner l = new DisjointClassesLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/SoccerClub")); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -20,7 +20,6 @@ package org.dllearner.algorithms; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,9 +30,9 @@ import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ClassExpressionLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.config.ConfigHelper; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.NamedClassEditor; @@ -45,9 +44,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,14 +65,9 @@ @ConfigOption(name="classToDescribe", required=true, description="", propertyEditorClass=NamedClassEditor.class) private NamedClass classToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", defaultValue="10", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedDescription> currentlyBestEvaluatedDescriptions; private long startTime; private int fetchedRows; @@ -146,19 +138,6 @@ logger.info("...finished in {}ms. (Got {} rows)", (System.currentTimeMillis()-startTime), fetchedRows); } - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - } - - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public NamedClass getClassToDescribe() { return classToDescribe; } @@ -180,7 +159,7 @@ String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind a <%s>} LIMIT %d OFFSET %d}}", classToDescribe.getName(), limit, offset); - ResultSet rs = new SparqlQuery(query, ks.getEndpoint()).send(); + ResultSet rs = executeSelectQuery(query); Individual ind; NamedClass newType; QuerySolution qs; @@ -228,24 +207,6 @@ } - private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ - SortedSet<Entry<NamedClass, Integer>> sortedSet = new TreeSet<Map.Entry<NamedClass,Integer>>(new Comparator<Entry<NamedClass, Integer>>() { - - @Override - public int compare(Entry<NamedClass, Integer> value1, Entry<NamedClass, Integer> value2) { - if(value1.getValue() < value2.getValue()){ - return 1; - } else if(value2.getValue() < value1.getValue()){ - return -1; - } else { - return value1.getKey().compareTo(value2.getKey()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } - private double computeScore(){ return 0; } @@ -258,7 +219,8 @@ public static void main(String[] args) throws Exception{ SimpleSubclassLearner l = new SimpleSubclassLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/SoccerClub")); + ConfigHelper.configure(l, "maxExecutionTimeInSeconds", 5); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Criminal")); l.init(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -20,7 +20,6 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,22 +29,18 @@ import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyDomainAxiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,14 +54,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -75,14 +65,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public DatatypeProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -127,18 +109,6 @@ return currentlyBestAxioms; } - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - - } - private boolean terminationCriteriaSatisfied(){ boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; @@ -170,33 +140,12 @@ return axioms; } - /* - * Returns the entries of the map sorted by value. - */ - private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ - SortedSet<Entry<NamedClass, Integer>> sortedSet = new TreeSet<Map.Entry<NamedClass,Integer>>(new Comparator<Entry<NamedClass, Integer>>() { - - @Override - public int compare(Entry<NamedClass, Integer> value1, Entry<NamedClass, Integer> value2) { - if(value1.getValue() < value2.getValue()){ - return 1; - } else if(value2.getValue() < value1.getValue()){ - return -1; - } else { - return value1.getKey().compareTo(value2.getKey()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } - private int addIndividualsWithTypes(Map<Individual, SortedSet<NamedClass>> ind2Types, int limit, int offset){ String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); // String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind <%s> ?o.} LIMIT %d OFFSET %d}}", propertyToDescribe.getName(), limit, offset); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); Individual ind; NamedClass newType; QuerySolution qs; @@ -217,24 +166,6 @@ return cnt; } - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } - public static void main(String[] args) throws Exception{ DataPropertyDomainAxiomLearner l = new DataPropertyDomainAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/AutomobileEngine/height")); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -20,9 +20,7 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -31,22 +29,17 @@ import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; -import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyRangeAxiom; import org.dllearner.core.owl.Individual; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,14 +53,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -76,14 +64,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public DatatypeProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -128,18 +108,6 @@ return currentlyBestAxioms; } - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - - } - private boolean terminationCriteriaSatisfied(){ boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; @@ -171,31 +139,11 @@ return axioms; } - /* - * Returns the entries of the map sorted by value. - */ - private SortedSet<Entry<Datatype, Integer>> sortByValues(Map<Datatype, Integer> map){ - SortedSet<Entry<Datatype, Integer>> sortedSet = new TreeSet<Map.Entry<Datatype,Integer>>(new Comparator<Entry<Datatype, Integer>>() { - - @Override - public int compare(Entry<Datatype, Integer> value1, Entry<Datatype, Integer> value2) { - if(value1.getValue() < value2.getValue()){ - return 1; - } else if(value2.getValue() < value1.getValue()){ - return -1; - } else { - return value1.getKey().getURI().compareTo(value2.getKey().getURI()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } private int addIndividualsWithTypes(Map<Individual, SortedSet<Datatype>> ind2Datatypes, int limit, int offset){ String query = String.format("SELECT ?ind, (DATATYPE(?val) AS ?datatype) WHERE {?ind <%s> ?val.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); Individual ind; Datatype newType; QuerySolution qs; @@ -216,22 +164,4 @@ return cnt; } - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } - } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -20,30 +20,24 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DisjointDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,14 +51,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -73,14 +62,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public DatatypeProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -107,7 +88,7 @@ //TODO //at first get all existing dataproperties in knowledgebase - Set<DatatypeProperty> dataProperties = getAllDataProperties(); + Set<DatatypeProperty> dataProperties = new SPARQLTasks(ks.getEndpoint()).getAllDataProperties(); //get properties and how often they occur int limit = 1000; @@ -123,7 +104,7 @@ while(!terminationCriteriaSatisfied() && repeat){ query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; repeat = false; while(rs.hasNext()){ @@ -152,18 +133,6 @@ return currentlyBestAxioms; } - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - - } - private List<EvaluatedAxiom> buildAxioms(Map<DatatypeProperty, Integer> property2Count, Set<DatatypeProperty> allProperties){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Integer all = property2Count.get(propertyToDescribe); @@ -188,67 +157,12 @@ return axioms; } - /* - * Returns the entries of the map sorted by value. - */ - private SortedSet<Entry<DatatypeProperty, Integer>> sortByValues(Map<DatatypeProperty, Integer> map){ - SortedSet<Entry<DatatypeProperty, Integer>> sortedSet = new TreeSet<Map.Entry<DatatypeProperty,Integer>>(new Comparator<Entry<DatatypeProperty, Integer>>() { - - @Override - public int compare(Entry<DatatypeProperty, Integer> value1, Entry<DatatypeProperty, Integer> value2) { - if(value1.getValue() > value2.getValue()){ - return 1; - } else if(value2.getValue() > value1.getValue()){ - return -1; - } else { - return value1.getKey().compareTo(value2.getKey()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } - private boolean terminationCriteriaSatisfied(){ boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; return timeLimitExceeded || resultLimitExceeded; } - private Set<DatatypeProperty> getAllDataProperties() { - Set<DatatypeProperty> properties = new TreeSet<DatatypeProperty>(); - String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:DatatypeProperty}"; - - ResultSet q = executeQuery(query); - while (q.hasNext()) { - QuerySolution qs = q.next(); - properties.add(new DatatypeProperty(qs.getResource("p").getURI())); - } - //remove property to describe - properties.remove(propertyToDescribe); - - return properties; - } - - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } - public static void main(String[] args) throws Exception{ DisjointDataPropertyAxiomLearner l = new DisjointDataPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/maximumBoatLength")); 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 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -20,30 +20,24 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.SortedSet; import java.util.TreeSet; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.DisjointObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,14 +51,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -73,14 +62,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -124,7 +105,7 @@ while(!terminationCriteriaSatisfied() && repeat){ query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; repeat = false; while(rs.hasNext()){ @@ -153,19 +134,6 @@ return currentlyBestAxioms; } - - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - - } - private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count, Set<ObjectProperty> allProperties){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Integer all = property2Count.get(propertyToDescribe); @@ -194,51 +162,11 @@ return axioms; } - /* - * Returns the entries of the map sorted by value. - */ - private SortedSet<Entry<ObjectProperty, Integer>> sortByValues(Map<ObjectProperty, Integer> map){ - SortedSet<Entry<ObjectProperty, Integer>> sortedSet = new TreeSet<Map.Entry<ObjectProperty,Integer>>(new Comparator<Entry<ObjectProperty, Integer>>() { - - @Override - public int compare(Entry<ObjectProperty, Integer> value1, Entry<ObjectProperty, Integer> value2) { - if(value1.getValue() > value2.getValue()){ - return 1; - } else if(value2.getValue() > value1.getValue()){ - return -1; - } else { - return value1.getKey().compareTo(value2.getKey()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } - private boolean terminationCriteriaSatisfied(){ boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; return timeLimitExceeded || resultLimitExceeded; } - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } - - } 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 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -20,28 +20,22 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.SortedSet; -import java.util.TreeSet; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.EquivalentDatatypePropertiesAxiom; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,14 +49,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -71,14 +60,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public DatatypeProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -119,7 +100,7 @@ while(!terminationCriteriaSatisfied() && repeat){ query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; repeat = false; while(rs.hasNext()){ @@ -149,18 +130,6 @@ return currentlyBestAxioms; } - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - - } - private boolean terminationCriteriaSatisfied(){ boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; @@ -182,44 +151,5 @@ property2Count.put(propertyToDescribe, all); return axioms; } - - /* - * Returns the entries of the map sorted by value. - */ - private SortedSet<Entry<DatatypeProperty, Integer>> sortByValues(Map<DatatypeProperty, Integer> map){ - SortedSet<Entry<DatatypeProperty, Integer>> sortedSet = new TreeSet<Map.Entry<DatatypeProperty,Integer>>(new Comparator<Entry<DatatypeProperty, Integer>>() { - @Override - public int compare(Entry<DatatypeProperty, Integer> value1, Entry<DatatypeProperty, Integer> value2) { - if(value1.getValue() < value2.getValue()){ - return 1; - } else if(value2.getValue() < value1.getValue()){ - return -1; - } else { - return value1.getKey().compareTo(value2.getKey()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } - } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -20,7 +20,6 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -28,22 +27,17 @@ import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; -import java.util.TreeSet; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,14 +51,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -73,14 +62,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -121,7 +102,7 @@ while(!terminationCriteriaSatisfied() && repeat){ query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; repeat = false; while(rs.hasNext()){ @@ -151,18 +132,6 @@ return currentlyBestAxioms; } - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - - } - private boolean terminationCriteriaSatisfied(){ boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; @@ -189,43 +158,5 @@ return axioms; } - /* - * Returns the entries of the map sorted by value. - */ - private SortedSet<Entry<ObjectProperty, Integer>> sortByValues(Map<ObjectProperty, Integer> map){ - SortedSet<Entry<ObjectProperty, Integer>> sortedSet = new TreeSet<Map.Entry<ObjectProperty,Integer>>(new Comparator<Entry<ObjectProperty, Integer>>() { - @Override - public int compare(Entry<ObjectProperty, Integer> value1, Entry<ObjectProperty, Integer> value2) { - if(value1.getValue() < value2.getValue()){ - return 1; - } else if(value2.getValue() < value1.getValue()){ - return -1; - } else { - return value1.getKey().compareTo(value2.getKey()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } - } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -24,24 +24,19 @@ import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.FunctionalDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="functional dataproperty axiom learner", shortName="dplfunc", version=0.1) @@ -51,14 +46,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -68,14 +58,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public DatatypeProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -108,7 +90,7 @@ //get number of instances of s with <s p o> query = String.format("SELECT (COUNT(DISTINCT ?s)) AS ?all WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; int all = 1; while(rs.hasNext()){ @@ -118,7 +100,7 @@ //get number of instances of s with <s p o> <s p o1> where o != o1 query = "SELECT (COUNT(DISTINCT ?s)) AS ?notfunctional WHERE {?s <%s> ?o. ?s <%s> ?o1. FILTER(?o != ?o1) }"; query = query.replace("%s", propertyToDescribe.getURI().toString()); - rs = executeQuery(query); + rs = executeSelectQuery(query); int notFunctional = 1; while(rs.hasNext()){ qs = rs.next(); @@ -137,46 +119,4 @@ return currentlyBestAxioms; } - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - } - - private boolean executeAskQuery(String query){ - logger.info("Sending query \n {}", query); - - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - boolean result = queryExecution.execAsk(); - return result; - } - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -24,24 +24,19 @@ import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="functional objectproperty axiom learner", shortName="oplfunc", version=0.1) @@ -51,14 +46,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -68,14 +58,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -108,7 +90,7 @@ //get number of instances of s with <s p o> query = String.format("SELECT (COUNT(DISTINCT ?s)) AS ?all WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; int all = 1; while(rs.hasNext()){ @@ -118,7 +100,7 @@ //get number of instances of s with <s p o> <s p o1> where o != o1 query = "SELECT (COUNT(DISTINCT ?s)) AS ?notfunctional WHERE {?s <%s> ?o. ?s <%s> ?o1. FILTER(?o != ?o1) }"; query = query.replace("%s", propertyToDescribe.getURI().toString()); - rs = executeQuery(query); + rs = executeSelectQuery(query); int notFunctional = 1; while(rs.hasNext()){ qs = rs.next(); @@ -137,46 +119,4 @@ return currentlyBestAxioms; } - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - } - - private boolean executeAskQuery(String query){ - logger.info("Sending query \n {}", query); - - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - boolean result = queryExecution.execAsk(); - return result; - } - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } } 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 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -24,24 +24,19 @@ import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.InverseFunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="inversefunctional objectproperty axiom learner", shortName="oplinvfunc", version=0.1) @@ -51,14 +46,9 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -68,14 +58,6 @@ this.ks = ks; } - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } @@ -108,7 +90,7 @@ //get number of instances of s with <s p o> query = String.format("SELECT (COUNT(DISTINCT ?o) AS ?all) WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); - ResultSet rs = executeQuery(query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; int all = 1; while(rs.hasNext()){ @@ -118,7 +100,7 @@ //get number of instances of s with <s p o> <s p o1> where o != o1 query = "SELECT (COUNT(DISTINCT ?s) AS ?noninversefunctional) WHERE {?s1 <%s> ?o. ?s2 <%s> ?o. FILTER(?s1 != ?s2) }"; query = query.replace("%s", propertyToDescribe.getURI().toString()); - rs = executeQuery(query); + rs = executeSelectQuery(query); int notFunctional = 1; while(rs.hasNext()){ qs = rs.next(); @@ -136,47 +118,5 @@ public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } - - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - } - private boolean executeAskQuery(String query){ - logger.info("Sending query \n {}", query); - - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - boolean result = queryExecution.execAsk(); - return result; - } - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-08-25 08:44:05 UTC (rev 3119) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-08-25 08:52:30 UTC (rev 3120) @@ -24,24 +24,19 @@ import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.IrreflexiveObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL2; @ComponentAnn(name="irreflexive objectproperty axiom learner", ... [truncated message content] |