From: <lor...@us...> - 2011-08-09 12:42:04
|
Revision: 3019 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3019&view=rev Author: lorenz_b Date: 2011-08-09 12:41:57 +0000 (Tue, 09 Aug 2011) Log Message: ----------- Fixed some bugs. Modified Paths: -------------- 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/DisjointPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.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-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -29,6 +29,7 @@ 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; @@ -155,8 +156,10 @@ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); } - result.put(nc, Integer.valueOf(cnt + 1)); + result.put(nc, cnt); } } @@ -230,5 +233,14 @@ 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")); + l.setMaxExecutionTimeInSeconds(0); + l.init(); + l.start(); + System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); + } + } 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-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -156,8 +156,10 @@ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); } - result.put(nc, Integer.valueOf(cnt + 1)); + result.put(nc, cnt); } } @@ -208,30 +210,11 @@ types = new HashSet<Datatype>(); individual2Datatypes.put(ind, types); } - types.add(getDatatypeForURI(qs.getResource("datatype").getURI())); + types.add(new Datatype(qs.getResource("datatype").getURI())); } return individual2Datatypes; } - private Datatype getDatatypeForURI(String uri){ - return new Datatype(uri); -// if(uri.equals(OWL2Datatype.BOOLEAN.getURI())) -// return OWL2Datatype.BOOLEAN.getDatatype(); -// else if(uri.equals(OWL2Datatype.DOUBLE.getURI())) -// return OWL2Datatype.DOUBLE.getDatatype(); -// else if(uri.equals(OWL2Datatype.INT.getURI())) -// return OWL2Datatype.INT.getDatatype(); -// else if(uri.equals(OWL2Datatype.INTEGER.getURI())) -// return OWL2Datatype.INTEGER.getDatatype(); -// else if(uri.equals(OWL2Datatype.STRING.getURI())) -// return OWL2Datatype.STRING.getDatatype(); -// else if(uri.equals(OWL2Datatype.DATE.getURI())) -// return OWL2Datatype.DATE.getDatatype(); -// else if(uri.equals(OWL2Datatype.DATETIME.getURI())) -// return OWL2Datatype.DATETIME.getDatatype(); -// throw new Error("Unsupported datatype " + uri + ". Please inform a DL-Learner developer to add it."); - } - /* * Executes a SELECT query and returns the result. */ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -19,6 +19,7 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DisjointObjectPropertyAxiom; @@ -39,7 +40,7 @@ private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); - @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) private int maxExecutionTimeInSeconds = 10; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -1,7 +1,5 @@ package org.dllearner.algorithms.properties; -import java.beans.PropertyEditor; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -14,8 +12,8 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.AbstractComponent; import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -24,6 +22,7 @@ import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -39,7 +38,6 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; @ComponentAnn(name="property domain axiom learner") public class PropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { @@ -159,8 +157,10 @@ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); } - result.put(nc, Integer.valueOf(cnt + 1)); + result.put(nc, cnt); } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -12,8 +12,8 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.AbstractComponent; import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -22,6 +22,7 @@ import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -29,6 +30,7 @@ import org.dllearner.core.owl.ObjectPropertyRangeAxiom; 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; @@ -36,7 +38,6 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; @ComponentAnn(name="property range learner") public class PropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { @@ -156,13 +157,15 @@ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); } - result.put(nc, Integer.valueOf(cnt + 1)); + result.put(nc, cnt); } } EvaluatedAxiom evalAxiom; - for(Entry<NamedClass, Integer> entry : sortByValues(result)){ + for(Entry<NamedClass, Integer> entry : sortByValues(result)){System.out.println(entry.getKey());System.out.println(entry.getValue()); evalAxiom = new EvaluatedAxiom(new ObjectPropertyRangeAxiom(propertyToDescribe, entry.getKey()), new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); axioms.add(evalAxiom); @@ -195,7 +198,7 @@ private Map<Individual, Set<NamedClass>> getObjectsWithTypes(int offset){ Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); int limit = 1000; - String query = String.format("SELECT ?ind ?type WHERE {?s <%s> ?ind. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?s <%s> ?ind. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); ResultSet rs = executeQuery(query); QuerySolution qs; Individual ind; @@ -230,5 +233,14 @@ ResultSet resultSet = queryExecution.execSelect(); return resultSet; } + + public static void main(String[] args) throws Exception{ + PropertyRangeAxiomLearner l = new PropertyRangeAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/aircraftElectronic")); + l.setMaxExecutionTimeInSeconds(0); + l.init(); + l.start(); + System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); + } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -65,5 +65,30 @@ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { return uri.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Datatype other = (Datatype) obj; + if (uri == null) { + if (other.uri != null) + return false; + } else if (!uri.equals(other.uri)) + return false; + return true; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |