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] |
From: <lor...@us...> - 2011-08-28 13:06:50
|
Revision: 3151 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3151&view=rev Author: lorenz_b Date: 2011-08-28 13:06:43 +0000 (Sun, 28 Aug 2011) Log Message: ----------- Replaced accuracy computation with the average of the confidence interval boundaries (computed with Wald95 method). Modified Paths: -------------- 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/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/learningproblems/AxiomScore.java 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-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -199,18 +199,15 @@ result.remove(classToDescribe); EvaluatedDescription evalDesc; + int total = individual2Types.keySet().size(); for(Entry<NamedClass, Integer> entry : sortByValues(result)){ evalDesc = new EvaluatedDescription(entry.getKey(), - new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + computeScore(total, entry.getValue())); currentlyBestEvaluatedDescriptions.add(evalDesc); } } - private double computeScore(){ - return 0; - } - private boolean terminationCriteriaSatisfied(){ boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; @@ -218,8 +215,8 @@ } public static void main(String[] args) throws Exception{ - SimpleSubclassLearner l = new SimpleSubclassLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); - ConfigHelper.configure(l, "maxExecutionTimeInSeconds", 5); + SimpleSubclassLearner l = new SimpleSubclassLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveOpenLink())); + ConfigHelper.configure(l, "maxExecutionTimeInSeconds", 10); 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-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -38,9 +38,9 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,10 +130,14 @@ } } + //omit owl:Thing + result.remove(new NamedClass(Thing.instance.getURI())); + EvaluatedAxiom evalAxiom; + int total = individual2Types.keySet().size(); for(Entry<NamedClass, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new DatatypePropertyDomainAxiom(propertyToDescribe, entry.getKey()), - new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + computeScore(total, entry.getValue())); axioms.add(evalAxiom); } 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-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -39,7 +39,6 @@ import org.dllearner.core.owl.DatatypePropertyRangeAxiom; import org.dllearner.core.owl.Individual; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,9 +129,10 @@ } EvaluatedAxiom evalAxiom; + int total = individual2Types.keySet().size(); for(Entry<Datatype, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new DatatypePropertyRangeAxiom(propertyToDescribe, entry.getKey()), - new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + computeScore(total, entry.getValue())); axioms.add(evalAxiom); } @@ -163,5 +163,4 @@ } return cnt; } - } 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-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -31,7 +31,6 @@ import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.FunctionalDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -107,8 +106,8 @@ notFunctional = qs.getLiteral("notfunctional").getInt(); } if(all > 0){ - double frac = (all - notFunctional) / (double)all; - currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalDatatypePropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalDatatypePropertyAxiom(propertyToDescribe), + computeScore(all, all - notFunctional))); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); @@ -118,5 +117,4 @@ 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-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -31,7 +31,6 @@ import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -107,8 +106,8 @@ notFunctional = qs.getLiteral("notfunctional").getInt(); } if(all > 0){ - double frac = (all - notFunctional) / (double)all; - currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalObjectPropertyAxiom(propertyToDescribe), + computeScore(all, all - notFunctional))); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); @@ -118,5 +117,5 @@ public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } - + } 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-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -25,6 +25,7 @@ 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; @@ -32,6 +33,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.learningproblems.Heuristics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,14 +103,14 @@ 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 = executeSelectQuery(query); - int notFunctional = 1; + int notInverseFunctional = 1; while(rs.hasNext()){ qs = rs.next(); - notFunctional = qs.getLiteral("noninversefunctional").getInt(); + notInverseFunctional = qs.getLiteral("noninversefunctional").getInt(); } if(all > 0){ - double frac = (all - notFunctional) / (double)all; - currentlyBestAxioms.add(new EvaluatedAxiom(new InverseFunctionalObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + currentlyBestAxioms.add(new EvaluatedAxiom(new InverseFunctionalObjectPropertyAxiom(propertyToDescribe), + computeScore(all, all - notInverseFunctional))); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); 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-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -31,7 +31,6 @@ import org.dllearner.core.owl.IrreflexiveObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -111,7 +110,8 @@ if(all > 0){ double frac = irreflexive / (double)all; - currentlyBestAxioms.add(new EvaluatedAxiom(new IrreflexiveObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + currentlyBestAxioms.add(new EvaluatedAxiom(new IrreflexiveObjectPropertyAxiom(propertyToDescribe), + computeScore(all, irreflexive))); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); 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-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -38,8 +38,8 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyDomainAxiom; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -129,10 +129,14 @@ } } + //omit owl:Thing + result.remove(new NamedClass(Thing.instance.getURI())); + EvaluatedAxiom evalAxiom; + int total = individual2Types.keySet().size(); for(Entry<NamedClass, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new ObjectPropertyDomainAxiom(propertyToDescribe, entry.getKey()), - new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + computeScore(total, entry.getValue())); axioms.add(evalAxiom); } 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-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -38,9 +38,9 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyRangeAxiom; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,10 +130,14 @@ } } + //omit owl:Thing + result.remove(new NamedClass(Thing.instance.getURI())); + EvaluatedAxiom evalAxiom; + int total = individual2Types.keySet().size(); for(Entry<NamedClass, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new ObjectPropertyRangeAxiom(propertyToDescribe, entry.getKey()), - new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + computeScore(total, entry.getValue())); axioms.add(evalAxiom); } @@ -167,9 +171,9 @@ } public static void main(String[] args) throws Exception{ - ObjectPropertyRangeAxiomLearner l = new ObjectPropertyRangeAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/aircraftElectronic")); - l.setMaxExecutionTimeInSeconds(0); + ObjectPropertyRangeAxiomLearner l = new ObjectPropertyRangeAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/academicAdvisor")); + l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); 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-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -31,7 +31,6 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,7 +98,8 @@ int reflexive = qs.getLiteral("reflexiv").getInt(); if(all > 0){ double frac = reflexive / (double)all; - currentlyBestAxioms.add(new EvaluatedAxiom(new ReflexiveObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + currentlyBestAxioms.add(new EvaluatedAxiom(new ReflexiveObjectPropertyAxiom(propertyToDescribe), + computeScore(all, reflexive))); } } 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-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -35,7 +35,6 @@ import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.SubDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -138,17 +137,17 @@ private List<EvaluatedAxiom> buildAxioms(Map<DatatypeProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); - Integer all = property2Count.get(propertyToDescribe); + Integer total = property2Count.get(propertyToDescribe); property2Count.remove(propertyToDescribe); EvaluatedAxiom evalAxiom; for(Entry<DatatypeProperty, Integer> entry : sortByValues(property2Count)){ evalAxiom = new EvaluatedAxiom(new SubDatatypePropertyAxiom(propertyToDescribe, entry.getKey()), - new AxiomScore(entry.getValue() / (double)all)); + computeScore(total, entry.getValue())); axioms.add(evalAxiom); } - property2Count.put(propertyToDescribe, all); + property2Count.put(propertyToDescribe, total); return axioms; } 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-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -35,7 +35,6 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SubObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -138,17 +137,17 @@ private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); - Integer all = property2Count.get(propertyToDescribe); + Integer total = property2Count.get(propertyToDescribe); property2Count.remove(propertyToDescribe); EvaluatedAxiom evalAxiom; for(Entry<ObjectProperty, Integer> entry : sortByValues(property2Count)){ evalAxiom = new EvaluatedAxiom(new SubObjectPropertyAxiom(propertyToDescribe, entry.getKey()), - new AxiomScore(entry.getValue() / (double)all)); + computeScore(total, entry.getValue())); axioms.add(evalAxiom); } - property2Count.put(propertyToDescribe, all); + property2Count.put(propertyToDescribe, total); return axioms; } 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-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -31,7 +31,6 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,7 +98,8 @@ int symmetric = qs.getLiteral("symmetric").getInt(); if(all > 0){ double frac = symmetric / (double)all; - currentlyBestAxioms.add(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + currentlyBestAxioms.add(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), + computeScore(all, symmetric))); } } 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-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -32,7 +32,6 @@ import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,7 +99,8 @@ int transitive = qs.getLiteral("transitive").getInt(); if(all > 0){ double frac = transitive / (double)all; - currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescribe), + computeScore(all, transitive))); } } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -30,8 +30,11 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.learningproblems.Heuristics; import org.dllearner.reasoning.SPARQLReasoner; import com.hp.hpl.jena.query.ResultSet; @@ -151,5 +154,14 @@ }); return entries; } + + protected Score computeScore(int total, int success){ + double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, success); + + double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; + double confidence = confidenceInterval[1] - confidenceInterval[0]; + + return new AxiomScore(accuracy, confidence); + } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/AxiomScore.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/AxiomScore.java 2011-08-28 12:50:50 UTC (rev 3150) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/AxiomScore.java 2011-08-28 13:06:43 UTC (rev 3151) @@ -25,14 +25,23 @@ private static final long serialVersionUID = 555252118489924570L; private double accuracy; + private double confidence; public AxiomScore(double accuracy) { this.accuracy = accuracy; } + + public AxiomScore(double accuracy, double confidence) { + this.accuracy = accuracy; + } @Override public double getAccuracy() { return accuracy; } + + public double getConfidence(){ + return confidence; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-30 07:47:15
|
Revision: 3167 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3167&view=rev Author: lorenz_b Date: 2011-08-30 07:47:09 +0000 (Tue, 30 Aug 2011) Log Message: ----------- Small fixes. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 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-29 20:22:23 UTC (rev 3166) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-08-30 07:47:09 UTC (rev 3167) @@ -31,6 +31,7 @@ import org.dllearner.core.owl.IrreflexiveObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlEndpoint; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,7 +100,7 @@ } //get number of instances s where not exists <s p s> - query = "SELECT (COUNT(DISTINCT ?s) AS ?irreflexive) WHERE {?s <%s> ?o. OPTIONAL{?s <%s> ?o1.FILTER(?s = ?o1)} FILTER(!BOUND(?o1))}"; + query = "SELECT (COUNT(DISTINCT ?s) AS ?irreflexive) WHERE {?s <%s> ?o. FILTER(?s != ?o)}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int irreflexive = 0; @@ -109,7 +110,6 @@ } if(all > 0){ - double frac = irreflexive / (double)all; currentlyBestAxioms.add(new EvaluatedAxiom(new IrreflexiveObjectPropertyAxiom(propertyToDescribe), computeScore(all, irreflexive))); } @@ -122,4 +122,10 @@ return currentlyBestAxioms; } + public static void main(String[] args) { + IrreflexiveObjectPropertyAxiomLearner l = new IrreflexiveObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/thumbnail")); + l.start(); + } + } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-08-29 20:22:23 UTC (rev 3166) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-08-30 07:47:09 UTC (rev 3167) @@ -153,7 +153,7 @@ propertyCharacteristics.add(AxiomType.ASYMMETRIC_OBJECT_PROPERTY); for(AxiomType type : propertyCharacteristics){ - query = "CONSTRUCT {?s a <%s>} WHERE {?s a %s}".replaceAll("%s", type.getName()); + query = "CONSTRUCT {?s a <http://www.w3.org/2002/07/owl#%s>} WHERE {?s a <http://www.w3.org/2002/07/owl#%s>}".replaceAll("%s", type.getName()); model.add(loadIncrementally(query)); } @@ -772,9 +772,9 @@ String NS = "http://dbpedia.org/ontology/"; SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); SPARQLReasoner r = new SPARQLReasoner(ks); - + long startTime = System.currentTimeMillis(); r.loadSchema(); - + System.out.println("Time needed: " + (System.currentTimeMillis()-startTime) + "ms"); // ObjectProperty oP = new ObjectProperty(NS + "league"); // for(Entry<Individual, SortedSet<Individual>> entry : r.getPropertyMembers(oP).entrySet()){ // System.out.println(entry.getKey()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-31 08:36:59
|
Revision: 3178 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3178&view=rev Author: jenslehmann Date: 2011-08-31 08:36:53 +0000 (Wed, 31 Aug 2011) Log Message: ----------- several smaller fixes Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-31 07:36:35 UTC (rev 3177) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-31 08:36:53 UTC (rev 3178) @@ -79,6 +79,7 @@ "org.dllearner.kb.sparql.SparqlKnowledgeSource", "org.dllearner.learningproblems.PosNegLPStandard", "org.dllearner.learningproblems.PosOnlyLP", + "org.dllearner.learningproblems.ClassLearningProblem", "org.dllearner.reasoning.FastInstanceChecker", "org.dllearner.reasoning.OWLAPIReasoner", "org.dllearner.algorithms.ocel.OCEL", Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-31 07:36:35 UTC (rev 3177) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-31 08:36:53 UTC (rev 3178) @@ -48,11 +48,11 @@ protected Set<Individual> negativeExamples = new TreeSet<Individual>(); protected Set<Individual> allExamples = new TreeSet<Individual>(); - @org.dllearner.core.config.ConfigOption(name = "useRetrievalForClassification", description = "\"Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.",defaultValue = "false", propertyEditorClass = BoolEditor.class) + @org.dllearner.core.config.ConfigOption(name = "useRetrievalForClassification", description = "\"Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.",defaultValue = "false") private boolean useRetrievalForClassification = false; @org.dllearner.core.config.ConfigOption(name = "useMultiInstanceChecks", description = "Use The Multi Instance Checks", defaultValue = "UseMultiInstanceChecks.TWOCHECKS", required = false, propertyEditorClass = StringTrimmerEditor.class) private UseMultiInstanceChecks useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; - @org.dllearner.core.config.ConfigOption(name = "percentPerLengthUnit", description = "Percent Per Length Unit", defaultValue = "0.05", required = false, propertyEditorClass = DoubleEditor.class) + @org.dllearner.core.config.ConfigOption(name = "percentPerLengthUnit", description = "Percent Per Length Unit", defaultValue = "0.05", required = false) private double percentPerLengthUnit = 0.05; Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-31 07:36:35 UTC (rev 3177) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-31 08:36:53 UTC (rev 3178) @@ -62,10 +62,10 @@ // approximation and F-measure // (taken from class learning => super class instances corresponds to negative examples // and class instances to positive examples) - @ConfigOption(name = "approxDelta", description = "The Approximate Delta", defaultValue = "0.05", required = false, propertyEditorClass = DoubleEditor.class) + @ConfigOption(name = "approxDelta", description = "The Approximate Delta", defaultValue = "0.05", required = false) private double approxDelta = 0.05; - @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false, propertyEditorClass = BoolEditor.class) + @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false) private boolean useApproximations; @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy.",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2011-08-31 07:36:35 UTC (rev 3177) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2011-08-31 08:36:53 UTC (rev 3178) @@ -127,7 +127,7 @@ private Map<DatatypeProperty, Map<Individual, SortedSet<Integer>>> id = new TreeMap<DatatypeProperty, Map<Individual, SortedSet<Integer>>>(); private Map<DatatypeProperty, Map<Individual, SortedSet<String>>> sd = new TreeMap<DatatypeProperty, Map<Individual, SortedSet<String>>>(); - @ConfigOption(name="defaultNegation", description = "Whether to use default negation, i.e. an instance not being in a class means that it is in the negation of the class.", defaultValue = "true", required = false, propertyEditorClass = BoolEditor.class) + @ConfigOption(name="defaultNegation", description = "Whether to use default negation, i.e. an instance not being in a class means that it is in the negation of the class.", defaultValue = "true", required = false) private boolean defaultNegation = true; @ConfigOption(name = "forAllRetrievalSemantics", description = "This option controls how to interpret the all quantifier in forall r.C. The standard option is" + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-31 08:48:03
|
Revision: 3179 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3179&view=rev Author: jenslehmann Date: 2011-08-31 08:47:57 +0000 (Wed, 31 Aug 2011) Log Message: ----------- small fix Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-31 08:36:53 UTC (rev 3178) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-31 08:47:57 UTC (rev 3179) @@ -35,8 +35,6 @@ import org.dllearner.core.owl.Individual; import org.dllearner.utilities.Helper; import org.springframework.beans.propertyeditors.StringTrimmerEditor; -import sun.beans.editors.BoolEditor; -import sun.beans.editors.DoubleEditor; /** * @author Jens Lehmann Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-31 08:36:53 UTC (rev 3178) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-31 08:47:57 UTC (rev 3179) @@ -26,10 +26,10 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.DoubleConfigOption; @@ -39,8 +39,6 @@ import org.dllearner.learningproblems.Heuristics.HeuristicType; import org.dllearner.utilities.Helper; import org.springframework.beans.propertyeditors.StringTrimmerEditor; -import sun.beans.editors.BoolEditor; -import sun.beans.editors.DoubleEditor; /** * The aim of this learning problem is to learn a concept definition such that Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2011-08-31 08:36:53 UTC (rev 3178) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2011-08-31 08:47:57 UTC (rev 3179) @@ -22,18 +22,18 @@ import java.io.File; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import java.util.Map.Entry; import org.apache.log4j.Logger; +import org.dllearner.core.AbstractKnowledgeSource; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; -import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Axiom; @@ -69,7 +69,6 @@ import org.dllearner.utilities.owl.ConceptTransformation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.propertyeditors.StringTrimmerEditor; -import sun.beans.editors.BoolEditor; /** * Reasoner for fast instance checks. It works by completely dematerialising the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-31 13:52:40
|
Revision: 3188 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3188&view=rev Author: lorenz_b Date: 2011-08-31 13:52:34 +0000 (Wed, 31 Aug 2011) Log Message: ----------- Some small changes. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-08-31 12:51:40 UTC (rev 3187) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-08-31 13:52:34 UTC (rev 3188) @@ -30,13 +30,16 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; -import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.learningproblems.Heuristics; import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; @@ -46,6 +49,8 @@ */ public class AbstractAxiomLearningAlgorithm extends AbstractComponent implements AxiomLearningAlgorithm{ + private static final Logger logger = LoggerFactory.getLogger(AbstractAxiomLearningAlgorithm.class); + @ConfigOption(name="maxExecutionTimeInSeconds", defaultValue="10", description="", propertyEditorClass=IntegerEditor.class) protected int maxExecutionTimeInSeconds = 10; @@ -118,20 +123,20 @@ } protected ResultSet executeSelectQuery(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); - } + queryExecution.setDefaultGraphURIs(ks.getEndpoint().getDefaultGraphURIs()); + queryExecution.setNamedGraphURIs(ks.getEndpoint().getNamedGraphURIs()); + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; } protected 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); Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java 2011-08-31 12:51:40 UTC (rev 3187) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java 2011-08-31 13:52:34 UTC (rev 3188) @@ -244,7 +244,7 @@ // TODO Allow other content types. httpQuery.setAccept(HttpParams.contentTypeResultsXML); - InputStream in = doTimedExec(httpQuery); + InputStream in = httpQuery.exec(); ResultSet rs = ResultSetFactory.fromXML(in); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-08-31 12:51:40 UTC (rev 3187) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-08-31 13:52:34 UTC (rev 3188) @@ -19,6 +19,7 @@ package org.dllearner.reasoning; +import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -29,6 +30,11 @@ import java.util.TreeMap; import java.util.TreeSet; +import org.aksw.commons.sparql.api.cache.core.QueryExecutionFactoryCache; +import org.aksw.commons.sparql.api.cache.extra.Cache; +import org.aksw.commons.sparql.api.cache.extra.CacheCoreH2; +import org.aksw.commons.sparql.api.cache.extra.CacheImpl; +import org.aksw.commons.sparql.api.cache.extra.CacheResource; import org.aksw.commons.sparql.api.core.QueryExecutionFactory; import org.aksw.commons.sparql.api.http.QueryExecutionFactoryHttp; import org.aksw.commons.sparql.api.pagination.core.QueryExecutionFactoryPaginated; @@ -49,6 +55,7 @@ import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.utilities.datastructures.SortedSetTuple; @@ -58,6 +65,7 @@ import org.slf4j.LoggerFactory; import com.clarkparsia.owlapiv3.XSD; +import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; @@ -120,7 +128,7 @@ return new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); } - public void loadSchema(){ + public Model loadSchema(){ Model model = ModelFactory.createDefaultModel(); //load class hierarchy @@ -161,16 +169,22 @@ model.add(loadIncrementally(query)); } -// for(Statement st : model.listStatements().toList()){ -// System.out.println(st); -// } + return model; } private Model loadIncrementally(String query){ - QueryExecutionFactory f = new QueryExecutionFactoryHttp(ks.getEndpoint().getURL().toString(), ks.getEndpoint().getDefaultGraphURIs()); - f = new QueryExecutionFactoryPaginated(f, 1000); - Model model = f.createQueryExecution(query).execConstruct(); - return model; + try { + QueryExecutionFactory f = new QueryExecutionFactoryHttp(ks.getEndpoint().getURL().toString(), ks.getEndpoint().getDefaultGraphURIs()); + f = new QueryExecutionFactoryCache(f, new CacheImpl(CacheCoreH2.create("cache", 60 * 24 *5))); + f = new QueryExecutionFactoryPaginated(f, 1000); + Model model = f.createQueryExecution(query).execConstruct(); + return model; + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; } @Override @@ -773,11 +787,13 @@ public static void main(String[] args) { - String NS = "http://dbpedia.org/ontology/"; SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); SPARQLReasoner r = new SPARQLReasoner(ks); long startTime = System.currentTimeMillis(); - r.loadSchema(); + Model schema = r.loadSchema(); + for(Statement st : schema.listStatements().toList()){ + System.out.println(st); + } System.out.println("Time needed: " + (System.currentTimeMillis()-startTime) + "ms"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-31 18:10:23
|
Revision: 3201 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3201&view=rev Author: jenslehmann Date: 2011-08-31 18:10:17 +0000 (Wed, 31 Aug 2011) Log Message: ----------- deleting empty packages Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/core/configurators/ trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-01 20:33:00
|
Revision: 3212 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3212&view=rev Author: lorenz_b Date: 2011-09-01 20:32:54 +0000 (Thu, 01 Sep 2011) Log Message: ----------- Removed unsued method. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentDatatypePropertiesAxiom.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 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-01 18:59:35 UTC (rev 3211) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-09-01 20:32:54 UTC (rev 3212) @@ -214,10 +214,11 @@ return timeLimitExceeded || resultLimitExceeded; } + public static void main(String[] args) throws Exception{ - SimpleSubclassLearner l = new SimpleSubclassLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveOpenLink())); + SimpleSubclassLearner l = new SimpleSubclassLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); ConfigHelper.configure(l, "maxExecutionTimeInSeconds", 10); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Criminal")); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Mountain")); l.init(); l.start(); 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-01 18:59:35 UTC (rev 3211) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-09-01 20:32:54 UTC (rev 3212) @@ -172,7 +172,7 @@ public static void main(String[] args) throws Exception{ ObjectPropertyDomainAxiomLearner l = new ObjectPropertyDomainAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/numberOfSuites")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/hometown")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); 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-01 18:59:35 UTC (rev 3211) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-09-01 20:32:54 UTC (rev 3212) @@ -116,8 +116,7 @@ qs.getLiteral("count").getInt(); repeat = true; } - close(); - System.out.println(repeat); + if(!result.isEmpty()){ currentlyBestAxioms = buildAxioms(result); offset += 1000; 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-01 18:59:35 UTC (rev 3211) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-09-01 20:32:54 UTC (rev 3212) @@ -138,7 +138,7 @@ public static void main(String[] args) throws Exception{ SymmetricObjectPropertyAxiomLearner l = new SymmetricObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/sisterStation")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/similar")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-09-01 18:59:35 UTC (rev 3211) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-09-01 20:32:54 UTC (rev 3212) @@ -54,6 +54,8 @@ protected SparqlEndpointKS ks; protected SPARQLReasoner reasoner; + ExtendedQueryEngineHTTP queryExecution; + public int getMaxExecutionTimeInSeconds() { return maxExecutionTimeInSeconds; } @@ -116,7 +118,7 @@ protected ResultSet executeSelectQuery(String query) { logger.info("Sending query\n{} ...", query); - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), + queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); queryExecution.setDefaultGraphURIs(ks.getEndpoint().getDefaultGraphURIs()); @@ -127,6 +129,10 @@ return resultSet; } + protected void close() { + queryExecution.close(); + } + protected boolean executeAskQuery(String query){ logger.info("Sending query\n{} ...", query); QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); @@ -156,9 +162,12 @@ double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, success); double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; + double confidence = confidenceInterval[1] - confidenceInterval[0]; return new AxiomScore(accuracy, confidence); } + + } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentDatatypePropertiesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentDatatypePropertiesAxiom.java 2011-09-01 18:59:35 UTC (rev 3211) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentDatatypePropertiesAxiom.java 2011-09-01 20:32:54 UTC (rev 3212) @@ -48,11 +48,11 @@ } public String toString(String baseURI, Map<String,String> prefixes) { - return "EquivalentObjectProperties(" + equivRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; + return "EquivalentDataProperties(" + equivRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; } public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) { - return "EquivalentObjectProperties(" + equivRole.toKBSyntaxString(baseURI, prefixes) + "," + role.toKBSyntaxString(baseURI, prefixes) + ")"; + return "EquivalentDataProperties(" + equivRole.toKBSyntaxString(baseURI, prefixes) + "," + role.toKBSyntaxString(baseURI, prefixes) + ")"; } @Override Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-01 18:59:35 UTC (rev 3211) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-01 20:32:54 UTC (rev 3212) @@ -31,15 +31,13 @@ import java.util.TreeSet; import org.aksw.commons.sparql.api.cache.core.QueryExecutionFactoryCache; -import org.aksw.commons.sparql.api.cache.extra.Cache; import org.aksw.commons.sparql.api.cache.extra.CacheCoreH2; import org.aksw.commons.sparql.api.cache.extra.CacheImpl; -import org.aksw.commons.sparql.api.cache.extra.CacheResource; import org.aksw.commons.sparql.api.core.QueryExecutionFactory; import org.aksw.commons.sparql.api.http.QueryExecutionFactoryHttp; import org.aksw.commons.sparql.api.pagination.core.QueryExecutionFactoryPaginated; +import org.aksw.commons.util.strings.StringUtils; import org.dllearner.core.IndividualReasoner; -import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.SchemaReasoner; import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Constant; @@ -55,17 +53,14 @@ import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.owl.ConceptComparator; -import org.semanticweb.owlapi.model.AxiomType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.clarkparsia.owlapiv3.XSD; -import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; @@ -139,24 +134,44 @@ query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#disjointWith> ?o} WHERE {?s <http://www.w3.org/2002/07/owl#disjointWith> ?o}"; model.add(loadIncrementally(query)); //load domain axioms - query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#domain> ?o} WHERE {?s <http://www.w3.org/2000/01/rdf-schema#domain> ?o}"; + query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#domain> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty> } " + + "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#domain> ?o.?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; model.add(loadIncrementally(query)); + query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#domain> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>} " + + "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#domain> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; + model.add(loadIncrementally(query)); //load range axioms - query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#range> ?o} WHERE {?s <http://www.w3.org/2000/01/rdf-schema#range> ?o}"; + query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#range> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>} " + + "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#range> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; model.add(loadIncrementally(query)); + query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#range> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>} " + + "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#range> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; + model.add(loadIncrementally(query)); //load property hierarchy - query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o} WHERE {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o}"; + query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>} " + + "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; model.add(loadIncrementally(query)); - query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#equivalentProperty> ?o} WHERE {?s <http://www.w3.org/2002/07/owl#equivalentProperty> ?o}"; + query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>} " + + "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; model.add(loadIncrementally(query)); - query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#propertyDisjointWith> ?o} WHERE {?s <http://www.w3.org/2002/07/owl#propertyDisjointWith> ?o}"; + query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#equivalentProperty> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>} " + + "WHERE {?s <http://www.w3.org/2002/07/owl#equivalentProperty> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; model.add(loadIncrementally(query)); + query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#equivalentProperty> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>} " + + "WHERE {?s <http://www.w3.org/2002/07/owl#equivalentProperty> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; + model.add(loadIncrementally(query)); + query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#propertyDisjointWith> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>} " + + "WHERE {?s <http://www.w3.org/2002/07/owl#propertyDisjointWith> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; + model.add(loadIncrementally(query)); + query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#propertyDisjointWith> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>} " + + "WHERE {?s <http://www.w3.org/2002/07/owl#propertyDisjointWith> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; + model.add(loadIncrementally(query)); //load inverse relation query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#inverseOf> ?o} WHERE {?s <http://www.w3.org/2002/07/owl#inverseOf> ?o}"; model.add(loadIncrementally(query)); //load property characteristics Set<Resource> propertyCharacteristics = new HashSet<Resource>(); - propertyCharacteristics.add(OWL.FunctionalProperty); +// propertyCharacteristics.add(OWL.FunctionalProperty); propertyCharacteristics.add(OWL.InverseFunctionalProperty); propertyCharacteristics.add(OWL.SymmetricProperty); propertyCharacteristics.add(OWL.TransitiveProperty); @@ -168,25 +183,35 @@ query = "CONSTRUCT {?s a <%s>} WHERE {?s a <%s>}".replaceAll("%s", propChar.getURI()); model.add(loadIncrementally(query)); } + //for functional properties we have to distinguish between data and object properties, + //i.e. we have to keep the property type information, otherwise conversion to OWLAPI ontology makes something curious + query = "CONSTRUCT {?s a <%s>. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>} WHERE {?s a <%s>.?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}". + replaceAll("%s", OWL.FunctionalProperty.getURI()); + model.add(loadIncrementally(query)); + query = "CONSTRUCT {?s a <%s>. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>} WHERE {?s a <%s>.?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}". + replaceAll("%s", OWL.FunctionalProperty.getURI()); + model.add(loadIncrementally(query)); + return model; } private Model loadIncrementally(String query){ -// try { + System.out.println(StringUtils.md5Hash(query)); + try { QueryExecutionFactory f = new QueryExecutionFactoryHttp(ks.getEndpoint().getURL().toString(), ks.getEndpoint().getDefaultGraphURIs()); -// f = new QueryExecutionFactoryCache(f, new CacheImpl(CacheCoreH2.create("cache", 60 * 24 *5))); - System.out.println("SPARQLReasoner.loadIncrementally needs to be rewritten for aksw-commons 0.1"); - System.exit(0); + f = new QueryExecutionFactoryCache(f, new CacheImpl(CacheCoreH2.create("cache", 60 * 24 *5))); +// System.out.println("SPARQLReasoner.loadIncrementally needs to be rewritten for aksw-commons 0.1"); +// System.exit(0); f = new QueryExecutionFactoryPaginated(f, 1000); Model model = f.createQueryExecution(query).execConstruct(); return model; -// } catch (ClassNotFoundException e) { -// e.printStackTrace(); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// return null; + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-02 10:11:44
|
Revision: 3227 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3227&view=rev Author: lorenz_b Date: 2011-09-02 10:11:38 +0000 (Fri, 02 Sep 2011) Log Message: ----------- Extended vocabulary. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-09-02 09:23:45 UTC (rev 3226) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-09-02 10:11:38 UTC (rev 3227) @@ -81,7 +81,7 @@ OWLAxiom ax = OWLAPIConverter.getOWLAPIAxiom(axiom); ax.accept(r); - OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); + OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.AddSuggestion, ind); OWLAxiom ax2 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.hasAxiom, ind, sw.toString()); OWLAnnotation anno = f.getOWLAnnotation(EnrichmentVocabulary.belongsTo, ind.getIRI()); // OWLAxiom ax2 = ax.getAnnotatedAxiom(Collections.singleton(anno)); Modified: trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java 2011-09-02 09:23:45 UTC (rev 3226) +++ trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java 2011-09-02 10:11:38 UTC (rev 3227) @@ -43,6 +43,10 @@ public static final OWLClass Suggestion = factory.getOWLClass(IRI.create(NS + "Suggestion")); + public static final OWLClass AddSuggestion = factory.getOWLClass(IRI.create(NS + "AddSuggestion")); + + public static final OWLClass DeleteSuggestion = factory.getOWLClass(IRI.create(NS + "DeleteSuggestion")); + public static final OWLClass Parameter = factory.getOWLClass(IRI.create(NS + "Parameter")); public static final OWLClass Creation = factory.getOWLClass(IRI.create(NS + "Creation")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-14 19:20:04
|
Revision: 3265 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3265&view=rev Author: lorenz_b Date: 2011-09-14 19:19:58 +0000 (Wed, 14 Sep 2011) Log Message: ----------- Fixed problem with new OWL API. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2011-09-14 17:44:57 UTC (rev 3264) +++ trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2011-09-14 19:19:58 UTC (rev 3265) @@ -111,7 +111,7 @@ "org.dllearner.reasoning.PelletReasoner", //learning problems "org.dllearner.learningproblems.PosNegLPStandard", - "org.dllearner.learningproblems.fuzzydll.FuzzyPosNegLPStandard", // added by Josue + "org.dllearner.learningproblems.FuzzyPosNegLPStandard", // added by Josue "org.dllearner.learningproblems.PosNegLPStrict", "org.dllearner.learningproblems.PosOnlyLP", "org.dllearner.learningproblems.ClassLearningProblem", Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2011-09-14 17:44:57 UTC (rev 3264) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2011-09-14 19:19:58 UTC (rev 3265) @@ -1010,6 +1010,9 @@ // policy: returned sets are clones, i.e. can be modified // (of course we only have to clone the leafs of a class description tree) if (description instanceof NamedClass) { + if(((NamedClass) description).getName().equals("http://www.w3.org/2002/07/owl#Nothing")){ + return new TreeSet<Individual>(); + } return (TreeSet<Individual>) classInstancesPos.get((NamedClass) description).clone(); } else if (description instanceof Negation) { if(description.getChild(0) instanceof NamedClass) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-15 07:57:54
|
Revision: 3266 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3266&view=rev Author: lorenz_b Date: 2011-09-15 07:57:48 +0000 (Thu, 15 Sep 2011) Log Message: ----------- Added inference usage for object property domain axiom learner. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.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/SubDataPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 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-14 19:19:58 UTC (rev 3265) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-09-15 07:57:48 UTC (rev 3266) @@ -143,7 +143,7 @@ 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); + String query = String.format("SELECT ?ind (DATATYPE(?val) AS ?datatype) WHERE {?ind <%s> ?val.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); ResultSet rs = executeSelectQuery(query); Individual ind; 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-14 19:19:58 UTC (rev 3265) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-09-15 07:57:48 UTC (rev 3266) @@ -88,7 +88,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()); + query = String.format("SELECT (COUNT(DISTINCT ?s) AS ?all) WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; int all = 1; @@ -97,7 +97,7 @@ all = qs.getLiteral("all").getInt(); } //get number of instances of s with <s p o> <s p o1> where o != o1 - query = "SELECT (COUNT(DISTINCT ?s)) AS ?notfunctional WHERE {?s <%s> ?o. ?s <%s> ?o1. FILTER(?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 = executeSelectQuery(query); int notFunctional = 1; 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-14 19:19:58 UTC (rev 3265) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-09-15 07:57:48 UTC (rev 3266) @@ -24,6 +24,7 @@ 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; @@ -41,6 +42,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,7 +94,7 @@ logger.info("Existing domain: " + existingDomain); //get subjects with types - Map<Individual, SortedSet<NamedClass>> individual2Types = new HashMap<Individual, SortedSet<NamedClass>>(); + Map<Individual, SortedSet<Description>> individual2Types = new HashMap<Individual, SortedSet<Description>>(); boolean repeat = true; int limit = 1000; while(!terminationCriteriaSatisfied() && repeat){ @@ -115,11 +117,11 @@ return timeLimitExceeded || resultLimitExceeded; } - private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<NamedClass>> individual2Types){ + private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Description>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); - Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); - for(Entry<Individual, SortedSet<NamedClass>> entry : individual2Types.entrySet()){ - for(NamedClass nc : entry.getValue()){ + Map<Description, Integer> result = new HashMap<Description, Integer>(); + for(Entry<Individual, SortedSet<Description>> entry : individual2Types.entrySet()){ + for(Description nc : entry.getValue()){ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); @@ -135,7 +137,7 @@ EvaluatedAxiom evalAxiom; int total = individual2Types.keySet().size(); - for(Entry<NamedClass, Integer> entry : sortByValues(result)){ + for(Entry<Description, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new ObjectPropertyDomainAxiom(propertyToDescribe, entry.getKey()), computeScore(total, entry.getValue())); axioms.add(evalAxiom); @@ -144,16 +146,16 @@ return axioms; } - private int addIndividualsWithTypes(Map<Individual, SortedSet<NamedClass>> ind2Types, int limit, int offset){ + private int addIndividualsWithTypes(Map<Individual, SortedSet<Description>> 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 = executeSelectQuery(query); Individual ind; - NamedClass newType; + Description newType; QuerySolution qs; - SortedSet<NamedClass> types; + SortedSet<Description> types; int cnt = 0; while(rs.hasNext()){ cnt++; @@ -162,20 +164,35 @@ newType = new NamedClass(qs.getResource("type").getURI()); types = ind2Types.get(ind); if(types == null){ - types = new TreeSet<NamedClass>(); + 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{ - ObjectPropertyDomainAxiomLearner l = new ObjectPropertyDomainAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + + SPARQLReasoner reasoner = new SPARQLReasoner(ks); + reasoner.prepareSubsumptionHierarchy(); + + ObjectPropertyDomainAxiomLearner l = new ObjectPropertyDomainAxiomLearner(ks); + l.setReasoner(reasoner); l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/hometown")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); + System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); } 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-14 19:19:58 UTC (rev 3265) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-09-15 07:57:48 UTC (rev 3266) @@ -172,7 +172,7 @@ public static void main(String[] args) throws Exception{ ObjectPropertyRangeAxiomLearner l = new ObjectPropertyRangeAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/academicAdvisor")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/vicePrimeMinister")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); 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-14 19:19:58 UTC (rev 3265) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-09-15 07:57:48 UTC (rev 3266) @@ -90,7 +90,7 @@ //get properties and how often they occur int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?p a <http://www.w3.org/2002/07/owl#DatatypeProperty>. ?s ?p ?o. " + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + "}"; String query; @@ -159,8 +159,8 @@ public static void main(String[] args) throws Exception{ SubDataPropertyOfAxiomLearner l = new SubDataPropertyOfAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); - l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/number")); - l.setMaxExecutionTimeInSeconds(1000000); + l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/purpose")); + l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-09-14 19:19:58 UTC (rev 3265) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-09-15 07:57:48 UTC (rev 3266) @@ -78,7 +78,9 @@ @Override public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); + if(reasoner == null){ + reasoner = new SPARQLReasoner(ks); + } } @Override Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2011-09-14 19:19:58 UTC (rev 3265) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2011-09-15 07:57:48 UTC (rev 3266) @@ -297,4 +297,13 @@ return new ClassHierarchy(subsumptionHierarchyUpNew, subsumptionHierarchyDownNew); } + + /** + * Checks whether the description is contained in the hierarchy. + * @param description + * @return + */ + public boolean contains(Description description){ + return subsumptionHierarchyUp.containsKey(description); + } } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-14 19:19:58 UTC (rev 3265) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-15 07:57:48 UTC (rev 3266) @@ -19,7 +19,6 @@ package org.dllearner.reasoning; -import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -30,9 +29,6 @@ import java.util.TreeMap; import java.util.TreeSet; -import org.aksw.commons.sparql.api.cache.core.QueryExecutionFactoryCache; -import org.aksw.commons.sparql.api.cache.extra.CacheCoreH2; -import org.aksw.commons.sparql.api.cache.extra.CacheImpl; import org.aksw.commons.sparql.api.core.QueryExecutionFactory; import org.aksw.commons.sparql.api.http.QueryExecutionFactoryHttp; import org.aksw.commons.sparql.api.pagination.core.QueryExecutionFactoryPaginated; @@ -64,7 +60,6 @@ import org.dllearner.utilities.owl.ConceptComparator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.propertyeditors.StringTrimmerEditor; import com.clarkparsia.owlapiv3.XSD; import com.hp.hpl.jena.query.QuerySolution; @@ -72,7 +67,6 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; -import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL2; @@ -632,8 +626,7 @@ @Override public ClassHierarchy getClassHierarchy() { - // TODO Auto-generated method stub - return null; + return hierarchy; } @Override @@ -812,6 +805,14 @@ return resultset; } + /** + * Returns TRUE if the class hierarchy was computed before. + * @return + */ + public boolean isPrepared(){ + return hierarchy != null; + } + private boolean executeAskQuery(String query){ QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { @@ -841,10 +842,13 @@ SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); SPARQLReasoner r = new SPARQLReasoner(ks); long startTime = System.currentTimeMillis(); - Model schema = r.loadSchema(); - for(Statement st : schema.listStatements().toList()){ - System.out.println(st); - } + ClassHierarchy h = r.prepareSubsumptionHierarchy(); + System.out.println(h.getSuperClasses(new NamedClass("http://dbpedia.org/ontology/PoloLeague"))); + System.out.println(h.toString(false)); +// Model schema = r.loadSchema(); +// for(Statement st : schema.listStatements().toList()){ +// System.out.println(st); +// } System.out.println("Time needed: " + (System.currentTimeMillis()-startTime) + "ms"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-16 20:17:29
|
Revision: 3276 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3276&view=rev Author: lorenz_b Date: 2011-09-16 20:17:22 +0000 (Fri, 16 Sep 2011) Log Message: ----------- Added inference to subClassOf learner. Result of learning algorithm now prefers the more specific resources. Added method to check if endpoint supports SPARQL 1.1. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 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-16 11:04:43 UTC (rev 3275) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-09-16 20:17:22 UTC (rev 3276) @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; @@ -45,6 +46,7 @@ import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -131,7 +133,7 @@ } - Map<Individual, SortedSet<NamedClass>> ind2Types = new HashMap<Individual, SortedSet<NamedClass>>(); + Map<Individual, SortedSet<Description>> ind2Types = new HashMap<Individual, SortedSet<Description>>(); int limit = 1000; boolean repeat = true; while(!terminationCriteriaSatisfied() && repeat){ @@ -160,37 +162,46 @@ this.maxFetchedRows = maxFetchedRows; } - private boolean addIndividualsWithTypes(Map<Individual, SortedSet<NamedClass>> ind2Types, int limit, int offset){ + 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; 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); // String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a <%s>. ?ind a ?type} LIMIT %d OFFSET %d", classToDescribe.getName(), limit, offset); ResultSet rs = executeSelectQuery(query); Individual ind; - NamedClass newType; + Description newType; QuerySolution qs; - SortedSet<NamedClass> types; + SortedSet<Description> types; while(rs.hasNext()){ 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<NamedClass>(); + 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); + } + + } + notEmpty = true; } return notEmpty; } - private void createEvaluatedDescriptions(Map<Individual, SortedSet<NamedClass>> individual2Types){ + private void createEvaluatedDescriptions(Map<Individual, SortedSet<Description>> individual2Types){ currentlyBestEvaluatedDescriptions.clear(); - Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); - for(Entry<Individual, SortedSet<NamedClass>> entry : individual2Types.entrySet()){ - for(NamedClass nc : entry.getValue()){ + Map<Description, Integer> result = new HashMap<Description, Integer>(); + for(Entry<Individual, SortedSet<Description>> entry : individual2Types.entrySet()){ + for(Description nc : entry.getValue()){ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); @@ -207,7 +218,7 @@ EvaluatedDescription evalDesc; int total = individual2Types.keySet().size(); - for(Entry<NamedClass, Integer> entry : sortByValues(result)){ + for(Entry<Description, Integer> entry : sortByValues(result, true)){ evalDesc = new EvaluatedDescription(entry.getKey(), computeScore(total, entry.getValue())); currentlyBestEvaluatedDescriptions.add(evalDesc); @@ -223,7 +234,14 @@ public static void main(String[] args) throws Exception{ - SimpleSubclassLearner l = new SimpleSubclassLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveOpenLink()); + + SPARQLReasoner reasoner = new SPARQLReasoner(ks); + reasoner.prepareSubsumptionHierarchy(); + + SimpleSubclassLearner l = new SimpleSubclassLearner(ks); + l.setReasoner(reasoner); + ConfigHelper.configure(l, "maxExecutionTimeInSeconds", 10); l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Bridge")); l.init(); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-09-16 11:04:43 UTC (rev 3275) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-09-16 20:17:22 UTC (rev 3276) @@ -29,6 +29,8 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.Description; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; @@ -163,6 +165,38 @@ return entries; } + protected List<Entry<Description, Integer>> sortByValues(Map<Description, Integer> map, final boolean useHierachy){ + List<Entry<Description, Integer>> entries = new ArrayList<Entry<Description, Integer>>(map.entrySet()); + final ClassHierarchy hierarchy = reasoner.getClassHierarchy(); + Collections.sort(entries, new Comparator<Entry<Description, Integer>>() { + + @Override + public int compare(Entry<Description, Integer> o1, Entry<Description, Integer> o2) { + int ret = o2.getValue().compareTo(o1.getValue()); + //if the score is the same, than we optionally also take into account the subsumption hierarchy + if(ret == 0 && useHierachy){ + if(hierarchy != null){ + if(hierarchy.contains(o1.getKey()) && hierarchy.contains(o2.getKey())){ + if(hierarchy.isSubclassOf(o1.getKey(), o2.getKey())){ + ret = -1; + } else if(hierarchy.isSubclassOf(o2.getKey(), o1.getKey())){ + ret = 1; + } else { + //we use the depth in the class hierarchy as third ranking property +// int depth1 = hierarchy.getDepth2Root(o1.getKey()); +// int depth2 = hierarchy.getDepth2Root(o2.getKey()); +// ret = depth1 - depth2; + } + } + } + } + + return ret; + } + }); + return entries; + } + protected Score computeScore(int total, int success){ double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, success); Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2011-09-16 11:04:43 UTC (rev 3275) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2011-09-16 20:17:22 UTC (rev 3276) @@ -184,6 +184,44 @@ return false; } } + + /** + * Implements a subsumption check using the hierarchy (no further reasoning + * checks are used). + * + * @param subClass + * The (supposedly) more special class. + * @param superClass + * The (supposedly) more general class. + * @return True if <code>subClass</code> is a subclass of + * <code>superclass</code>. + */ + public boolean isSubclassOf(Description subClass, Description superClass) { + if (subClass.equals(superClass)) { + return true; + } else { + SortedSet<Description> superClasses = subsumptionHierarchyUp.get(subClass); + if(superClasses != null){ + for (Description moreGeneralClass : superClasses) { + + // search the upper classes of the subclass + if (moreGeneralClass instanceof NamedClass) { + if (isSubclassOf(moreGeneralClass, superClass)) { + return true; + } + // we reached top, so we can return false (if top is a + // direct upper + // class, then no other upper classes can exist) + } else { + return false; + } + } + } + // we cannot reach the class via any of the upper classes, + // so it is not a super class + return false; + } + } @Override public String toString() { @@ -306,4 +344,16 @@ public boolean contains(Description description){ return subsumptionHierarchyUp.containsKey(description); } + + public int getDepth2Root(Description description){ + SortedSet<Description> superClasses = subsumptionHierarchyUp.get(description); + int depth = 0; + if(superClasses != null){ + depth = 1; + for(Description superClass : superClasses){ + depth += getDepth2Root(superClass); + } + } + return depth; + } } Modified: trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2011-09-16 11:04:43 UTC (rev 3275) +++ trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2011-09-16 20:17:22 UTC (rev 3276) @@ -43,6 +43,7 @@ public class SparqlEndpointKS implements KnowledgeSource { private SparqlEndpoint endpoint; + private boolean supportsSPARQL_1_1 = false; // TODO: turn those into config options @@ -96,6 +97,14 @@ public void setNamedGraphURIs(List<String> namedGraphURIs) { this.namedGraphURIs = namedGraphURIs; + } + + public boolean supportsSPARQL_1_1() { + return supportsSPARQL_1_1; + } + + public void setSupportsSPARQL_1_1(boolean supportsSPARQL_1_1) { + this.supportsSPARQL_1_1 = supportsSPARQL_1_1; } } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 2011-09-16 11:04:43 UTC (rev 3275) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 2011-09-16 20:17:22 UTC (rev 3276) @@ -713,6 +713,18 @@ return classes; } + public boolean supportsSPARQL_1_1(){ + String query = "SELECT * WHERE {?s ?p ?o. {SELECT * WHERE {?s ?p ?o.} LIMIT 1} } LIMIT 1"; + SparqlQuery sq = new SparqlQuery(query, sparqlEndpoint); + try { + sq.send(); + return true; + } catch (Exception e) { + System.out.println("Endpoint doesn't seem to support SPARQL 1.1 ."); + } + return false; + } + } /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-26 08:54:53
|
Revision: 3285 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3285&view=rev Author: lorenz_b Date: 2011-09-26 08:54:46 +0000 (Mon, 26 Sep 2011) Log Message: ----------- Some code cleanup. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/utilities/owl/AxiomComparator.java 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-23 08:33:44 UTC (rev 3284) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-09-26 08:54:46 UTC (rev 3285) @@ -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; @@ -64,8 +63,6 @@ private long startTime; private int fetchedRows; - private Set<Description> existingDomains; - public DataPropertyDomainAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -94,17 +91,18 @@ currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); if(returnOnlyNewAxioms){ - existingDomains = new HashSet<Description>(); //get existing domains Description existingDomain = reasoner.getDomain(propertyToDescribe); - existingDomains.add(existingDomain); - logger.info("Existing domain: " + existingDomain); - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(existingDomain)){ - for(Description sup : reasoner.getClassHierarchy().getSuperClasses(existingDomain)){ - existingDomains.add(sup); - logger.info("Existing domain(inferred): " + sup); + if(existingDomain != null){ + existingAxioms.add(new DatatypePropertyDomainAxiom(propertyToDescribe, existingDomain)); + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(existingDomain)){ + for(Description sup : reasoner.getClassHierarchy().getSuperClasses(existingDomain)){ + existingAxioms.add(new DatatypePropertyDomainAxiom(propertyToDescribe, existingDomain)); + logger.info("Existing domain(inferred): " + sup); + } } + } } } @@ -150,11 +148,6 @@ //omit owl:Thing result.remove(new NamedClass(Thing.instance.getURI())); - if(returnOnlyNewAxioms){ - for(Description domain : existingDomains){ - result.remove(domain); - } - } EvaluatedAxiom evalAxiom; int total = individual2Types.keySet().size(); 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-23 08:33:44 UTC (rev 3284) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-09-26 08:54:46 UTC (rev 3285) @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -35,7 +34,6 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -65,8 +63,6 @@ private long startTime; private int fetchedRows; - private Set<Description> existingDomains; - public ObjectPropertyDomainAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -95,19 +91,19 @@ currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); if(returnOnlyNewAxioms){ - existingDomains = new HashSet<Description>(); //get existing domains Description existingDomain = reasoner.getDomain(propertyToDescribe); - existingDomains.add(existingDomain); - logger.info("Existing domain: " + existingDomain); - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(existingDomain)){ - for(Description sup : reasoner.getClassHierarchy().getSuperClasses(existingDomain)){ - existingDomains.add(sup); - logger.info("Existing domain(inferred): " + sup); + if(existingDomain != null){ + existingAxioms.add(new ObjectPropertyDomainAxiom(propertyToDescribe, existingDomain)); + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(existingDomain)){ + for(Description sup : reasoner.getClassHierarchy().getSuperClasses(existingDomain)){ + existingAxioms.add(new ObjectPropertyDomainAxiom(propertyToDescribe, existingDomain)); + logger.info("Existing domain(inferred): " + sup); + } } + } - } } @@ -152,11 +148,6 @@ //omit owl:Thing result.remove(new NamedClass(Thing.instance.getURI())); - if(returnOnlyNewAxioms){ - for(Description domain : existingDomains){ - result.remove(domain); - } - } EvaluatedAxiom evalAxiom; int total = individual2Types.keySet().size(); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-09-23 08:33:44 UTC (rev 3284) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-09-26 08:54:46 UTC (rev 3285) @@ -24,7 +24,10 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Map.Entry; +import java.util.Set; import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.config.ConfigOption; @@ -37,6 +40,7 @@ import org.dllearner.learningproblems.AxiomScore; import org.dllearner.learningproblems.Heuristics; import org.dllearner.reasoning.SPARQLReasoner; +import org.dllearner.utilities.owl.AxiomComparator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +63,13 @@ protected SparqlEndpointKS ks; protected SPARQLReasoner reasoner; + protected SortedSet<Axiom> existingAxioms; + public AbstractAxiomLearningAlgorithm() { + existingAxioms = new TreeSet<Axiom>(new AxiomComparator()); + } + + ExtendedQueryEngineHTTP queryExecution; public int getMaxExecutionTimeInSeconds() { @@ -128,7 +138,13 @@ for(EvaluatedAxiom evAx : currentlyBestEvAxioms){ if(evAx.getScore().getAccuracy() >= accuracyThreshold && returnList.size() < nrOfAxioms){ - returnList.add(evAx); + if(returnOnlyNewAxioms){ + if(!existingAxioms.contains(evAx.getAxiom())){ + returnList.add(evAx); + } + } else { + returnList.add(evAx); + } } } Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-09-23 08:33:44 UTC (rev 3284) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-09-26 08:54:46 UTC (rev 3285) @@ -49,6 +49,8 @@ private Axiom axiom; private Score score; + private boolean asserted = false; + public EvaluatedAxiom(Axiom axiom, Score score) { this.axiom = axiom; this.score = score; @@ -62,6 +64,14 @@ return score; } + public boolean isAsserted() { + return asserted; + } + + public void setAsserted(boolean asserted) { + this.asserted = asserted; + } + @Override public String toString() { return axiom + "(" + score.getAccuracy()+ ")"; Added: trunk/components-core/src/main/java/org/dllearner/utilities/owl/AxiomComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/AxiomComparator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/AxiomComparator.java 2011-09-26 08:54:46 UTC (rev 3285) @@ -0,0 +1,330 @@ +package org.dllearner.utilities.owl; + +import java.util.Collection; +import java.util.Comparator; + +import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; +import org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner; +import org.dllearner.algorithms.properties.ReflexiveObjectPropertyAxiomLearner; +import org.dllearner.core.owl.AsymmetricObjectPropertyAxiom; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.ClassAssertionAxiom; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyAssertion; +import org.dllearner.core.owl.DatatypePropertyDomainAxiom; +import org.dllearner.core.owl.DatatypePropertyRangeAxiom; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DisjointClassesAxiom; +import org.dllearner.core.owl.DisjointDatatypePropertyAxiom; +import org.dllearner.core.owl.DisjointObjectPropertyAxiom; +import org.dllearner.core.owl.EquivalentClassesAxiom; +import org.dllearner.core.owl.EquivalentDatatypePropertiesAxiom; +import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; +import org.dllearner.core.owl.FunctionalDatatypePropertyAxiom; +import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; +import org.dllearner.core.owl.InverseFunctionalObjectPropertyAxiom; +import org.dllearner.core.owl.IrreflexiveObjectPropertyAxiom; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyAssertion; +import org.dllearner.core.owl.ObjectPropertyDomainAxiom; +import org.dllearner.core.owl.ObjectPropertyRangeAxiom; +import org.dllearner.core.owl.Property; +import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; +import org.dllearner.core.owl.SubClassAxiom; +import org.dllearner.core.owl.SubDatatypePropertyAxiom; +import org.dllearner.core.owl.SubObjectPropertyAxiom; +import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; +import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; + +public class AxiomComparator implements Comparator<Axiom>{ + + private ConceptComparator conceptComp; + private RoleComparator roleComp; + + public AxiomComparator() { + conceptComp = new ConceptComparator(); + roleComp = new RoleComparator(); + } + + @Override + public int compare(Axiom ax1, Axiom ax2) { + if(ax1 instanceof SubClassAxiom){ + if(ax2 instanceof SubClassAxiom){ + Description sub1 = ((SubClassAxiom)ax1).getSubConcept(); + Description sub2 = ((SubClassAxiom)ax2).getSubConcept(); + if(conceptComp.compare(sub1, sub2) == 0){ + Description sup1 = ((SubClassAxiom)ax1).getSuperConcept(); + Description sup2 = ((SubClassAxiom)ax2).getSuperConcept(); + return conceptComp.compare(sup1, sup2); + } else { + return -1; + } + + } else { + return -1; + } + } else if(ax1 instanceof DisjointClassesAxiom){ + if(ax2 instanceof DisjointClassesAxiom){ + Collection<Description> descriptions1 = ((DisjointClassesAxiom)ax1).getDescriptions(); + Collection<Description> descriptions2 = ((DisjointClassesAxiom)ax2).getDescriptions(); + if(descriptions1.size() == descriptions2.size()){ + for(Description d1 : descriptions1){ + boolean existsEqual = false; + for(Description d2 : descriptions2){ + if(conceptComp.compare(d1, d2) == 0){ + existsEqual = true; + break; + } + } + if(!existsEqual){ + return -1; + } + } + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof EquivalentClassesAxiom){ + if(ax2 instanceof EquivalentClassesAxiom){ + Description eq11 = ((EquivalentClassesAxiom)ax1).getConcept1(); + Description eq21 = ((EquivalentClassesAxiom)ax2).getConcept1(); + Description eq12 = ((EquivalentClassesAxiom)ax1).getConcept2(); + Description eq22 = ((EquivalentClassesAxiom)ax2).getConcept2(); + + if(conceptComp.compare(eq11, eq21) == 0){ + return conceptComp.compare(eq12, eq22); + } else if(conceptComp.compare(eq11, eq22) == 0){ + return conceptComp.compare(eq12, eq21); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof SubObjectPropertyAxiom){ + if(ax2 instanceof SubObjectPropertyAxiom){ + ObjectProperty sub1 = ((SubObjectPropertyAxiom)ax1).getSubRole(); + ObjectProperty sub2 = ((SubObjectPropertyAxiom)ax2).getSubRole(); + if(roleComp.compare(sub1, sub2) == 0){ + ObjectProperty sup1 = ((SubObjectPropertyAxiom)ax1).getRole(); + ObjectProperty sup2 = ((SubObjectPropertyAxiom)ax2).getRole(); + return roleComp.compare(sup1, sup2); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof DisjointObjectPropertyAxiom){ + if(ax2 instanceof DisjointObjectPropertyAxiom){ + ObjectProperty dis11 = ((DisjointObjectPropertyAxiom)ax1).getRole(); + ObjectProperty dis12 = ((DisjointObjectPropertyAxiom)ax1).getDisjointRole(); + ObjectProperty dis21 = ((DisjointObjectPropertyAxiom)ax2).getRole(); + ObjectProperty dis22 = ((DisjointObjectPropertyAxiom)ax2).getDisjointRole(); + if(roleComp.compare(dis11, dis21) == 0){ + return roleComp.compare(dis12, dis22); + } else if(roleComp.compare(dis11, dis22) == 0){ + return roleComp.compare(dis12, dis21); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof EquivalentObjectPropertiesAxiom){ + if(ax2 instanceof EquivalentObjectPropertiesAxiom){ + Collection<ObjectProperty> properties1 = ((EquivalentObjectPropertiesAxiom)ax1).getEquivalentProperties(); + Collection<ObjectProperty> properties2 = ((EquivalentObjectPropertiesAxiom)ax2).getEquivalentProperties(); + if(properties1.size() == properties2.size()){ + for(ObjectProperty p1 : properties1){ + boolean existsEqual = false; + for(ObjectProperty p2 : properties2){ + if(roleComp.compare(p1, p2) == 0){ + existsEqual = true; + break; + } + } + if(!existsEqual){ + return -1; + } + } + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof ObjectPropertyDomainAxiom){ + if(ax2 instanceof ObjectPropertyDomainAxiom){ + ObjectProperty p1 = ((ObjectPropertyDomainAxiom)ax1).getProperty(); + ObjectProperty p2 = ((ObjectPropertyDomainAxiom)ax2).getProperty(); + if(roleComp.compare(p1, p2) == 0){ + return conceptComp.compare(((ObjectPropertyDomainAxiom)ax1).getDomain(), ((ObjectPropertyDomainAxiom)ax2).getDomain()); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof ObjectPropertyRangeAxiom){ + if(ax2 instanceof ObjectPropertyRangeAxiom){ + Property p1 = ((ObjectPropertyRangeAxiom)ax1).getProperty(); + Property p2 = ((ObjectPropertyRangeAxiom)ax2).getProperty(); + if(roleComp.compare(p1, p2) == 0){ + return conceptComp.compare(((ObjectPropertyRangeAxiom)ax1).getRange(), ((ObjectPropertyRangeAxiom)ax2).getRange()); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof FunctionalObjectPropertyAxiom){ + if(ax2 instanceof FunctionalObjectPropertyAxiom){ + return roleComp.compare(((FunctionalObjectPropertyAxiom)ax1).getRole(), ((FunctionalObjectPropertyAxiom)ax2).getRole()); + } else { + return -1; + } + } else if(ax1 instanceof InverseFunctionalObjectPropertyAxiom){ + if(ax2 instanceof InverseFunctionalObjectPropertyAxiom){ + return roleComp.compare(((InverseFunctionalObjectPropertyAxiom)ax1).getRole(), ((InverseFunctionalObjectPropertyAxiom)ax2).getRole()); + } else { + return -1; + } + } else if(ax1 instanceof ReflexiveObjectPropertyAxiom){ + if(ax2 instanceof ReflexiveObjectPropertyAxiom){ + return roleComp.compare(((ReflexiveObjectPropertyAxiom)ax1).getRole(), ((ReflexiveObjectPropertyAxiom)ax2).getRole()); + } else { + return -1; + } + } else if(ax1 instanceof IrreflexiveObjectPropertyAxiom){ + if(ax2 instanceof IrreflexiveObjectPropertyAxiom){ + return roleComp.compare(((IrreflexiveObjectPropertyAxiom)ax1).getRole(), ((IrreflexiveObjectPropertyAxiom)ax2).getRole()); + } else { + return -1; + } + } else if(ax1 instanceof TransitiveObjectPropertyAxiom){ + if(ax2 instanceof TransitiveObjectPropertyAxiom){ + return roleComp.compare(((TransitiveObjectPropertyAxiom)ax1).getRole(), ((TransitiveObjectPropertyAxiom)ax2).getRole()); + } else { + return -1; + } + } else if(ax1 instanceof SymmetricObjectPropertyAxiom){ + if(ax2 instanceof SymmetricObjectPropertyAxiom){ + return roleComp.compare(((SymmetricObjectPropertyAxiom)ax1).getRole(), ((SymmetricObjectPropertyAxiom)ax2).getRole()); + } else { + return -1; + } + } else if(ax1 instanceof AsymmetricObjectPropertyAxiom){ + if(ax2 instanceof AsymmetricObjectPropertyAxiom){ + return roleComp.compare(((AsymmetricObjectPropertyAxiom)ax1).getRole(), ((AsymmetricObjectPropertyAxiom)ax2).getRole()); + } else { + return -1; + } + } else if(ax1 instanceof SubDatatypePropertyAxiom){ + if(ax2 instanceof SubDatatypePropertyAxiom){ + DatatypeProperty sub1 = ((SubDatatypePropertyAxiom)ax1).getSubRole(); + DatatypeProperty sub2 = ((SubDatatypePropertyAxiom)ax2).getSubRole(); + if(roleComp.compare(sub1, sub2) == 0){ + DatatypeProperty sup1 = ((SubDatatypePropertyAxiom)ax1).getRole(); + DatatypeProperty sup2 = ((SubDatatypePropertyAxiom)ax2).getRole(); + return roleComp.compare(sup1, sup2); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof DisjointDatatypePropertyAxiom){ + if(ax2 instanceof DisjointDatatypePropertyAxiom){ + DatatypeProperty dis11 = ((DisjointDatatypePropertyAxiom)ax1).getRole(); + DatatypeProperty dis12 = ((DisjointDatatypePropertyAxiom)ax1).getDisjointRole(); + DatatypeProperty dis21 = ((DisjointDatatypePropertyAxiom)ax2).getRole(); + DatatypeProperty dis22 = ((DisjointDatatypePropertyAxiom)ax2).getDisjointRole(); + if(roleComp.compare(dis11, dis21) == 0){ + return roleComp.compare(dis12, dis22); + } else if(roleComp.compare(dis11, dis22) == 0){ + return roleComp.compare(dis12, dis21); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof EquivalentDatatypePropertiesAxiom){ + if(ax2 instanceof EquivalentDatatypePropertiesAxiom){ + DatatypeProperty eq11 = ((EquivalentDatatypePropertiesAxiom)ax1).getRole(); + DatatypeProperty eq12 = ((EquivalentDatatypePropertiesAxiom)ax1).getEquivalentRole(); + DatatypeProperty eq21 = ((EquivalentDatatypePropertiesAxiom)ax2).getRole(); + DatatypeProperty eq22 = ((EquivalentDatatypePropertiesAxiom)ax2).getEquivalentRole(); + if(roleComp.compare(eq11, eq21) == 0){ + return roleComp.compare(eq12, eq22); + } else if(roleComp.compare(eq11, eq22) == 0){ + return roleComp.compare(eq12, eq21); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof DatatypePropertyDomainAxiom){ + if(ax2 instanceof DatatypePropertyDomainAxiom){ + DatatypeProperty p1 = ((DatatypePropertyDomainAxiom)ax1).getProperty(); + DatatypeProperty p2 = ((DatatypePropertyDomainAxiom)ax2).getProperty(); + if(roleComp.compare(p1, p2) == 0){ + return conceptComp.compare(((DatatypePropertyDomainAxiom)ax1).getDomain(), ((DatatypePropertyDomainAxiom)ax2).getDomain()); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof DatatypePropertyRangeAxiom){ + if(ax2 instanceof DatatypePropertyRangeAxiom){ + Property p1 = ((DatatypePropertyRangeAxiom)ax1).getProperty(); + Property p2 = ((DatatypePropertyRangeAxiom)ax2).getProperty(); + if(roleComp.compare(p1, p2) == 0){ + return ((DatatypePropertyRangeAxiom)ax1).getRange().toString(null, null).compareTo( + ((DatatypePropertyRangeAxiom)ax2).getRange().toString(null, null)); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof FunctionalDatatypePropertyAxiom){ + if(ax2 instanceof FunctionalDatatypePropertyAxiom){ + return roleComp.compare(((FunctionalDatatypePropertyAxiom)ax1).getRole(), ((FunctionalDatatypePropertyAxiom)ax2).getRole()); + } else { + return -1; + } + } else if(ax1 instanceof ClassAssertionAxiom){ + if(ax2 instanceof ClassAssertionAxiom){ + Description d1 = ((ClassAssertionAxiom)ax1).getConcept(); + Description d2 = ((ClassAssertionAxiom)ax2).getConcept(); + if(conceptComp.compare(d1, d2) == 0){ + return ((ClassAssertionAxiom)ax1).getIndividual().compareTo(((ClassAssertionAxiom)ax2).getIndividual()); + } else { + return -1; + } + } else { + return -1; + } + } else if(ax1 instanceof ObjectPropertyAssertion){ + if(ax2 instanceof ObjectPropertyAssertion){ + return -1;//TODO + } else { + return -1; + } + } else if(ax1 instanceof DatatypePropertyAssertion){ + if(ax2 instanceof DatatypePropertyAssertion){ + return -1;//TODO + } else { + return -1; + } + } + return -1; + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/utilities/owl/AxiomComparator.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-26 21:23:05
|
Revision: 3286 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3286&view=rev Author: lorenz_b Date: 2011-09-26 21:22:59 +0000 (Mon, 26 Sep 2011) Log Message: ----------- Some modifications to store the property that axioms are already asserted in the knowledge base. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.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/SymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -154,6 +154,9 @@ for(Entry<Description, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new DatatypePropertyDomainAxiom(propertyToDescribe, entry.getKey()), computeScore(total, entry.getValue())); + if(existingAxioms.contains(evalAxiom.getAxiom())){ + evalAxiom.setAsserted(true); + } axioms.add(evalAxiom); } 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -80,10 +80,11 @@ fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - //check if property is already declared as symmetric in knowledge base + //check if property is already declared as functional in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); boolean declaredAsFunctional = executeAskQuery(query); if(declaredAsFunctional) { + existingAxioms.add(new FunctionalDatatypePropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as functional in knowledge base."); } @@ -107,7 +108,7 @@ } if(all > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalDatatypePropertyAxiom(propertyToDescribe), - computeScore(all, all - notFunctional))); + computeScore(all, all - notFunctional), declaredAsFunctional)); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -85,6 +85,7 @@ String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); boolean declaredAsFunctional = executeAskQuery(query); if(declaredAsFunctional) { + existingAxioms.add(new FunctionalObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as functional in knowledge base."); } @@ -108,7 +109,7 @@ } if(all > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalObjectPropertyAxiom(propertyToDescribe), - computeScore(all, all - notFunctional))); + computeScore(all, all - notFunctional), declaredAsFunctional)); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -87,8 +87,9 @@ //check if property is already declared as symmetric in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.InverseFunctionalProperty.getURI()); - boolean declaredAsFunctional = executeAskQuery(query); - if(declaredAsFunctional) { + boolean declaredAsInverseFunctional = executeAskQuery(query); + if(declaredAsInverseFunctional) { + existingAxioms.add(new InverseFunctionalObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as functional in knowledge base."); } @@ -112,7 +113,7 @@ } if(all > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new InverseFunctionalObjectPropertyAxiom(propertyToDescribe), - computeScore(all, all - notInverseFunctional))); + computeScore(all, all - notInverseFunctional), declaredAsInverseFunctional)); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -81,10 +81,11 @@ fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - //check if property is already declared as reflexive in knowledge base + //check if property is already declared as irreflexive in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.IrreflexiveProperty.getURI()); - boolean declaredAsReflexive = executeAskQuery(query); - if(declaredAsReflexive) { + boolean declaredAsIrreflexive = executeAskQuery(query); + if(declaredAsIrreflexive) { + existingAxioms.add(new IrreflexiveObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as irreflexive in knowledge base."); } @@ -111,7 +112,7 @@ if(all > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new IrreflexiveObjectPropertyAxiom(propertyToDescribe), - computeScore(all, irreflexive))); + computeScore(all, irreflexive), declaredAsIrreflexive)); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -90,7 +90,7 @@ fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - if(returnOnlyNewAxioms){ + if(reasoner.isPrepared()){ //get existing domains Description existingDomain = reasoner.getDomain(propertyToDescribe); if(existingDomain != null){ @@ -154,6 +154,9 @@ for(Entry<Description, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new ObjectPropertyDomainAxiom(propertyToDescribe, entry.getKey()), computeScore(total, entry.getValue())); + if(existingAxioms.contains(evalAxiom.getAxiom())){ + evalAxiom.setAsserted(true); + } axioms.add(evalAxiom); } 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -39,6 +39,7 @@ 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; @@ -64,8 +65,6 @@ private long startTime; private int fetchedRows; - private Set<Description> existingRanges; - public ObjectPropertyRangeAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -93,20 +92,20 @@ fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - if(returnOnlyNewAxioms){ - existingRanges = new HashSet<Description>(); + if(reasoner.isPrepared()){ //get existing ranges - Description existingRange = reasoner.getRange(propertyToDescribe); - existingRanges.add(existingRange); - logger.info("Existing range: " + existingRange); - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(existingRange)){ - for(Description sup : reasoner.getClassHierarchy().getSuperClasses(existingRange)){ - existingRanges.add(sup); - logger.info("Existing range(inferred): " + sup); + Description existingDomain = reasoner.getRange(propertyToDescribe); + if(existingDomain != null){ + existingAxioms.add(new ObjectPropertyRangeAxiom(propertyToDescribe, existingDomain)); + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(existingDomain)){ + for(Description sup : reasoner.getClassHierarchy().getSuperClasses(existingDomain)){ + existingAxioms.add(new ObjectPropertyRangeAxiom(propertyToDescribe, existingDomain)); + logger.info("Existing range(inferred): " + sup); + } } + } - } } @@ -151,17 +150,15 @@ //omit owl:Thing result.remove(new NamedClass(Thing.instance.getURI())); - if(returnOnlyNewAxioms){ - for(Description range : existingRanges){ - result.remove(range); - } - } EvaluatedAxiom evalAxiom; int total = individual2Types.keySet().size(); for(Entry<Description, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new ObjectPropertyRangeAxiom(propertyToDescribe, entry.getKey()), computeScore(total, entry.getValue())); + if(existingAxioms.contains(evalAxiom.getAxiom())){ + evalAxiom.setAsserted(true); + } axioms.add(evalAxiom); } 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -85,6 +85,7 @@ String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.ReflexiveProperty.getURI()); boolean declaredAsReflexive = executeAskQuery(query); if(declaredAsReflexive) { + existingAxioms.add(new ReflexiveObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as reflexive in knowledge base."); } @@ -109,7 +110,7 @@ } if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new ReflexiveObjectPropertyAxiom(propertyToDescribe), - computeScore(total, reflexive))); + computeScore(total, reflexive), declaredAsReflexive)); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -85,6 +85,7 @@ String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.SymmetricProperty.getURI()); boolean declaredAsSymmetric = executeAskQuery(query); if(declaredAsSymmetric) { + existingAxioms.add(new SymmetricObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as symmetric in knowledge base."); } @@ -125,7 +126,7 @@ if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), - computeScore(total, symmetric))); + computeScore(total, symmetric), declaredAsSymmetric)); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); 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-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -85,6 +85,7 @@ String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.TransitiveProperty.getURI()); boolean declaredAsTransitive = executeAskQuery(query); if(declaredAsTransitive) { + existingAxioms.add(new TransitiveObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as transitive in knowledge base."); } @@ -123,7 +124,7 @@ if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescribe), - computeScore(total, transitive))); + computeScore(total, transitive), declaredAsTransitive)); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-09-26 08:54:46 UTC (rev 3285) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-09-26 21:22:59 UTC (rev 3286) @@ -55,6 +55,12 @@ this.axiom = axiom; this.score = score; } + + public EvaluatedAxiom(Axiom axiom, Score score, boolean asserted) { + this.axiom = axiom; + this.score = score; + this.asserted = asserted; + } public Axiom getAxiom() { return axiom; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-27 08:10:24
|
Revision: 3287 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3287&view=rev Author: lorenz_b Date: 2011-09-27 08:10:17 +0000 (Tue, 27 Sep 2011) Log Message: ----------- Mark datarange axiom if already asserted in the knowledge base. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 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-26 21:22:59 UTC (rev 3286) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-09-27 08:10:17 UTC (rev 3287) @@ -41,6 +41,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,7 +90,10 @@ currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); //get existing range DataRange existingRange = reasoner.getRange(propertyToDescribe); - logger.debug("Existing range: " + existingRange); + if(existingRange != null){ + existingAxioms.add(new DatatypePropertyRangeAxiom(propertyToDescribe, existingRange)); + logger.debug("Existing range: " + existingRange); + } //get objects with datatypes Map<Individual, SortedSet<Datatype>> individual2Datatypes = new HashMap<Individual, SortedSet<Datatype>>(); @@ -135,6 +139,9 @@ for(Entry<Datatype, Integer> entry : sortByValues(result)){ evalAxiom = new EvaluatedAxiom(new DatatypePropertyRangeAxiom(propertyToDescribe, entry.getKey()), computeScore(total, entry.getValue())); + if(existingAxioms.contains(evalAxiom.getAxiom())){ + evalAxiom.setAsserted(true); + } axioms.add(evalAxiom); } @@ -172,9 +179,15 @@ public static void main(String[] args) throws Exception{ SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + + SPARQLReasoner reasoner = new SPARQLReasoner(ks); + reasoner.prepareSubsumptionHierarchy(); + DataPropertyRangeAxiomLearner l = new DataPropertyRangeAxiomLearner(ks); - l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/background")); + l.setReasoner(reasoner); + l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/topSpeed")); l.setMaxExecutionTimeInSeconds(10); + l.setReturnOnlyNewAxioms(true); l.init(); l.start(); System.out.println(l.getCurrentlyBestEvaluatedAxioms(1)); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-26 21:22:59 UTC (rev 3286) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-27 08:10:17 UTC (rev 3287) @@ -41,6 +41,7 @@ import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; +import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; @@ -570,8 +571,20 @@ @Override public DataRange getRange(DatatypeProperty datatypeProperty) { - // TODO Auto-generated method stub - return null; + String query = String.format("SELECT ?range WHERE {" + + "<%s> <%s> ?range. FILTER(isIRI(?range))" + + "}", + datatypeProperty.getName(), RDFS.range.getURI()); + + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + DataRange range = null; + while(rs.hasNext()){ + qs = rs.next(); + range = new Datatype(qs.getResource("range").getURI()); + + } + return range; } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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] |
From: <lor...@us...> - 2011-11-16 20:22:49
|
Revision: 3411 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3411&view=rev Author: lorenz_b Date: 2011-11-16 20:22:43 +0000 (Wed, 16 Nov 2011) Log Message: ----------- Improved algorithm to be aware of asserted subclasses. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.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-11-16 18:36:22 UTC (rev 3410) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-11-16 20:22:43 UTC (rev 3411) @@ -68,6 +68,7 @@ private NamedClass classToDescribe; private List<EvaluatedDescription> currentlyBestEvaluatedDescriptions; + private SortedSet<Description> subClasses; public DisjointClassesLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -94,6 +95,13 @@ Set<NamedClass> classes = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); classes.remove(classToDescribe); + //get the subclasses + if(reasoner.isPrepared()){ + subClasses = reasoner.getClassHierarchy().getSubClasses(classToDescribe, false); + } else { + subClasses = reasoner.getSubClasses(classToDescribe, true); + } + //get classes and how often they occur int limit = 1000; int offset = 0; @@ -188,11 +196,10 @@ Set<NamedClass> completeDisjointclasses = new TreeSet<NamedClass>(allClasses); completeDisjointclasses.removeAll(class2Count.keySet()); - //we remove the asserted sublcasses here - if(reasoner.isPrepared()){ - completeDisjointclasses.removeAll(reasoner.getClassHierarchy().getSubClasses(classToDescribe)); - } else { - completeDisjointclasses.removeAll(reasoner.getSubClasses(classToDescribe)); + //we remove the asserted subclasses here + completeDisjointclasses.removeAll(subClasses); + for(Description subClass : subClasses){ + class2Count.remove(subClass); } @@ -220,8 +227,10 @@ public static void main(String[] args) throws Exception{ DisjointClassesLearner l = new DisjointClassesLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()))); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/ChemicalSubstance")); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Person")); l.init(); + l.getReasoner().prepareSubsumptionHierarchy(); +// System.out.println(l.getReasoner().getClassHierarchy().getSubClasses(new NamedClass("http://dbpedia.org/ontology/Athlete"), false));System.exit(0); l.start(); for(EvaluatedAxiom e : l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE, 0.75)){ Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-11-16 18:36:22 UTC (rev 3410) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-11-16 20:22:43 UTC (rev 3411) @@ -682,6 +682,10 @@ @Override public SortedSet<Description> getSubClasses(Description description) { + return getSubClasses(description, false); + } + + public SortedSet<Description> getSubClasses(Description description, boolean useVirtuoso) { if(!(description instanceof NamedClass || description instanceof Thing)){ throw new IllegalArgumentException("Only named classes are supported."); } @@ -689,11 +693,16 @@ description = new NamedClass(Thing.instance.getURI()); } SortedSet<Description> subClasses = new TreeSet<Description>(); - String query = String.format("SELECT ?sub {?sub <%s> <%s>. FILTER(isIRI(?sub))}", - RDFS.subClassOf.getURI(), - ((NamedClass)description).getURI().toString() - - ); + String query; + if(useVirtuoso){ + query = getAllSubClassesVirtuosoQuery(description); + } else { + query = String.format("SELECT ?sub {?sub <%s> <%s>. FILTER(isIRI(?sub))}", + RDFS.subClassOf.getURI(), + ((NamedClass)description).getURI().toString() + + ); + } ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -702,6 +711,15 @@ } return subClasses; } + + private String getAllSubClassesVirtuosoQuery(Description description){ + String query = String.format( + "SELECT DISTINCT ?sub WHERE {"+ + "{SELECT ?sub ?o where {?sub rdfs:subClassOf ?o.}}"+ + "OPTION ( TRANSITIVE, t_distinct, t_in(?sub), t_out(?o), t_min (1), t_max (8), t_step ('step_no') as ?dist ) ."+ + "FILTER(?o = <%s>)}", description.toString()); + return query; + } @Override public ObjectPropertyHierarchy getObjectPropertyHierarchy() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-16 18:36:28
|
Revision: 3410 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3410&view=rev Author: jenslehmann Date: 2011-11-16 18:36:22 +0000 (Wed, 16 Nov 2011) Log Message: ----------- some fixes for fuzzy learning Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java trunk/components-core/src/main/java/org/dllearner/core/LearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/learningproblems/FuzzyPosNegLPStandard.java Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-11-16 17:42:42 UTC (rev 3409) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-11-16 18:36:22 UTC (rev 3410) @@ -42,6 +42,7 @@ import org.dllearner.utilities.owl.AxiomComparator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; @@ -53,6 +54,7 @@ */ public abstract class AbstractAxiomLearningAlgorithm extends AbstractComponent implements AxiomLearningAlgorithm{ + protected LearningProblem learningProblem; private static final Logger logger = LoggerFactory.getLogger(AbstractAxiomLearningAlgorithm.class); @ConfigOption(name="maxExecutionTimeInSeconds", defaultValue="10", description="", propertyEditorClass=IntegerEditor.class) @@ -75,6 +77,16 @@ existingAxioms = new TreeSet<Axiom>(new AxiomComparator()); } + @Override + public LearningProblem getLearningProblem() { + return learningProblem; + } + + @Autowired + @Override + public void setLearningProblem(LearningProblem learningProblem) { + this.learningProblem = learningProblem; + } ExtendedQueryEngineHTTP queryExecution; Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java 2011-11-16 17:42:42 UTC (rev 3409) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java 2011-11-16 18:36:22 UTC (rev 3410) @@ -283,13 +283,15 @@ * The learning problem variable, which must be used by * all learning algorithm implementations. */ + @Override public AbstractLearningProblem getLearningProblem() { return learningProblem; } @Autowired - public void setLearningProblem(AbstractLearningProblem learningProblem) { - this.learningProblem = learningProblem; + @Override + public void setLearningProblem(LearningProblem learningProblem) { + this.learningProblem = (AbstractLearningProblem) learningProblem; } /** Modified: trunk/components-core/src/main/java/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/LearningAlgorithm.java 2011-11-16 17:42:42 UTC (rev 3409) +++ trunk/components-core/src/main/java/org/dllearner/core/LearningAlgorithm.java 2011-11-16 18:36:22 UTC (rev 3410) @@ -19,7 +19,9 @@ package org.dllearner.core; +import org.springframework.beans.factory.annotation.Autowired; + /** * Basic interface for all DL-Learner learning algorithms. * @@ -34,4 +36,17 @@ */ public abstract void start(); + /** + * Get underlying learning problem. + * @return Underlying learning problem. + */ + public LearningProblem getLearningProblem(); + + /** + * Set the learning problem, which the algorithm should solve. + * @param learningProblem The learning problem to solve. + */ + @Autowired + public void setLearningProblem(LearningProblem learningProblem); + } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/FuzzyPosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/FuzzyPosNegLPStandard.java 2011-11-16 17:42:42 UTC (rev 3409) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/FuzzyPosNegLPStandard.java 2011-11-16 18:36:22 UTC (rev 3410) @@ -91,7 +91,9 @@ // approxDelta = configurator.getApproxAccuracy(); String accM = getAccuracyMethod(); - if(accM.equals("standard")) { + if(accM == null) { + heuristic = HeuristicType.FMEASURE; // use F-Measure by default + } else if(accM.equals("standard")) { heuristic = HeuristicType.AMEASURE; } else if(accM.equals("fmeasure")) { heuristic = HeuristicType.FMEASURE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-23 14:24:26
|
Revision: 3432 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3432&view=rev Author: lorenz_b Date: 2011-11-23 14:24:16 +0000 (Wed, 23 Nov 2011) Log Message: ----------- Added option to use the class popularity in the score. Added method to get the number of instances for a given class. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.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-11-23 13:16:44 UTC (rev 3431) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-11-23 14:24:16 UTC (rev 3432) @@ -75,6 +75,7 @@ private boolean useWordNetDistance = false; private boolean suggestMostGeneralClasses = true; + private boolean useClassPopularity = true; public DisjointClassesLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -239,7 +240,14 @@ SortedSet<Description> mostGeneralClasses = reasoner.getClassHierarchy().getMostGeneralClasses(); } for(NamedClass cls : completeDisjointclasses){ - evalDesc = new EvaluatedDescription(cls, new AxiomScore(1)); + if(useClassPopularity){ + double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(reasoner.getIndividualsCount(cls), 0); + double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; + evalDesc = new EvaluatedDescription(cls, new AxiomScore(1- accuracy)); + } else { + evalDesc = new EvaluatedDescription(cls, new AxiomScore(1)); + } + evalDescs.add(evalDesc); } @@ -268,7 +276,7 @@ public static void main(String[] args) throws Exception{ DisjointClassesLearner l = new DisjointClassesLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()))); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/AdministrativeRegion")); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/SoccerClub")); l.init(); l.getReasoner().prepareSubsumptionHierarchy(); // System.out.println(l.getReasoner().getClassHierarchy().getSubClasses(new NamedClass("http://dbpedia.org/ontology/Athlete"), false));System.exit(0); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-11-23 13:16:44 UTC (rev 3431) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-11-23 14:24:16 UTC (rev 3432) @@ -568,6 +568,17 @@ } return null; } + + public int getIndividualsCount(NamedClass nc){ + String query = String.format("SELECT COUNT(?s) WHERE {" + + "?s a ?type." + + "}", + nc.getURI()); + ResultSet rs = executeSelectQuery(query); + int cnt = rs.next().get(rs.getResultVars().get(0)).asLiteral().getInt(); + return cnt; + + } @Override public DataRange getRange(DatatypeProperty datatypeProperty) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-12-01 11:25:23
|
Revision: 3458 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3458&view=rev Author: jenslehmann Date: 2011-12-01 11:25:16 +0000 (Thu, 01 Dec 2011) Log Message: ----------- extended Manchester Syntax Parser such that < and > are now optional for URIs Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserConstants.java trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj Modified: trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java 2011-12-01 11:01:47 UTC (rev 3457) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java 2011-12-01 11:25:16 UTC (rev 3458) @@ -71,8 +71,10 @@ @Override public void setAsText(String arg0) throws IllegalArgumentException { // we assume that the start class string is given in Manchester syntax +// System.out.println("parser string: " + arg0); try { description = ManchesterSyntaxParser.parseClassExpression(arg0); +// System.out.println("parsed: " + description); } catch (ParseException e) { throw new IllegalArgumentException(e); } Modified: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java 2011-12-01 11:01:47 UTC (rev 3457) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java 2011-12-01 11:25:16 UTC (rev 3458) @@ -28,32 +28,32 @@ default: jj_la1[0] = jj_gen; if (jj_2_1(2147483647)) { - jj_consume_token(21); + jj_consume_token(22); c1 = ClassExpression(); jj_consume_token(AND); c2 = ClassExpression(); - jj_consume_token(22); + jj_consume_token(23); {if (true) return new Intersection(c1,c2);} } else if (jj_2_2(2147483647)) { - jj_consume_token(21); + jj_consume_token(22); c1 = ClassExpression(); jj_consume_token(OR); c2 = ClassExpression(); - jj_consume_token(22); + jj_consume_token(23); {if (true) return new Union(c1,c2);} } else if (jj_2_3(2147483647)) { - jj_consume_token(21); + jj_consume_token(22); s = URI(); jj_consume_token(SOME); c = ClassExpression(); - jj_consume_token(22); + jj_consume_token(23); {if (true) return new ObjectSomeRestriction(new ObjectProperty(s),c);} } else if (jj_2_4(2147483647)) { - jj_consume_token(21); + jj_consume_token(22); s = URI(); jj_consume_token(ONLY); c = ClassExpression(); - jj_consume_token(22); + jj_consume_token(23); {if (true) return new ObjectAllRestriction(new ObjectProperty(s),c);} } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -66,7 +66,7 @@ jj_consume_token(GE); i = Integer(); s = URI(); - jj_consume_token(23); + jj_consume_token(24); c = ClassExpression(); {if (true) return new ObjectMinCardinalityRestriction(i,new ObjectProperty(s),c);} break; @@ -74,29 +74,30 @@ jj_consume_token(LE); i = Integer(); s = URI(); - jj_consume_token(23); + jj_consume_token(24); c = ClassExpression(); {if (true) return new ObjectMaxCardinalityRestriction(i,new ObjectProperty(s),c);} break; default: jj_la1[1] = jj_gen; if (jj_2_5(4)) { - jj_consume_token(21); + jj_consume_token(22); s1 = URI(); - jj_consume_token(24); + jj_consume_token(25); s2 = URI(); - jj_consume_token(22); + jj_consume_token(23); {if (true) return new ObjectValueRestriction(new ObjectProperty(s1), new Individual(s2));} } else if (jj_2_6(4)) { - jj_consume_token(21); + jj_consume_token(22); s1 = URI(); - jj_consume_token(24); + jj_consume_token(25); s2 = String(); - jj_consume_token(22); + jj_consume_token(23); {if (true) return new StringValueRestriction(new DatatypeProperty(s1), s2);} } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case URI: + case URI_PREFIX: s = URI(); {if (true) return new NamedClass(s);} break; @@ -140,11 +141,24 @@ final public String URI() throws ParseException { Token t; String s; - t = jj_consume_token(URI); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case URI_PREFIX: + // LOOKAHEAD("<") + t = jj_consume_token(URI_PREFIX); // cut "<" and ">" s = t.image; s = s.substring(1, s.length() - 1); {if (true) return s;} + break; + case URI: + t = jj_consume_token(URI); + {if (true) return t.image;} + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } throw new Error("Missing return statement in function"); } @@ -190,30 +204,21 @@ finally { jj_save(5, xla); } } - private boolean jj_3R_8() { - if (jj_scan_token(21)) return true; - if (jj_3R_2()) return true; - if (jj_scan_token(SOME)) return true; - if (jj_3R_1()) return true; + private boolean jj_3R_7() { if (jj_scan_token(22)) return true; - return false; - } - - private boolean jj_3R_7() { - if (jj_scan_token(21)) return true; if (jj_3R_1()) return true; if (jj_scan_token(OR)) return true; if (jj_3R_1()) return true; - if (jj_scan_token(22)) return true; + if (jj_scan_token(23)) return true; return false; } private boolean jj_3R_6() { - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; if (jj_3R_1()) return true; if (jj_scan_token(AND)) return true; if (jj_3R_1()) return true; - if (jj_scan_token(22)) return true; + if (jj_scan_token(23)) return true; return false; } @@ -267,48 +272,63 @@ return false; } - private boolean jj_3R_14() { + private boolean jj_3R_16() { if (jj_scan_token(NUMBER)) return true; return false; } + private boolean jj_3R_15() { + if (jj_scan_token(URI)) return true; + return false; + } + private boolean jj_3R_13() { if (jj_3R_2()) return true; return false; } + private boolean jj_3R_14() { + if (jj_scan_token(URI_PREFIX)) return true; + return false; + } + private boolean jj_3R_2() { - if (jj_scan_token(URI)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_14()) { + jj_scanpos = xsp; + if (jj_3R_15()) return true; + } return false; } private boolean jj_3_6() { - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; if (jj_3R_2()) return true; - if (jj_scan_token(24)) return true; + if (jj_scan_token(25)) return true; if (jj_3R_3()) return true; - if (jj_scan_token(22)) return true; + if (jj_scan_token(23)) return true; return false; } private boolean jj_3_4() { - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; if (jj_3R_2()) return true; if (jj_scan_token(ONLY)) return true; return false; } private boolean jj_3_5() { - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; if (jj_3R_2()) return true; - if (jj_scan_token(24)) return true; + if (jj_scan_token(25)) return true; if (jj_3R_2()) return true; - if (jj_scan_token(22)) return true; + if (jj_scan_token(23)) return true; return false; } private boolean jj_3_3() { - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; if (jj_3R_2()) return true; if (jj_scan_token(SOME)) return true; return false; @@ -316,15 +336,15 @@ private boolean jj_3R_12() { if (jj_scan_token(LE)) return true; - if (jj_3R_14()) return true; + if (jj_3R_16()) return true; if (jj_3R_2()) return true; - if (jj_scan_token(23)) return true; + if (jj_scan_token(24)) return true; if (jj_3R_1()) return true; return false; } private boolean jj_3_2() { - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; if (jj_3R_1()) return true; if (jj_scan_token(OR)) return true; return false; @@ -332,9 +352,9 @@ private boolean jj_3R_11() { if (jj_scan_token(GE)) return true; - if (jj_3R_14()) return true; + if (jj_3R_16()) return true; if (jj_3R_2()) return true; - if (jj_scan_token(23)) return true; + if (jj_scan_token(24)) return true; if (jj_3R_1()) return true; return false; } @@ -346,18 +366,18 @@ } private boolean jj_3_1() { - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; if (jj_3R_1()) return true; if (jj_scan_token(AND)) return true; return false; } private boolean jj_3R_9() { - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; if (jj_3R_2()) return true; if (jj_scan_token(ONLY)) return true; if (jj_3R_1()) return true; - if (jj_scan_token(22)) return true; + if (jj_scan_token(23)) return true; return false; } @@ -366,6 +386,15 @@ return false; } + private boolean jj_3R_8() { + if (jj_scan_token(22)) return true; + if (jj_3R_2()) return true; + if (jj_scan_token(SOME)) return true; + if (jj_3R_1()) return true; + if (jj_scan_token(23)) return true; + return false; + } + /** Generated Token Manager. */ public ManchesterSyntaxParserTokenManager token_source; SimpleCharStream jj_input_stream; @@ -377,13 +406,13 @@ private Token jj_scanpos, jj_lastpos; private int jj_la; private int jj_gen; - final private int[] jj_la1 = new int[3]; + final private int[] jj_la1 = new int[4]; static private int[] jj_la1_0; static { jj_la1_init_0(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0xc00,0x70000,0x100000,}; + jj_la1_0 = new int[] {0xc00,0x70000,0x300000,0x300000,}; } final private JJCalls[] jj_2_rtns = new JJCalls[6]; private boolean jj_rescan = false; @@ -400,7 +429,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -415,7 +444,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -426,7 +455,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -437,7 +466,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -447,7 +476,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -457,7 +486,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -569,12 +598,12 @@ /** Generate ParseException. */ public ParseException generateParseException() { jj_expentries.clear(); - boolean[] la1tokens = new boolean[25]; + boolean[] la1tokens = new boolean[26]; if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 4; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<<j)) != 0) { @@ -583,7 +612,7 @@ } } } - for (int i = 0; i < 25; i++) { + for (int i = 0; i < 26; i++) { if (la1tokens[i]) { jj_expentry = new int[1]; jj_expentry[0] = i; Modified: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserConstants.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserConstants.java 2011-12-01 11:01:47 UTC (rev 3457) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserConstants.java 2011-12-01 11:25:16 UTC (rev 3458) @@ -42,6 +42,8 @@ int STRING = 19; /** RegularExpression Id. */ int URI = 20; + /** RegularExpression Id. */ + int URI_PREFIX = 21; /** Lexical state. */ int DEFAULT = 0; @@ -69,6 +71,7 @@ "\"<=\"", "<STRING>", "<URI>", + "<URI_PREFIX>", "\"(\"", "\")\"", "\".\"", Modified: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java 2011-12-01 11:01:47 UTC (rev 3457) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java 2011-12-01 11:25:16 UTC (rev 3458) @@ -18,12 +18,28 @@ { case 0: if ((active0 & 0x40000L) != 0L) - return 34; + return 39; + if ((active0 & 0x3c1fc06L) != 0L) + return 40; return -1; case 1: if ((active0 & 0x40000L) != 0L) - return 34; + return 39; + if ((active0 & 0x201fc00L) != 0L) + return 40; return -1; + case 2: + if ((active0 & 0x201dc00L) != 0L) + return 40; + return -1; + case 3: + if ((active0 & 0x200c800L) != 0L) + return 40; + return -1; + case 4: + if ((active0 & 0x2000800L) != 0L) + return 40; + return -1; default : return -1; } @@ -42,12 +58,16 @@ { switch(curChar) { + case 9: + return jjStartNfaWithStates_0(0, 2, 40); + case 32: + return jjStartNfaWithStates_0(0, 1, 40); case 40: - return jjStopAtPos(0, 21); + return jjStartNfaWithStates_0(0, 22, 40); case 41: - return jjStopAtPos(0, 22); + return jjStartNfaWithStates_0(0, 23, 40); case 46: - return jjStopAtPos(0, 23); + return jjStartNfaWithStates_0(0, 24, 40); case 60: return jjMoveStringLiteralDfa1_0(0x40000L); case 62: @@ -65,7 +85,7 @@ case 115: return jjMoveStringLiteralDfa1_0(0x4000L); case 118: - return jjMoveStringLiteralDfa1_0(0x1000000L); + return jjMoveStringLiteralDfa1_0(0x2000000L); default : return jjMoveNfa_0(0, 0); } @@ -83,19 +103,19 @@ if ((active0 & 0x20000L) != 0L) return jjStopAtPos(1, 17); else if ((active0 & 0x40000L) != 0L) - return jjStartNfaWithStates_0(1, 18, 34); + return jjStartNfaWithStates_0(1, 18, 39); break; case 79: return jjMoveStringLiteralDfa2_0(active0, 0xc00L); case 97: - return jjMoveStringLiteralDfa2_0(active0, 0x1000000L); + return jjMoveStringLiteralDfa2_0(active0, 0x2000000L); case 110: return jjMoveStringLiteralDfa2_0(active0, 0x9000L); case 111: return jjMoveStringLiteralDfa2_0(active0, 0x14000L); case 114: if ((active0 & 0x2000L) != 0L) - return jjStopAtPos(1, 13); + return jjStartNfaWithStates_0(1, 13, 40); break; default : break; @@ -115,21 +135,21 @@ { case 80: if ((active0 & 0x400L) != 0L) - return jjStopAtPos(2, 10); + return jjStartNfaWithStates_0(2, 10, 40); break; case 84: return jjMoveStringLiteralDfa3_0(active0, 0x800L); case 100: if ((active0 & 0x1000L) != 0L) - return jjStopAtPos(2, 12); + return jjStartNfaWithStates_0(2, 12, 40); break; case 108: - return jjMoveStringLiteralDfa3_0(active0, 0x1008000L); + return jjMoveStringLiteralDfa3_0(active0, 0x2008000L); case 109: return jjMoveStringLiteralDfa3_0(active0, 0x4000L); case 116: if ((active0 & 0x10000L) != 0L) - return jjStopAtPos(2, 16); + return jjStartNfaWithStates_0(2, 16, 40); break; default : break; @@ -151,13 +171,13 @@ return jjMoveStringLiteralDfa4_0(active0, 0x800L); case 101: if ((active0 & 0x4000L) != 0L) - return jjStopAtPos(3, 14); + return jjStartNfaWithStates_0(3, 14, 40); break; case 117: - return jjMoveStringLiteralDfa4_0(active0, 0x1000000L); + return jjMoveStringLiteralDfa4_0(active0, 0x2000000L); case 121: if ((active0 & 0x8000L) != 0L) - return jjStopAtPos(3, 15); + return jjStartNfaWithStates_0(3, 15, 40); break; default : break; @@ -178,8 +198,8 @@ case 79: return jjMoveStringLiteralDfa5_0(active0, 0x800L); case 101: - if ((active0 & 0x1000000L) != 0L) - return jjStopAtPos(4, 24); + if ((active0 & 0x2000000L) != 0L) + return jjStartNfaWithStates_0(4, 25, 40); break; default : break; @@ -199,7 +219,7 @@ { case 77: if ((active0 & 0x800L) != 0L) - return jjStopAtPos(5, 11); + return jjStartNfaWithStates_0(5, 11, 40); break; default : break; @@ -220,7 +240,7 @@ private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 34; + jjnewStateCnt = 39; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -235,7 +255,27 @@ { switch(jjstateSet[--i]) { + case 39: + if ((0xbfffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(10, 11); + if (curChar == 58) + jjCheckNAddTwoStates(12, 13); + break; + case 40: + if ((0xafffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(6, 7); + if (curChar == 58) + { + if (kind > 20) + kind = 20; + jjCheckNAdd(8); + } + break; case 0: + if ((0xafffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(6, 7); + else if (curChar == 60) + jjCheckNAddTwoStates(10, 11); if ((0x3fe000000000000L & l) != 0L) { if (kind > 8) @@ -246,26 +286,21 @@ { if (kind > 8) kind = 8; - jjCheckNAdd(31); + jjCheckNAdd(36); } else if (curChar == 47) jjAddStates(3, 5); - else if (curChar == 60) - jjCheckNAddTwoStates(7, 8); + else if (curChar == 58) + { + if (kind > 20) + kind = 20; + jjCheckNAdd(8); + } else if (curChar == 39) jjCheckNAddTwoStates(4, 5); else if (curChar == 34) jjCheckNAddTwoStates(1, 2); break; - case 34: - if ((0xbfffffffffffdbffL & l) != 0L) - jjCheckNAddTwoStates(7, 8); - else if (curChar == 62) - { - if (kind > 20) - kind = 20; - } - break; case 1: if ((0xfffffffbffffdbffL & l) != 0L) jjCheckNAddTwoStates(1, 2); @@ -287,131 +322,157 @@ kind = 19; break; case 6: - if (curChar == 60) - jjCheckNAddTwoStates(7, 8); + if ((0xafffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(6, 7); break; case 7: - if ((0xbfffffffffffdbffL & l) != 0L) - jjCheckNAddTwoStates(7, 8); + if (curChar != 58) + break; + if (kind > 20) + kind = 20; + jjCheckNAdd(8); break; case 8: - if (curChar == 62 && kind > 20) + if ((0xafffffffffffdbffL & l) == 0L) + break; + if (kind > 20) kind = 20; + jjCheckNAdd(8); break; case 9: + if (curChar == 60) + jjCheckNAddTwoStates(10, 11); + break; + case 10: + if ((0xbfffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(10, 11); + break; + case 11: + if (curChar == 58) + jjCheckNAddTwoStates(12, 13); + break; + case 12: + if ((0xbfffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(12, 13); + break; + case 13: + if (curChar == 62 && kind > 21) + kind = 21; + break; + case 14: if (curChar == 47) jjAddStates(3, 5); break; - case 10: + case 15: if (curChar == 47) jjCheckNAddStates(6, 8); break; - case 11: + case 16: if ((0xffffffffffffdbffL & l) != 0L) jjCheckNAddStates(6, 8); break; - case 12: + case 17: if ((0x2400L & l) != 0L && kind > 5) kind = 5; break; - case 13: + case 18: if (curChar == 10 && kind > 5) kind = 5; break; - case 14: + case 19: if (curChar == 13) - jjstateSet[jjnewStateCnt++] = 13; + jjstateSet[jjnewStateCnt++] = 18; break; - case 15: + case 20: if (curChar == 42) - jjCheckNAddTwoStates(16, 17); + jjCheckNAddTwoStates(21, 22); break; - case 16: + case 21: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddTwoStates(16, 17); + jjCheckNAddTwoStates(21, 22); break; - case 17: + case 22: if (curChar == 42) jjCheckNAddStates(9, 11); break; - case 18: + case 23: if ((0xffff7bffffffffffL & l) != 0L) - jjCheckNAddTwoStates(19, 17); + jjCheckNAddTwoStates(24, 22); break; - case 19: + case 24: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddTwoStates(19, 17); + jjCheckNAddTwoStates(24, 22); break; - case 20: + case 25: if (curChar == 47 && kind > 6) kind = 6; break; - case 21: + case 26: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 15; + jjstateSet[jjnewStateCnt++] = 20; break; - case 22: + case 27: if (curChar == 42) - jjCheckNAddTwoStates(23, 24); + jjCheckNAddTwoStates(28, 29); break; - case 23: + case 28: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddTwoStates(23, 24); + jjCheckNAddTwoStates(28, 29); break; - case 24: + case 29: if (curChar == 42) jjCheckNAddStates(12, 14); break; - case 25: + case 30: if ((0xffff7bffffffffffL & l) != 0L) - jjCheckNAddTwoStates(26, 24); + jjCheckNAddTwoStates(31, 29); break; - case 26: + case 31: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddTwoStates(26, 24); + jjCheckNAddTwoStates(31, 29); break; - case 27: + case 32: if (curChar == 47 && kind > 7) kind = 7; break; - case 28: + case 33: if ((0x3fe000000000000L & l) == 0L) break; if (kind > 8) kind = 8; jjCheckNAddStates(0, 2); break; - case 29: + case 34: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 8) kind = 8; - jjCheckNAdd(29); + jjCheckNAdd(34); break; - case 30: + case 35: if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(30, 31); + jjCheckNAddTwoStates(35, 36); break; - case 31: + case 36: if (curChar != 46) break; if (kind > 9) kind = 9; - jjCheckNAdd(32); + jjCheckNAdd(37); break; - case 32: + case 37: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 9) kind = 9; - jjCheckNAdd(32); + jjCheckNAdd(37); break; - case 33: + case 38: if (curChar != 48) break; if (kind > 8) kind = 8; - jjCheckNAdd(31); + jjCheckNAdd(36); break; default : break; } @@ -424,11 +485,20 @@ { switch(jjstateSet[--i]) { - case 34: - case 7: + case 39: + case 10: if ((0xffffffffefffffffL & l) != 0L) - jjCheckNAddTwoStates(7, 8); + jjCheckNAddTwoStates(10, 11); break; + case 40: + case 6: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAddTwoStates(6, 7); + break; + case 0: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAddTwoStates(6, 7); + break; case 1: if ((0xffffffffefffffffL & l) != 0L) jjAddStates(15, 16); @@ -437,23 +507,34 @@ if ((0xffffffffefffffffL & l) != 0L) jjAddStates(17, 18); break; - case 11: - jjAddStates(6, 8); + case 8: + if ((0xffffffffefffffffL & l) == 0L) + break; + if (kind > 20) + kind = 20; + jjstateSet[jjnewStateCnt++] = 8; break; + case 12: + if ((0xffffffffefffffffL & l) != 0L) + jjAddStates(19, 20); + break; case 16: - jjCheckNAddTwoStates(16, 17); + jjAddStates(6, 8); break; - case 18: - case 19: - jjCheckNAddTwoStates(19, 17); + case 21: + jjCheckNAddTwoStates(21, 22); break; case 23: - jjCheckNAddTwoStates(23, 24); + case 24: + jjCheckNAddTwoStates(24, 22); break; - case 25: - case 26: - jjCheckNAddTwoStates(26, 24); + case 28: + jjCheckNAddTwoStates(28, 29); break; + case 30: + case 31: + jjCheckNAddTwoStates(31, 29); + break; default : break; } } while(i != startsAt); @@ -466,11 +547,20 @@ { switch(jjstateSet[--i]) { - case 34: - case 7: + case 39: + case 10: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(7, 8); + jjCheckNAddTwoStates(10, 11); break; + case 40: + case 6: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(6, 7); + break; + case 0: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(6, 7); + break; case 1: if ((jjbitVec0[i2] & l2) != 0L) jjAddStates(15, 16); @@ -479,28 +569,39 @@ if ((jjbitVec0[i2] & l2) != 0L) jjAddStates(17, 18); break; - case 11: + case 8: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 20) + kind = 20; + jjstateSet[jjnewStateCnt++] = 8; + break; + case 12: if ((jjbitVec0[i2] & l2) != 0L) - jjAddStates(6, 8); + jjAddStates(19, 20); break; case 16: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(16, 17); + jjAddStates(6, 8); break; - case 18: - case 19: + case 21: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(19, 17); + jjCheckNAddTwoStates(21, 22); break; case 23: + case 24: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(23, 24); + jjCheckNAddTwoStates(24, 22); break; - case 25: - case 26: + case 28: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(26, 24); + jjCheckNAddTwoStates(28, 29); break; + case 30: + case 31: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(31, 29); + break; default : break; } } while(i != startsAt); @@ -512,36 +613,37 @@ kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 34 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 39 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } static final int[] jjnextStates = { - 29, 30, 31, 10, 21, 22, 11, 12, 14, 17, 18, 20, 24, 25, 27, 1, - 2, 4, 5, + 34, 35, 36, 15, 26, 27, 16, 17, 19, 22, 23, 25, 29, 30, 32, 1, + 2, 4, 5, 12, 13, }; /** Token literal values. */ public static final String[] jjstrLiteralImages = { "", null, null, null, null, null, null, null, null, null, "\124\117\120", "\102\117\124\124\117\115", "\141\156\144", "\157\162", "\163\157\155\145", "\157\156\154\171", -"\156\157\164", "\76\75", "\74\75", null, null, "\50", "\51", "\56", "\166\141\154\165\145", }; +"\156\157\164", "\76\75", "\74\75", null, null, null, "\50", "\51", "\56", +"\166\141\154\165\145", }; /** Lexer state names. */ public static final String[] lexStateNames = { "DEFAULT", }; static final long[] jjtoToken = { - 0x1ffff01L, + 0x3ffff01L, }; static final long[] jjtoSkip = { 0xfeL, }; protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[34]; -private final int[] jjstateSet = new int[68]; +private final int[] jjrounds = new int[39]; +private final int[] jjstateSet = new int[78]; protected char curChar; /** Constructor. */ public ManchesterSyntaxParserTokenManager(SimpleCharStream stream){ @@ -568,7 +670,7 @@ { int i; jjround = 0x80000001; - for (i = 34; i-- > 0;) + for (i = 39; i-- > 0;) jjrounds[i] = 0x80000000; } @@ -640,7 +742,7 @@ } try { input_stream.backup(0); - while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) + while (curChar <= 13 && (0x2400L & (1L << curChar)) != 0L) curChar = input_stream.BeginToken(); } catch (java.io.IOException e1) { continue EOFLoop; } Modified: trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj 2011-12-01 11:01:47 UTC (rev 3457) +++ trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj 2011-12-01 11:25:16 UTC (rev 3458) @@ -66,7 +66,10 @@ | < LE: "<=" > // support single quotes and double quotes | < STRING: "\"" (~["\"","\\","\n","\r"])* "\"" | "'" (~["\"","\\","\n","\r"])* "'"> - | < URI: "<" (~[">","\\","\n","\r"])* ">" > +// | < URI: "<" (~[">","\\","\n","\r"])* ">" > + | < URI: (~["<",">","\\","\n","\r"])* ":" (~["<",">","\\","\n","\r"])* > + | < URI_PREFIX: "<" (~[">","\\","\n","\r"])* ":" (~[">","\\","\n","\r"])* ">" > +// | <URI: ["<"] (~[ ">","<", "\"", "{", "}", "^", "\\", "|", "`", "\u0000"-"\u0020"])* ">"? > } Description ClassExpression() : @@ -150,11 +153,13 @@ String s; } { - t=<URI> + // LOOKAHEAD("<") + t=<URI_PREFIX> { // cut "<" and ">" s = t.image; s = s.substring(1, s.length() - 1); return s; } + | t=<URI> { return t.image; } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-05 13:09:01
|
Revision: 3472 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3472&view=rev Author: lorenz_b Date: 2011-12-05 13:08:51 +0000 (Mon, 05 Dec 2011) Log Message: ----------- Small improvement. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.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-12-05 09:42:14 UTC (rev 3471) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-05 13:08:51 UTC (rev 3472) @@ -241,7 +241,10 @@ } for(NamedClass cls : completeDisjointclasses){ if(useClassPopularity){ - double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(reasoner.getIndividualsCount(cls), 0); + int popularity = reasoner.getIndividualsCount(cls); + //we skip classes with no instances + if(popularity == 0) continue; + double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(popularity, 0); double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; evalDesc = new EvaluatedDescription(cls, new AxiomScore(1- accuracy)); } else { @@ -276,7 +279,7 @@ public static void main(String[] args) throws Exception{ DisjointClassesLearner l = new DisjointClassesLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()))); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/SoccerClub")); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Band")); l.init(); l.getReasoner().prepareSubsumptionHierarchy(); // System.out.println(l.getReasoner().getClassHierarchy().getSubClasses(new NamedClass("http://dbpedia.org/ontology/Athlete"), false));System.exit(0); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-12-05 09:42:14 UTC (rev 3471) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-12-05 13:08:51 UTC (rev 3472) @@ -571,7 +571,7 @@ public int getIndividualsCount(NamedClass nc){ String query = String.format("SELECT COUNT(?s) WHERE {" + - "?s a ?type." + + "?s a <%s>." + "}", nc.getURI()); ResultSet rs = executeSelectQuery(query); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-12 14:37:07
|
Revision: 3498 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3498&view=rev Author: lorenz_b Date: 2011-12-12 14:36:59 +0000 (Mon, 12 Dec 2011) Log Message: ----------- Updated chunk of algorithms to work with SPARQL endpoints, which not support COUNT queries. Fixed problem in hierarchy, which occurs when triples of type [<cls> <rdfs:subClassOf> <cls>] occur in the knowledge base. 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/AsymmetricObjectPropertyAxiomLearner.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/InverseObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/WordnetSimilarity.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/utilities/ICFinder.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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -77,6 +77,8 @@ private boolean suggestMostGeneralClasses = true; private boolean useClassPopularity = true; + private Set<NamedClass> allClasses; + public DisjointClassesLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -115,8 +117,8 @@ //TODO //at first get all existing classes in knowledgebase - Set<NamedClass> classes = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); - classes.remove(classToDescribe); + allClasses = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); + allClasses.remove(classToDescribe); //get the subclasses if(reasoner.isPrepared()){ @@ -125,46 +127,97 @@ subClasses = reasoner.getSubClasses(classToDescribe, true); } + if(ks.supportsSPARQL_1_1()){ + runSPARQL1_1_Mode(); + } else { + runSPARQL1_0_Mode(); + } + //get classes and how often they occur - int limit = 1000; - int offset = 0; - String queryTemplate = "SELECT ?type COUNT(?s) AS ?count WHERE {?s a ?type." + - "{SELECT ?s WHERE {?s a <%s>.} LIMIT %d OFFSET %d}" + - "}"; - String query; - Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); - NamedClass cls; - Integer oldCnt; - boolean repeat = true; - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, classToDescribe, limit, offset); - ResultSet rs = executeSelectQuery(query); - QuerySolution qs; - repeat = false; - while(rs.hasNext()){ - qs = rs.next(); - cls = new NamedClass(qs.getResource("type").getURI()); - int newCnt = qs.getLiteral("count").getInt(); - oldCnt = result.get(cls); - if(oldCnt == null){ - oldCnt = Integer.valueOf(newCnt); - } else { - oldCnt += newCnt; - } - - result.put(cls, oldCnt); - qs.getLiteral("count").getInt(); - repeat = true; - } - if(!result.isEmpty()){ - currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, classes); - offset += 1000; - } - } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + + private void runSPARQL1_0_Mode(){ + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?s ?type WHERE {?s a <%s>. ?s a ?type.} LIMIT %d OFFSET %d"; + String query; + Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); + NamedClass cls; + Integer oldCnt; + boolean repeat = true; + + int total = 0; + + String resource = ""; + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, classToDescribe, limit, offset); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + String newResource = qs.getResource("?s").getURI(); + if(newResource != resource){ + total++; + resource = newResource; + } + cls = new NamedClass(qs.getResource("type").getURI()); + oldCnt = result.get(cls); + if(oldCnt == null){ + oldCnt = Integer.valueOf(0); + } + int newCnt = oldCnt + 1; + + result.put(cls, newCnt); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, total); + offset += 1000; + } + } + } + + private void runSPARQL1_1_Mode(){ + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?type COUNT(?s) AS ?count WHERE {?s a ?type." + + "{SELECT ?s WHERE {?s a <%s>.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); + NamedClass cls; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, classToDescribe, limit, offset); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + cls = new NamedClass(qs.getResource("type").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(cls); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } else { + oldCnt += newCnt; + } + + result.put(cls, oldCnt); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, allClasses); + offset += 1000; + } + } + } @Override public List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions) { @@ -269,6 +322,63 @@ return evalDescs; } + private List<EvaluatedDescription> buildEvaluatedClassDescriptions(Map<NamedClass, Integer> class2Count, int total){ + List<EvaluatedDescription> evalDescs = new ArrayList<EvaluatedDescription>(); + + //Remove temporarily classToDescribe but keep track of their count + class2Count.remove(classToDescribe); + + //get complete disjoint classes + Set<NamedClass> completeDisjointclasses = new TreeSet<NamedClass>(allClasses); + completeDisjointclasses.removeAll(class2Count.keySet()); + + //drop all classes which have a super class in this set + if(suggestMostGeneralClasses && reasoner.isPrepared()){ + keepMostGeneralClasses(completeDisjointclasses); + } + + //we remove the asserted subclasses here + completeDisjointclasses.removeAll(subClasses); + for(Description subClass : subClasses){ + class2Count.remove(subClass); + } + + + EvaluatedDescription evalDesc; + //firstly, create disjoint classexpressions which not occur and give score of 1 + if(reasoner.isPrepared()){ + SortedSet<Description> mostGeneralClasses = reasoner.getClassHierarchy().getMostGeneralClasses(); + } + for(NamedClass cls : completeDisjointclasses){ + if(useClassPopularity){ + int popularity = reasoner.getIndividualsCount(cls); + //we skip classes with no instances + if(popularity == 0) continue; + double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(popularity, 0); + double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; + evalDesc = new EvaluatedDescription(cls, new AxiomScore(1- accuracy)); + } else { + evalDesc = new EvaluatedDescription(cls, new AxiomScore(1)); + } + + evalDescs.add(evalDesc); + } + + //secondly, create disjoint classexpressions with score 1 - (#occurence/#all) + for(Entry<NamedClass, Integer> entry : sortByValues(class2Count)){ +// evalDesc = new EvaluatedDescription(entry.getKey(), +// new AxiomScore(1 - (entry.getValue() / (double)all))); + double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, entry.getValue()); + double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; + evalDesc = new EvaluatedDescription(entry.getKey(), + new AxiomScore(1 - accuracy)); + evalDescs.add(evalDesc); + } + + class2Count.put(classToDescribe, total); + return evalDescs; + } + private void keepMostGeneralClasses(Set<NamedClass> classes){ ClassHierarchy h = reasoner.getClassHierarchy(); for(NamedClass nc : new HashSet<NamedClass>(classes)){ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -129,7 +129,6 @@ logger.info("Existing super classes: " + existingSuperClasses); } - Map<Individual, SortedSet<Description>> ind2Types = new HashMap<Individual, SortedSet<Description>>(); int limit = 1000; boolean repeat = true; @@ -142,7 +141,7 @@ logger.info("...finished in {}ms. (Got {} rows)", (System.currentTimeMillis()-startTime), fetchedRows); } - + public NamedClass getClassToDescribe() { return classToDescribe; } @@ -152,10 +151,13 @@ } 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; - 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); -// String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a <%s>. ?ind a ?type} LIMIT %d OFFSET %d", classToDescribe.getName(), limit, offset); + String query; + if(ks.supportsSPARQL_1_1()){ + query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind a <%s>} LIMIT %d OFFSET %d}}", classToDescribe.getName(), limit, offset); + } else { + query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a <%s>. ?ind a ?type} LIMIT %d OFFSET %d", classToDescribe.getName(), limit, offset); + } ResultSet rs = executeSelectQuery(query); Individual ind; Description newType; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2011-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -21,18 +21,14 @@ import java.net.URL; import java.util.ArrayList; -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.ObjectPropertyEditor; import org.dllearner.core.owl.AsymmetricObjectPropertyAxiom; -import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.slf4j.Logger; @@ -40,6 +36,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.OWL2; @ComponentAnn(name="asymmetric objectproperty axiom learner", shortName="oplasymm", version=0.1) @@ -49,6 +47,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; + + private boolean declaredAsymmetric; public AsymmetricObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -71,7 +71,7 @@ //check if property is already declared as asymmetric in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.AsymmetricProperty.getURI()); - boolean declaredAsymmetric = executeAskQuery(query); + declaredAsymmetric = executeAskQuery(query); if(declaredAsymmetric) { existingAxioms.add(new AsymmetricObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as symmetric in knowledge base."); @@ -87,36 +87,42 @@ } private void runSPARQL1_0_Mode(){ - BiHashMultimap<Individual, Individual> individualsMap = new BiHashMultimap<Individual, Individual>(); - boolean repeat = true; + Model model = ModelFactory.createDefaultModel(); 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); + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // get number of instances of s with <s p o> + query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; - Individual s; - Individual o; - int cnt = 0; + int total = 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++; + total = qs.getLiteral("total").getInt(); } - int total = individualsMap.size(); - int asymmetric = 0; + query = "SELECT (COUNT(?s) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query); + int symmetric = 0; + while(rs.hasNext()){ + qs = rs.next(); + symmetric = qs.getLiteral("symmetric").getInt(); + } + int asymmetric = total - symmetric; - for(java.util.Map.Entry<Individual, Individual> e : individualsMap.entries()){ - if(!individualsMap.getInverse().containsEntry(e.getKey(), e.getValue())){ - asymmetric++; - } + if(total > 0){ + currentlyBestAxioms.clear(); + currentlyBestAxioms.add(new EvaluatedAxiom(new AsymmetricObjectPropertyAxiom(propertyToDescribe), + computeScore(total, asymmetric), declaredAsymmetric)); } - - currentlyBestAxioms = Collections.singletonList(new EvaluatedAxiom(new AsymmetricObjectPropertyAxiom(propertyToDescribe), - computeScore(total, asymmetric))); - fetchedRows += limit; - repeat = (cnt == limit); + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } } @@ -142,7 +148,7 @@ if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new AsymmetricObjectPropertyAxiom(propertyToDescribe), - computeScore(total, asymmetric))); + computeScore(total, asymmetric), declaredAsymmetric)); } } 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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -33,6 +33,7 @@ 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.ObjectPropertyEditor; import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; @@ -126,8 +127,11 @@ properties = new HashSet<ObjectProperty>(); properties.add(propertyToDescribe); properties.add(entry.getKey()); - evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(properties), - new AxiomScore(entry.getValue() / (double)all)); + int popularity = reasoner.getPropertyCount(entry.getKey()); + int total = popularity;//Math.max(popularity, all); + int success = entry.getValue();System.out.println(entry.getKey());System.out.println(total);System.out.println(success); + Score score = computeScore(total, success); + evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(properties),score); axioms.add(evalAxiom); } @@ -138,7 +142,7 @@ public static void main(String[] args) throws Exception{ EquivalentObjectPropertyAxiomLearner l = new EquivalentObjectPropertyAxiomLearner(new SparqlEndpointKS(new SparqlEndpoint( new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())));//.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/country")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/thirdDriverCountry")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); 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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -34,6 +34,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="functional dataproperty axiom learner", shortName="dplfunc", version=0.1) @@ -43,6 +45,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; + + private boolean declaredAsFunctional; public FunctionalDataPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -65,35 +69,90 @@ //check if property is already declared as functional in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); - boolean declaredAsFunctional = executeAskQuery(query); + declaredAsFunctional = executeAskQuery(query); if(declaredAsFunctional) { existingAxioms.add(new FunctionalDatatypePropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as functional in knowledge base."); } - //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()); + 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() { + Model model = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // 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 = executeSelectQuery(query); + QuerySolution qs; + int all = 1; + while (rs.hasNext()) { + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + } + // get number of instances of s with <s p o> <s p o1> where o != o1 + query = "SELECT (COUNT(DISTINCT ?s) AS ?notfunctional) WHERE {?s <%s> ?o. ?s <%s> ?o1. FILTER(?o != ?o1) }"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query); + int notFunctional = 1; + while (rs.hasNext()) { + qs = rs.next(); + notFunctional = qs.getLiteral("notfunctional").getInt(); + } + if (all > 0) { + currentlyBestAxioms.clear(); + currentlyBestAxioms.add(new EvaluatedAxiom( + new FunctionalDatatypePropertyAxiom(propertyToDescribe), + computeScore(all, all - notFunctional), + declaredAsFunctional)); + } + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } + } + + private void runSPARQL1_1_Mode() { + // get number of instances of s with <s p o> + String query = String.format( + "SELECT (COUNT(DISTINCT ?s) AS ?all) WHERE {?s <%s> ?o.}", + propertyToDescribe.getName()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; int all = 1; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); all = qs.getLiteral("all").getInt(); } - //get number of instances of s with <s p o> <s p o1> where o != o1 + // 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 = executeSelectQuery(query); int notFunctional = 1; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); notFunctional = qs.getLiteral("notfunctional").getInt(); } - if(all > 0){ - currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalDatatypePropertyAxiom(propertyToDescribe), - computeScore(all, all - notFunctional), declaredAsFunctional)); + if (all > 0) { + currentlyBestAxioms.add(new EvaluatedAxiom( + new FunctionalDatatypePropertyAxiom(propertyToDescribe), + computeScore(all, all - notFunctional), + declaredAsFunctional)); } - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } } 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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -35,6 +35,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="functional objectproperty axiom learner", shortName="oplfunc", version=0.1) @@ -44,6 +46,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; + + private boolean declaredAsFunctional; public FunctionalObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -66,40 +70,94 @@ //check if property is already declared as symmetric in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); - boolean declaredAsFunctional = executeAskQuery(query); + declaredAsFunctional = executeAskQuery(query); if(declaredAsFunctional) { existingAxioms.add(new FunctionalObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as functional in knowledge base."); } - //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()); + 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() { + Model model = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // 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 = executeSelectQuery(query, model); + QuerySolution qs; + int all = 1; + while (rs.hasNext()) { + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + } + // get number of instances of s with <s p o> <s p o1> where o != o1 + query = "SELECT (COUNT(DISTINCT ?s) AS ?notfunctional) WHERE {?s <%s> ?o. ?s <%s> ?o1. FILTER(?o != ?o1) }"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query, model); + int notFunctional = 1; + while (rs.hasNext()) { + qs = rs.next(); + notFunctional = qs.getLiteral("notfunctional").getInt(); + } + if (all > 0) { + currentlyBestAxioms.clear(); + currentlyBestAxioms.add(new EvaluatedAxiom( + new FunctionalObjectPropertyAxiom(propertyToDescribe), + computeScore(all, all - notFunctional), + declaredAsFunctional)); + } + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } + } + + private void runSPARQL1_1_Mode() { + // get number of instances of s with <s p o> + String query = String.format( + "SELECT (COUNT(DISTINCT ?s) AS ?all) WHERE {?s <%s> ?o.}", + propertyToDescribe.getName()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; int all = 1; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); all = qs.getLiteral("all").getInt(); } - //get number of instances of s with <s p o> <s p o1> where o != o1 + // 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 = executeSelectQuery(query); int notFunctional = 1; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); notFunctional = qs.getLiteral("notfunctional").getInt(); } - if(all > 0){ - currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalObjectPropertyAxiom(propertyToDescribe), - computeScore(all, all - notFunctional), declaredAsFunctional)); + if (all > 0) { + currentlyBestAxioms.add(new EvaluatedAxiom( + new FunctionalObjectPropertyAxiom(propertyToDescribe), + computeScore(all, all - notFunctional), + declaredAsFunctional)); } - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } public static void main(String[] args) throws Exception{ - FunctionalObjectPropertyAxiomLearner l = new FunctionalObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); + FunctionalObjectPropertyAxiomLearner l = new FunctionalObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/league")); l.setMaxExecutionTimeInSeconds(10); l.init(); 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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -35,6 +35,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="inversefunctional objectproperty axiom learner", shortName="oplinvfunc", version=0.1) @@ -44,6 +46,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; + + private boolean declaredAsInverseFunctional; public InverseFunctionalObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -66,36 +70,99 @@ //check if property is already declared as symmetric in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.InverseFunctionalProperty.getURI()); - boolean declaredAsInverseFunctional = executeAskQuery(query); + declaredAsInverseFunctional = executeAskQuery(query); if(declaredAsInverseFunctional) { existingAxioms.add(new InverseFunctionalObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as functional in knowledge base."); } - //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()); + 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() { + Model model = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // 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 = executeSelectQuery(query); + QuerySolution qs; + int all = 1; + while (rs.hasNext()) { + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + } + // get number of instances of s with <s p o> <s p o1> where o != o1 + query = "SELECT (COUNT(DISTINCT ?s1) AS ?noninversefunctional) WHERE {?s1 <%s> ?o. ?s2 <%s> ?o. FILTER(?s1 != ?s2) }"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query); + int notInverseFunctional = 1; + while (rs.hasNext()) { + qs = rs.next(); + notInverseFunctional = qs.getLiteral("noninversefunctional") + .getInt(); + } + if (all > 0) { + currentlyBestAxioms.clear(); + currentlyBestAxioms + .add(new EvaluatedAxiom( + new InverseFunctionalObjectPropertyAxiom( + propertyToDescribe), computeScore(all, all + - notInverseFunctional), + declaredAsInverseFunctional)); + } + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } + } + + private void runSPARQL1_1_Mode() { + // get number of instances of s with <s p o> + String query = String.format( + "SELECT (COUNT(DISTINCT ?o) AS ?all) WHERE {?s <%s> ?o.}", + propertyToDescribe.getName()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; int all = 1; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); all = qs.getLiteral("all").getInt(); } - //get number of instances of s with <s p o> <s p o1> where o != o1 + // get number of instances of s with <s p o> <s p o1> where o != o1 query = "SELECT (COUNT(DISTINCT ?s1) AS ?noninversefunctional) WHERE {?s1 <%s> ?o. ?s2 <%s> ?o. FILTER(?s1 != ?s2) }"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int notInverseFunctional = 1; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); - notInverseFunctional = qs.getLiteral("noninversefunctional").getInt(); + notInverseFunctional = qs.getLiteral("noninversefunctional") + .getInt(); } - if(all > 0){ - currentlyBestAxioms.add(new EvaluatedAxiom(new InverseFunctionalObjectPropertyAxiom(propertyToDescribe), - computeScore(all, all - notInverseFunctional), declaredAsInverseFunctional)); + if (all > 0) { + currentlyBestAxioms + .add(new EvaluatedAxiom( + new InverseFunctionalObjectPropertyAxiom( + propertyToDescribe), computeScore(all, all + - notInverseFunctional), + declaredAsInverseFunctional)); } - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } public static void main(String[] args) throws Exception{ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java 2011-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -21,22 +21,15 @@ import java.net.URL; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; import java.util.SortedSet; -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.ObjectPropertyEditor; -import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.InverseObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.reasoning.SPARQLReasoner; @@ -45,6 +38,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; @ComponentAnn(name="inverse objectproperty domain axiom learner", shortName="oplinv", version=0.1) public class InverseObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -91,35 +86,36 @@ } private void runSPARQL1_0_Mode(){ - Map<ObjectProperty, Integer> prop2CountMap = new HashMap<ObjectProperty, Integer>(); - boolean repeat = true; + Model model = ModelFactory.createDefaultModel(); int limit = 1000; - int total = 0; - while(!terminationCriteriaSatisfied() && repeat){ - String query = String.format("SELECT ?s ?p WHERE {?s <%s> ?o. OPTIONAL{?o ?p ?s.}} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, fetchedRows); + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // get number of instances of s with <s p o> + query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; - ObjectProperty p; - int cnt = 0; + int total = 0; while(rs.hasNext()){ qs = rs.next(); - if(qs.getResource("p") != null){ - p = new ObjectProperty(qs.getResource("p").getURI()); - Integer oldCnt = prop2CountMap.get(p); - if(oldCnt == null){ - oldCnt = Integer.valueOf(0); - } - prop2CountMap.put(p, Integer.valueOf(oldCnt + 1)); - } - cnt++; + total = qs.getLiteral("total").getInt(); } - total += cnt; - for(Entry<ObjectProperty, Integer> entry : prop2CountMap.entrySet()){ - currentlyBestAxioms = Collections.singletonList(new EvaluatedAxiom(new InverseObjectPropertyAxiom(entry.getKey(), propertyToDescribe), - computeScore(total, entry.getValue()))); + + query = String.format("SELECT ?p (COUNT(?s) AS ?cnt) WHERE {?s <%s> ?o. ?o ?p ?s.} GROUP BY ?p", propertyToDescribe.getName()); + rs = executeSelectQuery(query); + while(rs.hasNext()){ + qs = rs.next(); + currentlyBestAxioms.add(new EvaluatedAxiom( + new InverseObjectPropertyAxiom(new ObjectProperty(qs.getResource("p").getURI()), propertyToDescribe), + computeScore(total, qs.getLiteral("cnt").getInt()))); } - fetchedRows += limit; - repeat = (cnt == limit); + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } } 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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -19,7 +19,6 @@ package org.dllearner.algorithms.properties; -import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -37,6 +36,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.OWL2; @ComponentAnn(name="irreflexive objectproperty axiom learner", shortName="oplirrefl", version=0.1) @@ -46,6 +47,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; + + private boolean declaredAsIrreflexive; public IrreflexiveObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -68,39 +71,97 @@ //check if property is already declared as irreflexive in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.IrreflexiveProperty.getURI()); - boolean declaredAsIrreflexive = executeAskQuery(query); + declaredAsIrreflexive = executeAskQuery(query); if(declaredAsIrreflexive) { existingAxioms.add(new IrreflexiveObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as irreflexive in knowledge base."); } + + if(ks.supportsSPARQL_1_1()){ + runSPARQL1_1_Mode(); + } else { + runSPARQL1_0_Mode(); + } - //get all instance s with <s p o> - query = String.format("SELECT (COUNT(DISTINCT ?s) AS ?all) WHERE {?s <%s> ?o.}", propertyToDescribe); + + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + private void runSPARQL1_0_Mode() { + Model model = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // get all instance s with <s p o> + query = String.format( + "SELECT (COUNT(DISTINCT ?s) AS ?all) WHERE {?s <%s> ?o.}", + propertyToDescribe); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + int all = 0; + while (rs.hasNext()) { + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + + } + + // get number of instances s where not exists <s p s> + query = "SELECT (COUNT(DISTINCT ?s) AS ?irreflexive) WHERE {?s <%s> ?o. FILTER(?s != ?o)}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query); + int irreflexive = 0; + while (rs.hasNext()) { + qs = rs.next(); + irreflexive = qs.getLiteral("irreflexive").getInt(); + } + + if (all > 0) { + currentlyBestAxioms.clear(); + currentlyBestAxioms.add(new EvaluatedAxiom( + new IrreflexiveObjectPropertyAxiom(propertyToDescribe), + computeScore(all, irreflexive), declaredAsIrreflexive)); + } + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } + } + + private void runSPARQL1_1_Mode() { + // get all instance s with <s p o> + String query = String.format( + "SELECT (COUNT(DISTINCT ?s) AS ?all) WHERE {?s <%s> ?o.}", + propertyToDescribe); ResultSet rs = executeSelectQuery(query); QuerySolution qs; int all = 0; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); all = qs.getLiteral("all").getInt(); - + } - - //get number of instances s where not exists <s p s> + + // get number of instances s where not exists <s p s> query = "SELECT (COUNT(DISTINCT ?s) AS ?irreflexive) WHERE {?s <%s> ?o. FILTER(?s != ?o)}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int irreflexive = 0; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); irreflexive = qs.getLiteral("irreflexive").getInt(); } - - if(all > 0){ - currentlyBestAxioms.add(new EvaluatedAxiom(new IrreflexiveObjectPropertyAxiom(propertyToDescribe), + + if (all > 0) { + currentlyBestAxioms.add(new EvaluatedAxiom( + new IrreflexiveObjectPropertyAxiom(propertyToDescribe), computeScore(all, irreflexive), declaredAsIrreflexive)); } - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } public static void main(String[] args) throws Exception { 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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -35,6 +35,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.OWL2; @ComponentAnn(name="reflexive objectproperty axiom learner", shortName="oplrefl", version=0.1) @@ -44,6 +46,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; + + private boolean declaredAsReflexive; public ReflexiveObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -66,19 +70,72 @@ //check if property is already declared as reflexive in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.ReflexiveProperty.getURI()); - boolean declaredAsReflexive = executeAskQuery(query); + declaredAsReflexive = executeAskQuery(query); if(declaredAsReflexive) { existingAxioms.add(new ReflexiveObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as reflexive in knowledge base."); } - //get fraction of instances s with <s p s> - 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() { + Model model = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // get fraction of instances s with <s p s> + query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + int total = 0; + while (rs.hasNext()) { + qs = rs.next(); + total = qs.getLiteral("total").getInt(); + } + query = "SELECT (COUNT(?s) AS ?reflexive) WHERE {?s <%s> ?s.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query); + int reflexive = 0; + while (rs.hasNext()) { + qs = rs.next(); + reflexive = qs.getLiteral("reflexive").getInt(); + + } + if (total > 0) { + currentlyBestAxioms.clear(); + currentlyBestAxioms.add(new EvaluatedAxiom( + new ReflexiveObjectPropertyAxiom(propertyToDescribe), + computeScore(total, reflexive), declaredAsReflexive)); + } + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } + } + + private void runSPARQL1_1_Mode() { + // get fraction of instances s with <s p s> + String query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; int total = 0; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); total = qs.getLiteral("total").getInt(); } @@ -86,17 +143,16 @@ query = query.replace("%s", propertyToDescribe.getURI().toString()); rs = executeSelectQuery(query); int reflexive = 0; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); reflexive = qs.getLiteral("reflexive").getInt(); - + } - if(total > 0){ - currentlyBestAxioms.add(new EvaluatedAxiom(new ReflexiveObjectPropertyAxiom(propertyToDescribe), + if (total > 0) { + currentlyBestAxioms.add(new EvaluatedAxiom( + new ReflexiveObjectPropertyAxiom(propertyToDescribe), computeScore(total, reflexive), declaredAsReflexive)); } - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } public static void main(String[] args) throws Exception{ 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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -21,15 +21,12 @@ import java.net.URL; import java.util.ArrayList; -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.ObjectPropertyEditor; -import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -39,6 +36,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.OWL2; @ComponentAnn(name="symmetric objectproperty axiom learner", shortName="oplsymm", version=0.1) @@ -48,6 +47,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; + + private boolean declaredAsSymmetric; public SymmetricObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -70,7 +71,7 @@ //check if property is already declared as symmetric in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.SymmetricProperty.getURI()); - boolean declaredAsSymmetric = executeAskQuery(query); + declaredAsSymmetric = executeAskQuery(query); if(declaredAsSymmetric) { existingAxioms.add(new SymmetricObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as symmetric in knowledge base."); @@ -86,36 +87,42 @@ } private void runSPARQL1_0_Mode(){ - BiHashMultimap<Individual, Individual> individualsMap = new BiHashMultimap<Individual, Individual>(); - boolean repeat = true; + Model model = ModelFactory.createDefaultModel(); 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); + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // get number of instances of s with <s p o> + query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; - Individual s; - Individual o; - int cnt = 0; + int total = 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++; + total = qs.getLiteral("total").getInt(); } - int total = individualsMap.size(); + query = "SELECT (COUNT(?s) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query); int symmetric = 0; + while(rs.hasNext()){ + qs = rs.next(); + symmetric = qs.getLiteral("symmetric").getInt(); + } - for(java.util.Map.Entry<Individual, Individual> e : individualsMap.entries()){ - if(individualsMap.getInverse().containsEntry(e.getKey(), e.getValue())){ - symmetric++; - } + + if(total > 0){ + currentlyBestAxioms.clear(); + currentlyBestAxioms.add(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), + computeScore(total, symmetric), declaredAsSymmetric)); } - - currentlyBestAxioms = Collections.singletonList(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), - computeScore(total, symmetric))); - fetchedRows += limit; - repeat = (cnt == limit); + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } } @@ -141,7 +148,7 @@ if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), - computeScore(total, symmetric))); + computeScore(total, symmetric), declaredAsSymmetric)); } } 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-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -20,7 +20,6 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Collections; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; @@ -36,6 +35,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="transitive objectproperty axiom learner", shortName="opltrans", version=0.1) @@ -45,6 +46,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; + + private boolean declaredAsTransitive; public TransitiveObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; @@ -67,13 +70,12 @@ //check if property is already declared as transitive in knowledge base String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.TransitiveProperty.getURI()); - boolean declaredAsTransitive = executeAskQuery(query); + declaredAsTransitive = executeAskQuery(query); if(declaredAsTransitive) { existingAxioms.add(new TransitiveObjectPropertyAxiom(propertyToDescribe)); logger.info("Property is already declared as transitive in knowledge base."); } - if(ks.supportsSPARQL_1_1()){ runSPARQL1_1_Mode(); } else { @@ -85,7 +87,42 @@ private void runSPARQL1_0_Mode(){ - currentlyBestAxioms = Collections.emptyList(); + Model model = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + // get number of instances of s with <s p o> + query = "SELECT (COUNT(?o) AS ?total) WHERE {?s <%s> ?o. ?o <%s> ?o1.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + int total = 0; + while(rs.hasNext()){ + qs = rs.next(); + total = qs.getLiteral("total").getInt(); + } + query = "SELECT (COUNT(?o) AS ?transitive) WHERE {?s <%s> ?o. ?o <%s> ?o1. ?s <%s> ?o1.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query); + int transitive = 0; + while(rs.hasNext()){ + qs = rs.next(); + transitive = qs.getLiteral("transitive").getInt(); + } + + if(total > 0){ + currentlyBestAxioms.clear(); + currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescribe), + computeScore(total, transitive), declaredAsTransitive)); + } + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } } private void runSPARQL1_1_Mode(){ @@ -109,7 +146,7 @@ if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescribe), - computeScore(total, transitive))); + computeScore(total, transitive), declaredAsTransitive)); } } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-11 11:37:29 UTC (rev 3497) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-12 14:36:59 UTC (rev 3498) @@ -28,7 +28,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.aksw.commons.jena.CollectionResultSet; import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; @@ -45,8 +44,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; /** @@ -183,6 +184,17 @@ return returnList; } + protected Model executeConstructQuery(String query) { + logger.info("Sending query\n{} ...", query); + queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), + query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + queryExecution.setDefaultGraphURIs(ks.getEndpoint().getDefaultGraphURIs()); + queryExecution.setNamedGraphURIs(ks.getEndpoint().getNamedGraphURIs()); + System.out.println(query); + return queryExecution.execConstruct(); + } + protected ResultSet executeSelectQuery(String query) { logger.info("Sending query\n{} ...", query); queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), @@ -203,6 +215,15 @@ return resultSet; } + protected ResultSet executeSelectQuery(String query, Model model) { + logger.info("Sending query\n{} ...", query); + QueryExecution qexec = QueryExecutionFactory.create(query, model); + ResultSet rs = qexec.execSelect();; + + + return rs; + } + protected v... [truncated message content] |
From: <lor...@us...> - 2011-12-13 11:57:39
|
Revision: 3501 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3501&view=rev Author: lorenz_b Date: 2011-12-13 11:57:29 +0000 (Tue, 13 Dec 2011) Log Message: ----------- Updated chunk of algorithms to work with SPARQL endpoints, which not support COUNT queries. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.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/SubDataPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.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-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -350,7 +350,7 @@ SortedSet<Description> mostGeneralClasses = reasoner.getClassHierarchy().getMostGeneralClasses(); } for(NamedClass cls : completeDisjointclasses){ - if(useClassPopularity){ + if(useClassPopularity && ks.supportsSPARQL_1_1()){ int popularity = reasoner.getIndividualsCount(cls); //we skip classes with no instances if(popularity == 0) continue; 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-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -42,6 +42,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; @ComponentAnn(name="disjoint dataproperty axiom learner", shortName="dpldisjoint", version=0.1) public class DisjointDataPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -51,6 +53,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; + private Set<DatatypeProperty> allDataProperties; + public DisjointDataPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -73,45 +77,94 @@ //TODO //at first get all existing dataproperties in knowledgebase - Set<DatatypeProperty> dataProperties = new SPARQLTasks(ks.getEndpoint()).getAllDataProperties(); + allDataProperties = new SPARQLTasks(ks.getEndpoint()).getAllDataProperties(); + allDataProperties.remove(propertyToDescribe); + 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() { + Model model = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); + while(!terminationCriteriaSatisfied() && newModel.size() != 0){ + model.add(newModel); + query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; + + DatatypeProperty prop; + Integer oldCnt; + ResultSet rs = executeSelectQuery(query, model); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + prop = new DatatypeProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result, allDataProperties); + } + + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } + + } + + private void runSPARQL1_1_Mode() { //get properties and how often they occur - int limit = 1000; - int offset = 0; - String queryTemplate = "SELECT ?p (COUNT(?s) as ?count) WHERE {?s ?p ?o." + - "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + - "}"; - String query; - Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); - DatatypeProperty prop; - Integer oldCnt; - boolean repeat = true; - - ResultSet rs = null; - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, propertyToDescribe, limit, offset); - rs = executeSelectQuery(query); - QuerySolution qs; - repeat = false; - while(rs.hasNext()){ - qs = rs.next(); - prop = new DatatypeProperty(qs.getResource("p").getURI()); - int newCnt = qs.getLiteral("count").getInt(); - oldCnt = result.get(prop); - if(oldCnt == null){ - oldCnt = Integer.valueOf(newCnt); - } - result.put(prop, oldCnt); - qs.getLiteral("count").getInt(); - repeat = true; - } - if(!result.isEmpty()){ - currentlyBestAxioms = buildAxioms(result, dataProperties); - offset += 1000; - } + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p (COUNT(?s) as ?count) WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); + DatatypeProperty prop; + Integer oldCnt; + boolean repeat = true; + + ResultSet rs = null; + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + rs = executeSelectQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new DatatypeProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result, allDataProperties); + offset += 1000; + } + } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override 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-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -36,6 +36,7 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.owl.DisjointObjectPropertyAxiom; +import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; @@ -47,6 +48,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; @ComponentAnn(name="disjoint objectproperty axiom learner", shortName="opldisjoint", version=0.1) public class DisjointObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -56,6 +59,8 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; + private Set<ObjectProperty> allObjectProperties; + private boolean usePropertyPopularity = true; public DisjointObjectPropertyAxiomLearner(SparqlEndpointKS ks){ @@ -77,48 +82,96 @@ fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - //TODO + //TODO detect existing axioms //at first get all existing objectproperties in knowledgebase - Set<ObjectProperty> objectProperties = new SPARQLTasks(ks.getEndpoint()).getAllObjectProperties(); - objectProperties.remove(propertyToDescribe); + allObjectProperties = new SPARQLTasks(ks.getEndpoint()).getAllObjectProperties(); + allObjectProperties.remove(propertyToDescribe); + 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() { + Model model = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); + while(!terminationCriteriaSatisfied() && newModel.size() != 0){ + model.add(newModel); + query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; + + ObjectProperty prop; + Integer oldCnt; + ResultSet rs = executeSelectQuery(query, model); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + prop = new ObjectProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result, allObjectProperties); + } + + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } + + } + + private void runSPARQL1_1_Mode() { //get properties and how often they occur - int limit = 1000; - int offset = 0; - String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + - "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + - "}"; - String query; - Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); - ObjectProperty prop; - Integer oldCnt; - boolean repeat = true; - - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeSelectQuery(query); - QuerySolution qs; - repeat = false; - while(rs.hasNext()){ - qs = rs.next(); - prop = new ObjectProperty(qs.getResource("p").getURI()); - int newCnt = qs.getLiteral("count").getInt(); - oldCnt = result.get(prop); - if(oldCnt == null){ - oldCnt = Integer.valueOf(newCnt); - } - result.put(prop, oldCnt); - qs.getLiteral("count").getInt(); - repeat = true; - } - if(!result.isEmpty()){ - currentlyBestAxioms = buildAxioms(result, objectProperties); - offset += 1000; - } + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); + ObjectProperty prop; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new ObjectProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result, allObjectProperties); + offset += 1000; + } + } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count, Set<ObjectProperty> allProperties){ 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-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -41,6 +41,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; @ComponentAnn(name="equivalent dataproperty axiom learner", shortName="dplequiv", version=0.1) public class EquivalentDataPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -72,43 +74,91 @@ SortedSet<DatatypeProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); logger.debug("Existing super properties: " + existingSuperProperties); - //get subjects with types + 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() { + Model model = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + - "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + - "}"; + String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); + while(!terminationCriteriaSatisfied() && newModel.size() != 0){ + model.add(newModel); + query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; + + DatatypeProperty prop; + Integer oldCnt; + ResultSet rs = executeSelectQuery(query, model); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + prop = new DatatypeProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result); + } + + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + } + + } + + private void runSPARQL1_1_Mode() { + // get subjects with types + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + "}"; String query; Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); DatatypeProperty prop; Integer oldCnt; boolean repeat = true; - - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, propertyToDescribe, limit, offset); + + while (!terminationCriteriaSatisfied() && repeat) { + query = String.format(queryTemplate, propertyToDescribe, limit, + offset); ResultSet rs = executeSelectQuery(query); QuerySolution qs; repeat = false; - while(rs.hasNext()){ + while (rs.hasNext()) { qs = rs.next(); prop = new DatatypeProperty(qs.getResource("p").getURI()); int newCnt = qs.getLiteral("count").getInt(); oldCnt = result.get(prop); - if(oldCnt == null){ + if (oldCnt == null) { oldCnt = Integer.valueOf(newCnt); } result.put(prop, oldCnt); qs.getLiteral("count").getInt(); repeat = true; } - if(!result.isEmpty()){ + if (!result.isEmpty()) { currentlyBestAxioms = buildAxioms(result); offset += 1000; } - + } - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } 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-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -40,12 +40,13 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.learningproblems.AxiomScore; 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.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; @ComponentAnn(name="equivalent objectproperty axiom learner", shortName="oplequiv", version=0.1) public class EquivalentObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -77,23 +78,31 @@ SortedSet<ObjectProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); logger.debug("Existing super properties: " + existingSuperProperties); - //get subjects with types + 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() { + Model model = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + - "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + - "}"; - String query; + String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); - ObjectProperty prop; - Integer oldCnt; - boolean repeat = true; - - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeSelectQuery(query); + while(!terminationCriteriaSatisfied() && newModel.size() != 0){ + model.add(newModel); + query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; + + ObjectProperty prop; + Integer oldCnt; + ResultSet rs = executeSelectQuery(query, model); QuerySolution qs; - repeat = false; while(rs.hasNext()){ qs = rs.next(); prop = new ObjectProperty(qs.getResource("p").getURI()); @@ -104,18 +113,58 @@ } result.put(prop, oldCnt); qs.getLiteral("count").getInt(); - repeat = true; } if(!result.isEmpty()){ currentlyBestAxioms = buildAxioms(result); - offset += 1000; } + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + private void runSPARQL1_1_Mode() { + //get subjects with types + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); + ObjectProperty prop; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new ObjectProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result); + offset += 1000; + } + + } + + } + private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Integer all = property2Count.get(propertyToDescribe); @@ -129,7 +178,7 @@ properties.add(entry.getKey()); int popularity = reasoner.getPropertyCount(entry.getKey()); int total = popularity;//Math.max(popularity, all); - int success = entry.getValue();System.out.println(entry.getKey());System.out.println(total);System.out.println(success); + int success = entry.getValue();//System.out.println(entry.getKey());System.out.println(total);System.out.println(success); Score score = computeScore(total, success); evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(properties),score); axioms.add(evalAxiom); 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-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -40,6 +40,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; @ComponentAnn(name="data subPropertyOf axiom learner", shortName="dplsubprop", version=0.1) public class SubDataPropertyOfAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -71,23 +73,31 @@ SortedSet<DatatypeProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); logger.debug("Existing super properties: " + existingSuperProperties); - //get properties and how often they occur + 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() { + Model model = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?p a <http://www.w3.org/2002/07/owl#DatatypeProperty>. ?s ?p ?o. " + - "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + - "}"; - String query; + String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); - DatatypeProperty prop; - Integer oldCnt; - boolean repeat = true; - - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeSelectQuery(query); + while(!terminationCriteriaSatisfied() && newModel.size() != 0){ + model.add(newModel); + query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; + + DatatypeProperty prop; + Integer oldCnt; + ResultSet rs = executeSelectQuery(query, model); QuerySolution qs; - repeat = false; while(rs.hasNext()){ qs = rs.next(); prop = new DatatypeProperty(qs.getResource("p").getURI()); @@ -98,18 +108,58 @@ } result.put(prop, oldCnt); qs.getLiteral("count").getInt(); - repeat = true; } - if(!result.isEmpty()){ currentlyBestAxioms = buildAxioms(result); - offset += 1000; } + + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + private void runSPARQL1_1_Mode() { + //get subjects with types + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); + DatatypeProperty prop; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new DatatypeProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result); + offset += 1000; + } + + } + + } + private List<EvaluatedAxiom> buildAxioms(Map<DatatypeProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Integer total = property2Count.get(propertyToDescribe); 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-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -40,6 +40,8 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; @ComponentAnn(name="object subPropertyOf axiom learner", shortName="oplsubprop", version=0.1) public class SubObjectPropertyOfAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -71,23 +73,31 @@ SortedSet<ObjectProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); logger.debug("Existing super properties: " + existingSuperProperties); - //get subjects with types + 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() { + Model model = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + - "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + - "}"; - String query; + String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); - ObjectProperty prop; - Integer oldCnt; - boolean repeat = true; - - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeSelectQuery(query); + while(!terminationCriteriaSatisfied() && newModel.size() != 0){ + model.add(newModel); + query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; + + ObjectProperty prop; + Integer oldCnt; + ResultSet rs = executeSelectQuery(query, model); QuerySolution qs; - repeat = false; while(rs.hasNext()){ qs = rs.next(); prop = new ObjectProperty(qs.getResource("p").getURI()); @@ -98,17 +108,58 @@ } result.put(prop, oldCnt); qs.getLiteral("count").getInt(); - repeat = true; } if(!result.isEmpty()){ currentlyBestAxioms = buildAxioms(result); - offset += 1000; } + + + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + private void runSPARQL1_1_Mode() { + //get subjects with types + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); + ObjectProperty prop; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new ObjectProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result); + offset += 1000; + } + + } + + } + private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Integer total = property2Count.get(propertyToDescribe); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -191,7 +191,7 @@ queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); queryExecution.setDefaultGraphURIs(ks.getEndpoint().getDefaultGraphURIs()); queryExecution.setNamedGraphURIs(ks.getEndpoint().getNamedGraphURIs()); - System.out.println(query); + return queryExecution.execConstruct(); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-12-12 15:40:07 UTC (rev 3500) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-12-13 11:57:29 UTC (rev 3501) @@ -595,7 +595,7 @@ public SortedSet<ObjectProperty> getInverseObjectProperties(ObjectProperty property){ SortedSet<ObjectProperty> inverseObjectProperties = new TreeSet<ObjectProperty>(); String query = "SELECT ?p WHERE {" + - "{<%p> <%ax> ?p.} UNION {?p <%ax> <%p>}}".replace("%p", property.getName()).replace("%ax", OWL.inverseOf.getURI()); + "{<%p> <%ax> ?p.} UNION {?p <%ax> <%p>}}".replace("%p", property.getName()).replace("%ax", OWL.inverseOf.getURI());System.out.println(query); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-19 11:22:49
|
Revision: 3506 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3506&view=rev Author: lorenz_b Date: 2011-12-19 11:22:43 +0000 (Mon, 19 Dec 2011) Log Message: ----------- Prepared all to work on local models. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.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-12-18 18:47:08 UTC (rev 3505) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-19 11:22:43 UTC (rev 3506) @@ -43,6 +43,8 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; +import org.dllearner.kb.OWLFile; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; @@ -117,7 +119,7 @@ //TODO //at first get all existing classes in knowledgebase - allClasses = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); + allClasses = getAllClasses(); allClasses.remove(classToDescribe); //get the subclasses @@ -128,9 +130,9 @@ } if(ks.supportsSPARQL_1_1()){ + runSPARQL1_0_Mode(); + } else { runSPARQL1_1_Mode(); - } else { - runSPARQL1_0_Mode(); } //get classes and how often they occur @@ -184,9 +186,9 @@ private void runSPARQL1_1_Mode(){ int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?type COUNT(?s) AS ?count WHERE {?s a ?type." + - "{SELECT ?s WHERE {?s a <%s>.} LIMIT %d OFFSET %d}" + - "}"; + String queryTemplate = "SELECT ?type (COUNT(?s) AS ?count) WHERE {?s a ?type." + + "{SELECT ?s WHERE {?s a <%s>.} LIMIT %d OFFSET %d} " + + "} GROUP BY ?type"; String query; Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); NamedClass cls; @@ -200,17 +202,20 @@ repeat = false; while(rs.hasNext()){ qs = rs.next(); - cls = new NamedClass(qs.getResource("type").getURI()); - int newCnt = qs.getLiteral("count").getInt(); - oldCnt = result.get(cls); - if(oldCnt == null){ - oldCnt = Integer.valueOf(newCnt); - } else { - oldCnt += newCnt; + if(qs.getResource("type") != null){ + cls = new NamedClass(qs.getResource("type").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(cls); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } else { + oldCnt += newCnt; + } + + result.put(cls, oldCnt); + repeat = true; } - result.put(cls, oldCnt); - repeat = true; } if(!result.isEmpty()){ currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, allClasses); @@ -350,7 +355,8 @@ SortedSet<Description> mostGeneralClasses = reasoner.getClassHierarchy().getMostGeneralClasses(); } for(NamedClass cls : completeDisjointclasses){ - if(useClassPopularity && ks.supportsSPARQL_1_1()){ + if(useClassPopularity && ( + (ks instanceof SparqlEndpointKS && ((SparqlEndpointKS) ks).supportsSPARQL_1_1()) || !(ks instanceof SparqlEndpointKS))){ int popularity = reasoner.getIndividualsCount(cls); //we skip classes with no instances if(popularity == 0) continue; @@ -387,9 +393,11 @@ } public static void main(String[] args) throws Exception{ + LocalModelBasedSparqlEndpointKS ks = new LocalModelBasedSparqlEndpointKS(new URL("http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/examples/swore/swore.rdf?revision=2217")); DisjointClassesLearner l = new DisjointClassesLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()))); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Band")); + l = new DisjointClassesLearner(ks); + l.setClassToDescribe(new NamedClass("http://ns.softwiki.de/req/CustomerRequirement")); l.init(); l.getReasoner().prepareSubsumptionHierarchy(); // System.out.println(l.getReasoner().getClassHierarchy().getSubClasses(new NamedClass("http://dbpedia.org/ontology/Athlete"), false));System.exit(0); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-18 18:47:08 UTC (rev 3505) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-19 11:22:43 UTC (rev 3506) @@ -25,6 +25,7 @@ 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; @@ -34,8 +35,12 @@ import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; 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.learningproblems.Heuristics; import org.dllearner.reasoning.SPARQLReasoner; @@ -44,6 +49,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.ResultSet; @@ -90,8 +96,6 @@ this.learningProblem = learningProblem; } - ExtendedQueryEngineHTTP queryExecution; - public int getMaxExecutionTimeInSeconds() { return maxExecutionTimeInSeconds; } @@ -132,7 +136,7 @@ public void init() throws ComponentInitException { ks.init(); if(reasoner == null){ - reasoner = new SPARQLReasoner(ks); + reasoner = new SPARQLReasoner((SparqlEndpointKS) ks); } } @@ -184,68 +188,72 @@ return returnList; } + protected Set<NamedClass> getAllClasses() { + if(ks.isRemote()){ + return new SPARQLTasks(((SparqlEndpointKS) ks).getEndpoint()).getAllClasses(); + } else { + Set<NamedClass> classes = new TreeSet<NamedClass>(); + for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().toList()){ + if(!cls.isAnon()){ + classes.add(new NamedClass(cls.getURI())); + } + } + return classes; + } + + } + protected Model executeConstructQuery(String query) { logger.info("Sending query\n{} ...", query); - queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), - query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - queryExecution.setDefaultGraphURIs(ks.getEndpoint().getDefaultGraphURIs()); - queryExecution.setNamedGraphURIs(ks.getEndpoint().getNamedGraphURIs()); - - return queryExecution.execConstruct(); + if(ks.isRemote()){ + SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(endpoint.getURL().toString(), + query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + queryExecution.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); + queryExecution.setNamedGraphURIs(endpoint.getNamedGraphURIs()); + return queryExecution.execConstruct(); + } else { + QueryExecution qexec = QueryExecutionFactory.create(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); + return qexec.execConstruct(); + } } protected ResultSet executeSelectQuery(String query) { logger.info("Sending query\n{} ...", query); - queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), - query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - queryExecution.setDefaultGraphURIs(ks.getEndpoint().getDefaultGraphURIs()); - queryExecution.setNamedGraphURIs(ks.getEndpoint().getNamedGraphURIs()); - -// ResultSet resultSet = null; -// try { -// resultSet = queryExecution.execSelect(); -// } catch (Exception e) { -// logger.error("Got a timeout during query execution.", e); -// resultSet = new CollectionResultSet(Collections.<String>emptyList(), Collections.<QuerySolution>emptyList()); -// } - ResultSet resultSet = queryExecution.execSelect(); - - return resultSet; + if(ks.isRemote()){ + SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(endpoint.getURL().toString(), + query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + queryExecution.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); + queryExecution.setNamedGraphURIs(endpoint.getNamedGraphURIs()); + return queryExecution.execSelect(); + } else { + return executeSelectQuery(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); + } } protected ResultSet executeSelectQuery(String query, Model model) { logger.info("Sending query\n{} ...", query); QueryExecution qexec = QueryExecutionFactory.create(query, model); ResultSet rs = qexec.execSelect();; - return rs; } - protected void close() { - queryExecution.close(); - } - protected 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); + if(ks.isRemote()){ + SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); + QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); + queryExecution.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); + queryExecution.setNamedGraphURIs(endpoint.getNamedGraphURIs()); + return queryExecution.execAsk(); + } else { + QueryExecution queryExecution = QueryExecutionFactory.create(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); + return queryExecution.execAsk(); } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } -// ResultSet rs = queryExecution.execSelect(); -// boolean result = false; -// QuerySolution qs; -// if(rs.hasNext()){ -// qs = rs.next(); -// result = qs.get(qs.varNames().next()).asLiteral().getBoolean(); -// } - boolean result = queryExecution.execAsk(); - return result; } protected <K, V extends Comparable<V>> List<Entry<K, V>> sortByValues(Map<K, V> map){ @@ -269,6 +277,7 @@ protected List<Entry<Description, Integer>> sortByValues(Map<Description, Integer> map, final boolean useHierachy){ List<Entry<Description, Integer>> entries = new ArrayList<Entry<Description, Integer>>(map.entrySet()); final ClassHierarchy hierarchy = reasoner.getClassHierarchy(); + Collections.sort(entries, new Comparator<Entry<Description, Integer>>() { @Override Added: trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2011-12-19 11:22:43 UTC (rev 3506) @@ -0,0 +1,60 @@ +package org.dllearner.kb; + +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; + +import org.dllearner.core.ComponentInitException; + +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.ontology.OntModelSpec; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.util.FileManager; + +public class LocalModelBasedSparqlEndpointKS extends SparqlEndpointKS { + + private OntModel model; + + public LocalModelBasedSparqlEndpointKS(OntModel model) { + this.model = model; + } + + public LocalModelBasedSparqlEndpointKS(String ontologyURL) throws MalformedURLException { + this(new URL(ontologyURL)); + } + + public LocalModelBasedSparqlEndpointKS(URL ontologyURL) { + Model baseModel = ModelFactory.createDefaultModel(); + // use the FileManager to find the input file + InputStream in = FileManager.get().open(ontologyURL.toString()); + if (in == null) { + throw new IllegalArgumentException( + "File: " + ontologyURL + " not found"); + } + // read the RDF/XML file + baseModel.read(in, null); + + model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, baseModel); + } + + @Override + public void init() throws ComponentInitException { + + } + + public OntModel getModel() { + return model; + } + + @Override + public boolean isRemote() { + return false; + } + + @Override + public boolean supportsSPARQL_1_1() { + return true; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2011-12-18 18:47:08 UTC (rev 3505) +++ trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2011-12-19 11:22:43 UTC (rev 3506) @@ -45,6 +45,7 @@ private SparqlEndpoint endpoint; private boolean supportsSPARQL_1_1 = false; + private boolean isRemote = true; // TODO: turn those into config options @@ -84,6 +85,10 @@ public void setUrl(URL url) { this.url = url; } + + public boolean isRemote() { + return isRemote; + } public List<String> getDefaultGraphURIs() { return defaultGraphURIs; Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-12-18 18:47:08 UTC (rev 3505) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-12-19 11:22:43 UTC (rev 3506) @@ -53,6 +53,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.Thing; +import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SPARQLTasks; @@ -64,6 +65,9 @@ import org.slf4j.LoggerFactory; import com.clarkparsia.owlapiv3.XSD; +import com.hp.hpl.jena.ontology.OntClass; +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; @@ -87,6 +91,7 @@ private SparqlEndpointKS ks; private ClassHierarchy hierarchy; + private OntModel model; public SPARQLReasoner(SparqlEndpointKS ks) { @@ -97,6 +102,10 @@ } } + public SPARQLReasoner(OntModel model) { + this.model = model; + } + public final ClassHierarchy prepareSubsumptionHierarchy() { logger.info("Preparing subsumption hierarchy ..."); long startTime = System.currentTimeMillis(); @@ -117,7 +126,18 @@ subsumptionHierarchyDown.put(Nothing.instance, new TreeSet<Description>(conceptComparator)); // ... and named classes - Set<NamedClass> atomicConcepts = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); + Set<NamedClass> atomicConcepts; + if(ks.isRemote()){ + atomicConcepts = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); + } else { + atomicConcepts = new TreeSet<NamedClass>(); + for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().toList()){ + if(!cls.isAnon()){ + atomicConcepts.add(new NamedClass(cls.getURI())); + } + } + } + for (NamedClass atom : atomicConcepts) { tmp = getSubClasses(atom); // quality control: we explicitly check that no reasoner implementation returns null here @@ -571,7 +591,7 @@ } public int getIndividualsCount(NamedClass nc){ - String query = String.format("SELECT COUNT(?s) WHERE {" + + String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {" + "?s a <%s>." + "}", nc.getURI()); @@ -859,20 +879,26 @@ private ResultSet executeSelectQuery(String query){ logger.info("Sending query \n {}", query); - ResultSet resultset = null; - if(useCache){ - resultset = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(ks.getEndpoint(), query)); + ResultSet rs = null; + if(ks.isRemote()){ + if(useCache){ + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(ks.getEndpoint(), query)); + } else { + 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); + } + rs = queryExecution.execSelect(); + } } else { - 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); - } - resultset = queryExecution.execSelect(); + QueryExecution qExec = com.hp.hpl.jena.query.QueryExecutionFactory.create(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); + rs = qExec.execSelect(); + } - return resultset; + return rs; } /** @@ -888,30 +914,26 @@ } private boolean executeAskQuery(String query){ - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); + boolean ret; + if(ks.isRemote()){ + 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); + } + ret = queryExecution.execAsk(); + + } else { + QueryExecution qExec = com.hp.hpl.jena.query.QueryExecutionFactory.create(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); + ret = qExec.execAsk(); } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - boolean ret = queryExecution.execAsk(); + return ret; } - private Model executeConstructQuery(String 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); - } - Model ret = queryExecution.execConstruct(); - return ret; - } - public static void main(String[] args) throws Exception{ // QueryEngineHTTP e = new QueryEngineHTTP("http://bibleontology.com/sparql/index.jsp", // "SELECT DISTINCT ?type WHERE {?s a ?type) LIMIT 10"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-27 10:37:00
|
Revision: 3514 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3514&view=rev Author: lorenz_b Date: 2011-12-27 10:36:53 +0000 (Tue, 27 Dec 2011) Log Message: ----------- Continued to get working disjointness algorithm on local model. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.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-12-21 14:38:40 UTC (rev 3513) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-27 10:36:53 UTC (rev 3514) @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -44,17 +45,21 @@ import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; -import org.dllearner.kb.OWLFile; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.learningproblems.Heuristics; +import org.openrdf.model.vocabulary.OWL; +import org.openrdf.model.vocabulary.RDF; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.ontology.OntClass; +import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; /** * Learns disjoint classes using SPARQL queries. @@ -123,64 +128,85 @@ allClasses.remove(classToDescribe); //get the subclasses - if(reasoner.isPrepared()){ - subClasses = reasoner.getClassHierarchy().getSubClasses(classToDescribe, false); + if(ks.isRemote()){ + if(reasoner.isPrepared()){ + subClasses = reasoner.getClassHierarchy().getSubClasses(classToDescribe, false); + } else { + subClasses = reasoner.getSubClasses(classToDescribe, true); + } } else { - subClasses = reasoner.getSubClasses(classToDescribe, true); + subClasses = new TreeSet<Description>(); + OntModel ontModel = ((LocalModelBasedSparqlEndpointKS)ks).getModel(); + OntClass cls = ontModel.getOntClass(classToDescribe.getName()); + for(OntClass sub : cls.listSubClasses(false).toSet()){ + if(!sub.isAnon()){ + subClasses.add(new NamedClass(sub.getURI())); + } + } + for(OntClass sup : cls.listSuperClasses().toSet()){System.out.println(cls.listSuperClasses().toSet()); + if(!sup.isAnon()){ + subClasses.add(new NamedClass(sup.getURI())); + } + } } if(ks.supportsSPARQL_1_1()){ runSPARQL1_0_Mode(); } else { - runSPARQL1_1_Mode(); + runSPARQL1_0_Mode(); } - //get classes and how often they occur - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } private void runSPARQL1_0_Mode(){ + Model model = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?s ?type WHERE {?s a <%s>. ?s a ?type.} LIMIT %d OFFSET %d"; - String query; + String baseQuery = "CONSTRUCT {?s a <%s>. ?s a ?type.} WHERE {?s a <%s>. ?s a ?type.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, classToDescribe.getName(), classToDescribe.getName(), limit, offset);System.out.println(query); + Model newModel = executeConstructQuery(query); Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); NamedClass cls; Integer oldCnt; - boolean repeat = true; - - int total = 0; - - String resource = ""; - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, classToDescribe, limit, offset); - ResultSet rs = executeSelectQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + //get total number of distinct instances + query = "SELECT (COUNT(DISTINCT ?s) AS ?count) WHERE {?s a ?type.}"; + ResultSet rs = executeSelectQuery(query, model); + int total = rs.next().getLiteral("count").getInt(); + + // get number of instances of s with <s p o> + query = "SELECT ?type (COUNT(?s) AS ?count) WHERE {?s a ?type.}" + + " GROUP BY ?type"; + rs = executeSelectQuery(query, model); QuerySolution qs; - repeat = false; while(rs.hasNext()){ - qs = rs.next(); - String newResource = qs.getResource("?s").getURI(); - if(newResource != resource){ - total++; - resource = newResource; + qs = rs.next();System.out.println(qs); + if(qs.getResource("type") != null){ + cls = new NamedClass(qs.getResource("type").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(cls); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } else { + oldCnt += newCnt; + } + + result.put(cls, oldCnt); } - cls = new NamedClass(qs.getResource("type").getURI()); - oldCnt = result.get(cls); - if(oldCnt == null){ - oldCnt = Integer.valueOf(0); - } - int newCnt = oldCnt + 1; - result.put(cls, newCnt); - repeat = true; } + if(!result.isEmpty()){ - currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, total); - offset += 1000; + currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, allClasses, total); } + + offset += limit; + query = String.format(baseQuery, classToDescribe.getName(), classToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } + } private void runSPARQL1_1_Mode(){ @@ -201,7 +227,7 @@ QuerySolution qs; repeat = false; while(rs.hasNext()){ - qs = rs.next(); + qs = rs.next();System.out.println(qs); if(qs.getResource("type") != null){ cls = new NamedClass(qs.getResource("type").getURI()); int newCnt = qs.getLiteral("count").getInt(); @@ -218,7 +244,7 @@ } if(!result.isEmpty()){ - currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, allClasses); + currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, allClasses, result.get(classToDescribe)); offset += 1000; } } @@ -269,11 +295,11 @@ return axioms; } - private List<EvaluatedDescription> buildEvaluatedClassDescriptions(Map<NamedClass, Integer> class2Count, Set<NamedClass> allClasses){ + private List<EvaluatedDescription> buildEvaluatedClassDescriptions(Map<NamedClass, Integer> class2Count, Set<NamedClass> allClasses, int total){ List<EvaluatedDescription> evalDescs = new ArrayList<EvaluatedDescription>(); //Remove temporarily classToDescribe but keep track of their count - Integer all = class2Count.get(classToDescribe); +// Integer all = class2Count.get(classToDescribe); class2Count.remove(classToDescribe); //get complete disjoint classes @@ -299,7 +325,12 @@ } for(NamedClass cls : completeDisjointclasses){ if(useClassPopularity){ - int popularity = reasoner.getIndividualsCount(cls); + int popularity = 0; + if(ks.isRemote()){ + popularity = reasoner.getIndividualsCount(cls); + } else { + popularity = ((LocalModelBasedSparqlEndpointKS)ks).getModel().getOntClass(cls.getName()).listInstances(true).toSet().size(); + } //we skip classes with no instances if(popularity == 0) continue; double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(popularity, 0); @@ -314,66 +345,10 @@ //secondly, create disjoint classexpressions with score 1 - (#occurence/#all) for(Entry<NamedClass, Integer> entry : sortByValues(class2Count)){ + //drop classes from OWL and RDF namespace + if(entry.getKey().getName().startsWith(OWL.NAMESPACE) || entry.getKey().getName().startsWith(RDF.NAMESPACE))continue; // evalDesc = new EvaluatedDescription(entry.getKey(), // new AxiomScore(1 - (entry.getValue() / (double)all))); - double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(all, entry.getValue()); - double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; - evalDesc = new EvaluatedDescription(entry.getKey(), - new AxiomScore(1 - accuracy)); - evalDescs.add(evalDesc); - } - - class2Count.put(classToDescribe, all); - return evalDescs; - } - - private List<EvaluatedDescription> buildEvaluatedClassDescriptions(Map<NamedClass, Integer> class2Count, int total){ - List<EvaluatedDescription> evalDescs = new ArrayList<EvaluatedDescription>(); - - //Remove temporarily classToDescribe but keep track of their count - class2Count.remove(classToDescribe); - - //get complete disjoint classes - Set<NamedClass> completeDisjointclasses = new TreeSet<NamedClass>(allClasses); - completeDisjointclasses.removeAll(class2Count.keySet()); - - //drop all classes which have a super class in this set - if(suggestMostGeneralClasses && reasoner.isPrepared()){ - keepMostGeneralClasses(completeDisjointclasses); - } - - //we remove the asserted subclasses here - completeDisjointclasses.removeAll(subClasses); - for(Description subClass : subClasses){ - class2Count.remove(subClass); - } - - - EvaluatedDescription evalDesc; - //firstly, create disjoint classexpressions which not occur and give score of 1 - if(reasoner.isPrepared()){ - SortedSet<Description> mostGeneralClasses = reasoner.getClassHierarchy().getMostGeneralClasses(); - } - for(NamedClass cls : completeDisjointclasses){ - if(useClassPopularity && ( - (ks instanceof SparqlEndpointKS && ((SparqlEndpointKS) ks).supportsSPARQL_1_1()) || !(ks instanceof SparqlEndpointKS))){ - int popularity = reasoner.getIndividualsCount(cls); - //we skip classes with no instances - if(popularity == 0) continue; - double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(popularity, 0); - double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; - evalDesc = new EvaluatedDescription(cls, new AxiomScore(1- accuracy)); - } else { - evalDesc = new EvaluatedDescription(cls, new AxiomScore(1)); - } - - evalDescs.add(evalDesc); - } - - //secondly, create disjoint classexpressions with score 1 - (#occurence/#all) - for(Entry<NamedClass, Integer> entry : sortByValues(class2Count)){ -// evalDesc = new EvaluatedDescription(entry.getKey(), -// new AxiomScore(1 - (entry.getValue() / (double)all))); double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, entry.getValue()); double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; evalDesc = new EvaluatedDescription(entry.getKey(), @@ -385,6 +360,7 @@ return evalDescs; } + private void keepMostGeneralClasses(Set<NamedClass> classes){ ClassHierarchy h = reasoner.getClassHierarchy(); for(NamedClass nc : new HashSet<NamedClass>(classes)){ @@ -393,17 +369,16 @@ } public static void main(String[] args) throws Exception{ - LocalModelBasedSparqlEndpointKS ks = new LocalModelBasedSparqlEndpointKS(new URL("http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/examples/swore/swore.rdf?revision=2217")); - DisjointClassesLearner l = new DisjointClassesLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), - Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()))); - l = new DisjointClassesLearner(ks); +// SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); + SparqlEndpointKS ks = new LocalModelBasedSparqlEndpointKS(new URL("http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/examples/swore/swore.rdf?revision=2217")); + DisjointClassesLearner l = new DisjointClassesLearner(ks); l.setClassToDescribe(new NamedClass("http://ns.softwiki.de/req/CustomerRequirement")); l.init(); - l.getReasoner().prepareSubsumptionHierarchy(); +// l.getReasoner().prepareSubsumptionHierarchy(); // System.out.println(l.getReasoner().getClassHierarchy().getSubClasses(new NamedClass("http://dbpedia.org/ontology/Athlete"), false));System.exit(0); l.start(); - for(EvaluatedAxiom e : l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE, 0.75)){ + for(EvaluatedAxiom e : l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE, 0.2)){ System.out.println(e); } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-21 14:38:40 UTC (rev 3513) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-27 10:36:53 UTC (rev 3514) @@ -45,6 +45,7 @@ import org.dllearner.learningproblems.Heuristics; import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.owl.AxiomComparator; +import org.openrdf.model.vocabulary.OWL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -55,6 +56,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.util.iterator.Filter; /** * @author Lorenz Bühmann @@ -193,7 +195,7 @@ return new SPARQLTasks(((SparqlEndpointKS) ks).getEndpoint()).getAllClasses(); } else { Set<NamedClass> classes = new TreeSet<NamedClass>(); - for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().toList()){ + for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().filterDrop(new OWLFilter()).toList()){ if(!cls.isAnon()){ classes.add(new NamedClass(cls.getURI())); } @@ -235,7 +237,7 @@ } protected ResultSet executeSelectQuery(String query, Model model) { - logger.info("Sending query\n{} ...", query); + logger.info("Sending query on local model\n{} ...", query); QueryExecution qexec = QueryExecutionFactory.create(query, model); ResultSet rs = qexec.execSelect();; @@ -317,6 +319,17 @@ return new AxiomScore(accuracy, confidence); } + class OWLFilter extends Filter<OntClass>{ + + @Override + public boolean accept(OntClass cls) { + if(!cls.isAnon()){ + return cls.getURI().startsWith(OWL.NAMESPACE); + } + return false; + } + + } } Modified: trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2011-12-21 14:38:40 UTC (rev 3513) +++ trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2011-12-27 10:36:53 UTC (rev 3514) @@ -35,7 +35,7 @@ // read the RDF/XML file baseModel.read(in, null); - model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, baseModel); + model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF, baseModel); } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |