From: <lor...@us...> - 2011-10-07 07:41:27
|
Revision: 3297 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3297&view=rev Author: lorenz_b Date: 2011-10-07 07:41:19 +0000 (Fri, 07 Oct 2011) Log Message: ----------- Some code cleanup. Started distinction in algorithms between endpoints with SPARQL 1.0 and SPARQL 1.1. support. 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/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -34,7 +34,6 @@ import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.NamedClassEditor; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.Description; @@ -65,25 +64,13 @@ @ConfigOption(name="classToDescribe", description="", propertyEditorClass=NamedClassEditor.class) private NamedClass classToDescribe; - @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 List<EvaluatedDescription> currentlyBestEvaluatedDescriptions; - private long startTime; - private int fetchedRows; public DisjointClassesLearner(SparqlEndpointKS ks){ this.ks = ks; } - - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public NamedClass getClassToDescribe() { return classToDescribe; } @@ -91,15 +78,7 @@ public void setClassToDescribe(NamedClass classToDescribe) { this.classToDescribe = classToDescribe; } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -228,12 +207,6 @@ return evalDescs; } - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } - 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -23,8 +23,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -35,7 +35,6 @@ 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; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.Description; @@ -67,12 +66,8 @@ @ConfigOption(name="classToDescribe", required=true, description="", propertyEditorClass=NamedClassEditor.class) private NamedClass classToDescribe; - @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 List<EvaluatedDescription> currentlyBestEvaluatedDescriptions; - private long startTime; - private int fetchedRows; public SimpleSubclassLearner(SparqlEndpointKS ks) { this.ks = ks; @@ -154,14 +149,6 @@ this.classToDescribe = classToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - private boolean addIndividualsWithTypes(Map<Individual, SortedSet<Description>> ind2Types, int limit, int offset){ // String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a <%s>. ?ind a ?type} LIMIT %d OFFSET %d", classToDescribe.getName(), limit, offset); boolean notEmpty = false; @@ -226,13 +213,6 @@ } - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } - - public static void main(String[] args) throws Exception{ SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveOpenLink()); 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -33,7 +33,6 @@ 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.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyDomainAxiom; import org.dllearner.core.owl.Description; @@ -56,13 +55,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public DataPropertyDomainAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -75,14 +68,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -120,17 +105,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } - private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Description>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<Description, Integer> result = new HashMap<Description, Integer>(); @@ -177,21 +151,23 @@ while(rs.hasNext()){ cnt++; qs = rs.next(); - ind = new Individual(qs.getResource("ind").getURI()); - newType = new NamedClass(qs.getResource("type").getURI()); - types = ind2Types.get(ind); - if(types == null){ - types = new TreeSet<Description>(); - ind2Types.put(ind, types); - } - types.add(newType); - Set<Description> superClasses; - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(newType)){ - superClasses = reasoner.getClassHierarchy().getSuperClasses(newType); - types.addAll(superClasses); + if(qs.get("type").isURIResource()){ + ind = new Individual(qs.getResource("ind").getURI()); + newType = new NamedClass(qs.getResource("type").getURI()); + types = ind2Types.get(ind); + if(types == null){ + types = new TreeSet<Description>(); + ind2Types.put(ind, types); } - + types.add(newType); + Set<Description> superClasses; + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(newType)){ + superClasses = reasoner.getClassHierarchy().getSuperClasses(newType); + types.addAll(superClasses); + } + + } } } return cnt; 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -32,13 +32,11 @@ 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.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.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.reasoning.SPARQLReasoner; @@ -55,13 +53,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public DataPropertyRangeAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -74,14 +66,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -108,17 +92,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } - private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Datatype>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<Datatype, Integer> result = new HashMap<Datatype, Integer>(); 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -26,13 +26,11 @@ import java.util.Map.Entry; import java.util.Set; -import org.apache.log4j.Level; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; 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.owl.DatatypeProperty; import org.dllearner.core.owl.DisjointDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -52,13 +50,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public DisjointDataPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -71,14 +63,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -159,12 +143,6 @@ return axioms; } - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } - public static void main(String[] args) throws Exception{ DisjointDataPropertyAxiomLearner l = new DisjointDataPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/position")); 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -31,7 +31,6 @@ import org.dllearner.core.ComponentAnn; 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.owl.DisjointObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; @@ -51,13 +50,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public DisjointObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -69,15 +62,7 @@ public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -128,11 +113,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count, Set<ObjectProperty> allProperties){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); @@ -162,11 +142,5 @@ return axioms; } - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } - } 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -31,10 +31,8 @@ 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.owl.DatatypeProperty; import org.dllearner.core.owl.EquivalentDatatypePropertiesAxiom; -import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; @@ -51,13 +49,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public EquivalentDataPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -69,15 +61,7 @@ public void setPropertyToDescribe(DatatypeProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -127,17 +111,8 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } + private List<EvaluatedAxiom> buildAxioms(Map<DatatypeProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Integer all = property2Count.get(propertyToDescribe); 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -32,7 +32,6 @@ import org.dllearner.core.ComponentAnn; 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.owl.EquivalentObjectPropertiesAxiom; import org.dllearner.core.owl.ObjectProperty; @@ -51,13 +50,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public EquivalentObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -69,15 +62,7 @@ public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -126,17 +111,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -20,14 +20,12 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.List; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; 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.owl.DatatypeProperty; import org.dllearner.core.owl.FunctionalDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -45,13 +43,6 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public FunctionalDataPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -65,14 +56,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -113,9 +96,4 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } } 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -20,13 +20,11 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.List; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; 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.owl.FunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; @@ -46,13 +44,6 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public FunctionalObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -66,14 +57,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -114,11 +97,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } public static void main(String[] args) throws Exception{ FunctionalObjectPropertyAxiomLearner l = new FunctionalObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -20,22 +20,16 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.List; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.EvaluatedAxiom; -import org.dllearner.core.Score; import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.InverseFunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.learningproblems.Heuristics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,13 +44,6 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public InverseFunctionalObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -70,14 +57,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -118,11 +97,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } public static void main(String[] args) throws Exception{ SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); 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-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -20,13 +20,11 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.List; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; 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.owl.IrreflexiveObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; @@ -46,13 +44,6 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public IrreflexiveObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -66,14 +57,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -117,11 +100,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } public static void main(String[] args) { IrreflexiveObjectPropertyAxiomLearner l = new IrreflexiveObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -19,6 +19,7 @@ package org.dllearner.algorithms.properties; +import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -32,7 +33,6 @@ import org.dllearner.core.ComponentAnn; 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.owl.Description; import org.dllearner.core.owl.Individual; @@ -56,13 +56,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public ObjectPropertyDomainAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -75,14 +69,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -120,17 +106,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } - private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Description>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<Description, Integer> result = new HashMap<Description, Integer>(); @@ -177,37 +152,39 @@ while(rs.hasNext()){ cnt++; qs = rs.next(); - ind = new Individual(qs.getResource("ind").getURI()); - newType = new NamedClass(qs.getResource("type").getURI()); - types = ind2Types.get(ind); - if(types == null){ - types = new TreeSet<Description>(); - ind2Types.put(ind, types); - } - types.add(newType); - Set<Description> superClasses; - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(newType)){ - superClasses = reasoner.getClassHierarchy().getSuperClasses(newType); - types.addAll(superClasses); + if(qs.get("type").isURIResource()){ + ind = new Individual(qs.getResource("ind").getURI()); + newType = new NamedClass(qs.getResource("type").getURI()); + types = ind2Types.get(ind); + if(types == null){ + types = new TreeSet<Description>(); + ind2Types.put(ind, types); } - + types.add(newType); + Set<Description> superClasses; + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(newType)){ + superClasses = reasoner.getClassHierarchy().getSuperClasses(newType); + types.addAll(superClasses); + } + + } } + } return cnt; } public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint(new URL("http://factforge.net/sparql")));//.getEndpointDBpediaLiveAKSW())); SPARQLReasoner reasoner = new SPARQLReasoner(ks); - reasoner.prepareSubsumptionHierarchy(); - System.out.println(reasoner.getClassHierarchy().getSubClasses(Thing.instance).size()); +// reasoner.prepareSubsumptionHierarchy(); ObjectPropertyDomainAxiomLearner l = new ObjectPropertyDomainAxiomLearner(ks); l.setReasoner(reasoner); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/author")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/industry")); l.setMaxExecutionTimeInSeconds(10); l.setReturnOnlyNewAxioms(true); l.init(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -21,11 +21,10 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -33,13 +32,11 @@ import org.dllearner.core.ComponentAnn; 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.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectPropertyDomainAxiom; import org.dllearner.core.owl.ObjectPropertyRangeAxiom; import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; @@ -58,13 +55,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public ObjectPropertyRangeAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -76,15 +67,7 @@ public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -121,17 +104,6 @@ } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Description>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); 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 2011-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -20,13 +20,11 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.List; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; 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.owl.ObjectProperty; import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; @@ -46,13 +44,6 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public ReflexiveObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -66,14 +57,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -115,11 +98,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } public static void main(String[] args) throws Exception{ ReflexiveObjectPropertyAxiomLearner l = new ReflexiveObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -31,7 +31,6 @@ 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.owl.DatatypeProperty; import org.dllearner.core.owl.SubDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -49,14 +48,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - - public SubDataPropertyOfAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -68,15 +60,7 @@ public void setPropertyToDescribe(DatatypeProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -125,17 +109,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } private List<EvaluatedAxiom> buildAxioms(Map<DatatypeProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); @@ -153,10 +126,6 @@ return axioms; } - private long getRemainingMaxExecutionTime(){ - return (maxExecutionTimeInSeconds == 0) ? 0 : Math.max(1, (maxExecutionTimeInSeconds * 1000)-(System.currentTimeMillis()-startTime)); - } - public static void main(String[] args) throws Exception{ SubDataPropertyOfAxiomLearner l = new SubDataPropertyOfAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/purpose")); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2011-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -30,9 +30,7 @@ import org.dllearner.core.ComponentAnn; 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.owl.DatatypeProperty; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SubObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -50,14 +48,7 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - - public SubObjectPropertyOfAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -69,15 +60,7 @@ public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -125,17 +108,6 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); @@ -153,10 +125,6 @@ return axioms; } - private long getRemainingMaxExecutionTime(){ - return (maxExecutionTimeInSeconds == 0) ? 0 : Math.max(1, (maxExecutionTimeInSeconds * 1000)-(System.currentTimeMillis()-startTime)); - } - public static void main(String[] args) throws Exception{ SubObjectPropertyOfAxiomLearner l = new SubObjectPropertyOfAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveOpenLink())); l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/writer")); 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 2011-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -19,15 +19,17 @@ package org.dllearner.algorithms.properties; +import java.net.URL; import java.util.ArrayList; -import java.util.List; +import java.util.Collections; +import org.aksw.commons.collections.multimaps.BiHashMultimap; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; 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.owl.Individual; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -46,13 +48,6 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public SymmetricObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -66,14 +61,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -89,23 +76,51 @@ logger.info("Property is already declared as symmetric in knowledge base."); } - //get fraction of instances s with <s p o> also exists <o p s> -// query = "SELECT (COUNT(?s)) AS ?all ,(COUNT(?o1)) AS ?symmetric WHERE {?s <%s> ?o. OPTIONAL{?o <%s> ?s. ?o <%s> ?o1}}"; -// query = query.replace("%s", propertyToDescribe.getURI().toString()); -// ResultSet rs = executeSelectQuery(query); -// QuerySolution qs; -// while(rs.hasNext()){ -// qs = rs.next(); -// int all = qs.getLiteral("all").getInt(); -// int symmetric = qs.getLiteral("symmetric").getInt(); -// if(all > 0){ -// double frac = symmetric / (double)all; -// currentlyBestAxioms.add(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), -// computeScore(all, symmetric))); -// } -// -// } - query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + if(ks.supportsSPARQL_1_1()){ + runSPARQL1_1_Mode(); + } else { + runSPARQL1_0_Mode(); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + private void runSPARQL1_0_Mode(){ + BiHashMultimap<Individual, Individual> individualsMap = new BiHashMultimap<Individual, Individual>(); + boolean repeat = true; + int limit = 1000; + while(!terminationCriteriaSatisfied() && repeat){ + String query = String.format("SELECT DISTINCT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d", propertyToDescribe.getURI().toString(), limit, fetchedRows); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + Individual s; + Individual o; + int cnt = 0; + while(rs.hasNext()){ + qs = rs.next(); + s = new Individual(qs.getResource("s").getURI()); + o = new Individual(qs.getResource("o").getURI()); + individualsMap.put(s, o); + cnt++; + } + int total = individualsMap.size(); + int symmetric = 0; + + for(java.util.Map.Entry<Individual, Individual> e : individualsMap.entries()){ + if(individualsMap.getInverse().containsEntry(e.getKey(), e.getValue())){ + symmetric++; + } + } + + currentlyBestAxioms = Collections.singletonList(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), + computeScore(total, symmetric))); + fetchedRows += limit; + repeat = (cnt == limit); + } + } + + private void runSPARQL1_1_Mode(){ + String query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -126,20 +141,14 @@ if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), - computeScore(total, symmetric), declaredAsSymmetric)); + computeScore(total, symmetric))); } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { - return currentlyBestAxioms; - } public static void main(String[] args) throws Exception{ - SymmetricObjectPropertyAxiomLearner l = new SymmetricObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/similar")); + SymmetricObjectPropertyAxiomLearner l = new SymmetricObjectPropertyAxiomLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://factforge.net/sparql"))));//.getEndpointDBpediaLiveAKSW())); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/industry")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); 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 2011-09-30 12:13:40 UTC (rev 3296) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2011-10-07 07:41:19 UTC (rev 3297) @@ -20,13 +20,12 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.List; +import java.util.Collections; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; 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.owl.ObjectProperty; import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; @@ -46,13 +45,6 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; - @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 List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - public TransitiveObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -66,14 +58,6 @@ this.propertyToDescribe = propertyToDescribe; } - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - @Override public void start() { logger.info("Start learning..."); @@ -89,22 +73,23 @@ logger.info("Property is already declared as transitive in knowledge base."); } - //get fraction of instances s where for a chain <s p o> <o p o1> exists also <s p o1> -// query = "SELECT (COUNT(?o)) AS ?all ,(COUNT(?o2)) AS ?transitive WHERE {?s <%s> ?o. ?o <%s> ?o1. OPTIONAL{?s <%s> ?o1. ?s <%s> ?o2}}"; -// query = query.replace("%s", propertyToDescribe.getURI().toString()); -// ResultSet rs = executeSelectQuery(query); -// QuerySolution qs; -// while(rs.hasNext()){ -// qs = rs.next(); -// int all = qs.getLiteral("all").getInt(); -// int transitive = qs.getLiteral("transitive").getInt(); -// if(all > 0){ -// currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescribe), -// computeScore(all, transitive))); -// } -// -// } - query = "SELECT (COUNT(?o) AS ?total) WHERE {?s <%s> ?o. ?o <%s> ?o1.}"; + + if(ks.supportsSPARQL_1_1()){ + runSPARQL1_1_Mode(); + } else { + runSPARQL1_0_Mode(); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + + private void runSPARQL1_0_Mode(){ + currentlyBestAxioms = Collections.emptyList(); + } + + private void runSPARQL1_1_Mode(){ + String query = "SELECT (COUNT(?o) AS ?total) WHERE {?s <%s> ?o. ?o <%s> ?o1.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -124,16 +109,10 @@ if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescr... [truncated message content] |