|
From: <lor...@us...> - 2011-07-28 08:30:47
|
Revision: 2971
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2971&view=rev
Author: lorenz_b
Date: 2011-07-28 08:30:40 +0000 (Thu, 28 Jul 2011)
Log Message:
-----------
Continued reasoner for SPARQL endpoints.
Modified Paths:
--------------
trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java
trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java
trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.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/algorithms/properties/ReflexivePropertyAxiomLearner.java
trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java
trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java
trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java
trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java
Added Paths:
-----------
trunk/components-core/src/main/java/org/dllearner/core/config/
trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java
trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java
trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java
trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java
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-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -11,7 +11,6 @@
public class DisjointPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
private String propertyToDescribe;
public String getPropertyToDescribe() {
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -11,7 +11,6 @@
public class EquivalentPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
private String propertyToDescribe;
public String getPropertyToDescribe() {
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -11,7 +11,6 @@
public class FunctionalPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
private String propertyToDescribe;
public String getPropertyToDescribe() {
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-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -11,7 +11,6 @@
public class PropertyDomainAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
private String propertyToDescribe;
public String getPropertyToDescribe() {
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-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -11,7 +11,6 @@
public class PropertyRangeAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
private String propertyToDescribe;
public String getPropertyToDescribe() {
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -11,7 +11,6 @@
public class ReflexivePropertyAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
private String propertyToDescribe;
public String getPropertyToDescribe() {
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -1,29 +1,36 @@
package org.dllearner.algorithms.properties;
+import java.beans.PropertyEditor;
+import java.lang.reflect.Field;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.dllearner.core.AxiomLearningAlgorithm;
import org.dllearner.core.Component;
import org.dllearner.core.ComponentInitException;
+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.Axiom;
+import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.kb.SparqlEndpointKS;
+import org.dllearner.kb.sparql.SparqlEndpoint;
+import org.springframework.beans.propertyeditors.CustomNumberEditor;
public class SubPropertyOfAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
- private String propertyToDescribe;
+ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class)
+ private ObjectProperty propertyToDescribe;
+ @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class)
+ private int maxExecutionTimeInSeconds;
- public String getPropertyToDescribe() {
- return propertyToDescribe;
- }
-
- public void setPropertyToDescribe(String propertyToDescribe) {
- this.propertyToDescribe = propertyToDescribe;
- }
-
+
+ private SparqlEndpointKS ks;
+
public SubPropertyOfAxiomLearner(SparqlEndpointKS ks){
-
+ this.ks = ks;
}
@Override
@@ -50,4 +57,42 @@
}
+ public int getMaxExecutionTimeInSeconds() {
+ return maxExecutionTimeInSeconds;
+ }
+
+ public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) {
+ this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds;
+ }
+
+ public ObjectProperty getPropertyToDescribe() {
+ return propertyToDescribe;
+ }
+
+ public void setPropertyToDescribe(ObjectProperty propertyToDescribe) {
+ this.propertyToDescribe = propertyToDescribe;
+ }
+
+ public static void main(String[] args) throws Exception{
+ Map<String, String> propertiesMap = new HashMap<String, String>();
+ propertiesMap.put("propertyToDescribe", "http://dbpedia.org/ontology/locatedIn");
+ propertiesMap.put("maxExecutionTimeInSeconds", "20");
+
+ SubPropertyOfAxiomLearner l = new SubPropertyOfAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
+
+ Field[] fields = l.getClass().getDeclaredFields();
+ for(Field f : fields){
+ ConfigOption option = f.getAnnotation(ConfigOption.class);
+ if(option != null){
+ String configValue = propertiesMap.get(option.name());
+ PropertyEditor editor = (PropertyEditor) option.propertyEditorClass().newInstance();
+ editor.setAsText(configValue);
+ f.set(l, editor.getValue());
+ }
+ }
+
+ System.out.println(l.getPropertyToDescribe());
+ System.out.println(l.getMaxExecutionTimeInSeconds());
+ }
+
}
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -11,7 +11,6 @@
public class SymmetricPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
private String propertyToDescribe;
public String getPropertyToDescribe() {
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -11,7 +11,6 @@
public class TransitivePropertyAxiomLearner extends Component implements AxiomLearningAlgorithm {
- @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned")
private String propertyToDescribe;
public String getPropertyToDescribe() {
Added: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java (rev 0)
+++ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -0,0 +1,36 @@
+package org.dllearner.core.config;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Chris
+ * Date: 7/26/11
+ * Time: 8:55 PM
+ *
+ * This is an example annotation class allowing one to configure a field with a name, description, and corresponding property editor.
+ *
+ * Note: Only put this on Setters that take the actual object you want to end up with as the example expects it to be on the setter
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ConfigOption {
+
+ /**
+ * The name of this config option.
+ * @return The name of this config option.
+ */
+ String name();
+
+ /**
+ * The description of this config option
+ * @return
+ */
+ String description();
+
+ /**
+ * An implementation of the Property Editor to use
+ * @return
+ */
+ Class propertyEditorClass();
+}
Property changes on: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java (rev 0)
+++ trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -0,0 +1,82 @@
+package org.dllearner.core.config;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyEditor;
+
+public class IntegerEditor implements PropertyEditor {
+
+ private Integer value;
+
+ @Override
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getAsText() {
+ return value.toString();
+ }
+
+ @Override
+ public Component getCustomEditor() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getJavaInitializationString() {
+ return value.toString();
+ }
+
+ @Override
+ public String[] getTags() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Object getValue() {
+ return value;
+ }
+
+ @Override
+ public boolean isPaintable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void paintValue(Graphics gfx, Rectangle box) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setAsText(String text) throws IllegalArgumentException {
+ value = Integer.valueOf(text);
+
+ }
+
+ @Override
+ public void setValue(Object value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean supportsCustomEditor() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
Property changes on: trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java (rev 0)
+++ trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -0,0 +1,88 @@
+package org.dllearner.core.config;
+
+import org.dllearner.core.owl.ObjectProperty;
+
+import java.awt.*;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyEditor;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Chris
+ * Date: 7/26/11
+ * Time: 9:42 PM
+ * <p/>
+ * Basic Property Editor for the Object Property DL-Learner class. Doesn't have GUI support yet but we could add that later if we wanted.
+ */
+public class ObjectPropertyEditor implements PropertyEditor {
+
+
+ private ObjectProperty value;
+
+ @Override
+ public void setValue(Object value) {
+ this.value = (ObjectProperty) value;
+ }
+
+ @Override
+ public Object getValue() {
+ return value;
+ }
+
+ @Override
+ public boolean isPaintable() {
+ /** Not right now, we're doing non gui work */
+ return false;
+ }
+
+ @Override
+ public void paintValue(Graphics gfx, Rectangle box) {
+
+ }
+
+ @Override
+ public String getJavaInitializationString() {
+ /** This returns the value needed to reconstitute the object from a string */
+ return value.getName();
+ }
+
+ @Override
+ public String getAsText() {
+ /** Get the text value of this object - for displaying in GUIS, etc */
+ return value.getName();
+ }
+
+ @Override
+ public void setAsText(String text) throws IllegalArgumentException {
+ value = new ObjectProperty(text);
+ }
+
+ @Override
+ public String[] getTags() {
+ /** If there was a known set of values it had to have, we could add that list here */
+ return new String[0];
+ }
+
+ @Override
+ public Component getCustomEditor() {
+ /** GUI stuff, if you wanted to edit it a custom way */
+ return null;
+ }
+
+ @Override
+ public boolean supportsCustomEditor() {
+ /** We don't support this right now, but maybe later */
+ return false;
+
+ }
+
+ @Override
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ /** More gui stuff, we don't need this for our basic example */
+ }
+
+ @Override
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ /** More gui stuff, we don't need this for our basic example */
+ }
+}
Property changes on: trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java (rev 0)
+++ trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -0,0 +1,22 @@
+package org.dllearner.core.config;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Chris
+ * Date: 7/26/11
+ * Time: 10:17 PM
+ * <p/>
+ * Making a basic extension so I can get a default constructor so that using reflection is simpler.
+ *
+ * I'm extending a Spring provided class for this.
+ */
+public class OurStringTrimmerEditor extends org.springframework.beans.propertyeditors.StringTrimmerEditor {
+
+
+ /**
+ * Default Constructor
+ */
+ public OurStringTrimmerEditor() {
+ super(true);
+ }
+}
Property changes on: trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-07-27 14:33:14 UTC (rev 2970)
+++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-07-28 08:30:40 UTC (rev 2971)
@@ -1,8 +1,11 @@
package org.dllearner.reasoning;
+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;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -16,17 +19,21 @@
import org.dllearner.core.owl.DatatypePropertyHierarchy;
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Individual;
+import org.dllearner.core.owl.Intersection;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.ObjectPropertyHierarchy;
import org.dllearner.kb.SparqlEndpointKS;
+import org.dllearner.kb.sparql.SparqlEndpoint;
import org.dllearner.utilities.datastructures.SortedSetTuple;
+import com.clarkparsia.owlapiv3.XSD;
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;
import com.hp.hpl.jena.vocabulary.RDF;
+import com.hp.hpl.jena.vocabulary.RDFS;
public class SPARQLReasoner implements SchemaReasoner, IndividualReasoner{
@@ -138,8 +145,30 @@
@Override
public Map<Individual, SortedSet<Individual>> getPropertyMembers(ObjectProperty objectProperty) {
- // TODO Auto-generated method stub
- return null;
+ Map<Individual, SortedSet<Individual>> subject2objects = new HashMap<Individual, SortedSet<Individual>>();
+ String query = String.format("select ?s ?o WHERE {" +
+ "?s %s ?o." +
+ " FILTER(isIRI(?o))}",
+ inAngleBrackets(objectProperty.getName()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ Individual sub;
+ Individual obj;
+ SortedSet<Individual> objects;
+ while(rs.hasNext()){
+ qs = rs.next();
+ sub = new Individual(qs.getResource("s").getURI());
+ obj = new Individual(qs.getResource("o").getURI());
+ objects = subject2objects.get(sub);
+ if(objects == null){
+ objects = new TreeSet<Individual>();
+ subject2objects.put(sub, objects);
+ }
+ objects.add(obj);
+
+ }
+ return subject2objects;
}
@Override
@@ -150,32 +179,124 @@
@Override
public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) {
- // TODO Auto-generated method stub
- return null;
+ Map<Individual, SortedSet<Double>> subject2objects = new HashMap<Individual, SortedSet<Double>>();
+ String query = String.format("select ?s ?o WHERE {" +
+ "?s %s ?o." +
+ " FILTER(DATATYPE(?o) = %s)}",
+ inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.DOUBLE.toStringID()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ Individual sub;
+ Double obj;
+ SortedSet<Double> objects;
+ while(rs.hasNext()){
+ qs = rs.next();
+ sub = new Individual(qs.getResource("s").getURI());
+ obj = qs.getLiteral("o").getDouble();
+ objects = subject2objects.get(sub);
+ if(objects == null){
+ objects = new TreeSet<Double>();
+ subject2objects.put(sub, objects);
+ }
+ objects.add(obj);
+
+ }
+ return subject2objects;
}
@Override
public Map<Individual, SortedSet<Integer>> getIntDatatypeMembers(DatatypeProperty datatypeProperty) {
- // TODO Auto-generated method stub
- return null;
+ Map<Individual, SortedSet<Integer>> subject2objects = new HashMap<Individual, SortedSet<Integer>>();
+ String query = String.format("select ?s ?o WHERE {" +
+ "?s %s ?o." +
+ " FILTER(DATATYPE(?o) = %s)}",
+ inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.INT.toStringID()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ Individual sub;
+ Integer obj;
+ SortedSet<Integer> objects;
+ while(rs.hasNext()){
+ qs = rs.next();
+ sub = new Individual(qs.getResource("s").getURI());
+ obj = qs.getLiteral("o").getInt();
+ objects = subject2objects.get(sub);
+ if(objects == null){
+ objects = new TreeSet<Integer>();
+ subject2objects.put(sub, objects);
+ }
+ objects.add(obj);
+
+ }
+ return subject2objects;
}
@Override
public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembers(DatatypeProperty datatypeProperty) {
- // TODO Auto-generated method stub
- return null;
+ Map<Individual, SortedSet<Boolean>> subject2objects = new HashMap<Individual, SortedSet<Boolean>>();
+ String query = String.format("select ?s ?o WHERE {" +
+ "?s %s ?o." +
+ " FILTER(DATATYPE(?o) = %s)}",
+ inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.BOOLEAN.toStringID()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ Individual sub;
+ Boolean obj;
+ SortedSet<Boolean> objects;
+ while(rs.hasNext()){
+ qs = rs.next();
+ sub = new Individual(qs.getResource("s").getURI());
+ obj = qs.getLiteral("o").getBoolean();
+ objects = subject2objects.get(sub);
+ if(objects == null){
+ objects = new TreeSet<Boolean>();
+ subject2objects.put(sub, objects);
+ }
+ objects.add(obj);
+
+ }
+ return subject2objects;
}
@Override
public SortedSet<Individual> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) {
- // TODO Auto-generated method stub
- return null;
+ SortedSet<Individual> members = new TreeSet<Individual>();
+ String query = String.format("select ?ind WHERE {" +
+ "?ind %s ?o." +
+ " FILTER(isLiteral(?o) && DATATYPE(?o) = %s && ?o=%s)}",
+ inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.BOOLEAN.toStringID()),
+ "\"true\"^^"+inAngleBrackets(XSD.BOOLEAN.toStringID()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ while(rs.hasNext()){
+ qs = rs.next();
+ members.add(new Individual(qs.getResource("ind").getURI()));
+
+ }
+ return members;
}
@Override
public SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) {
- // TODO Auto-generated method stub
- return null;
+ SortedSet<Individual> members = new TreeSet<Individual>();
+ String query = String.format("select ?ind WHERE {" +
+ "?ind %s ?o." +
+ " FILTER(isLiteral(?o) && DATATYPE(?o) = %s && ?o=%s)}",
+ inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.BOOLEAN.toStringID()),
+ "\"false\"^^"+inAngleBrackets(XSD.BOOLEAN.toStringID()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ while(rs.hasNext()){
+ qs = rs.next();
+ members.add(new Individual(qs.getResource("ind").getURI()));
+
+ }
+ return members;
}
@Override
@@ -186,25 +307,75 @@
@Override
public Set<NamedClass> getInconsistentClasses() {
- // TODO Auto-generated method stub
- return null;
+ throw new UnsupportedOperationException();
}
@Override
public Description getDomain(ObjectProperty objectProperty) {
- // TODO Auto-generated method stub
+ String query = String.format("select ?domain WHERE {" +
+ "%s %s ?domain. FILTER(isIRI(?domain))" +
+ "}",
+ inAngleBrackets(objectProperty.getName()), inAngleBrackets(RDFS.domain.getURI()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ List<Description> domains = new ArrayList<Description>();
+ while(rs.hasNext()){
+ qs = rs.next();
+ domains.add(new NamedClass(qs.getResource("domain").getURI()));
+
+ }
+ if(domains.size() == 1){
+ return domains.get(0);
+ } else if(domains.size() > 1){
+ return new Intersection(domains);
+ }
return null;
}
@Override
public Description getDomain(DatatypeProperty datatypeProperty) {
- // TODO Auto-generated method stub
+ String query = String.format("select ?domain WHERE {" +
+ "%s %s ?domain. FILTER(isIRI(?domain))" +
+ "}",
+ inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(RDFS.domain.getURI()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ List<Description> domains = new ArrayList<Description>();
+ while(rs.hasNext()){
+ qs = rs.next();
+ domains.add(new NamedClass(qs.getResource("domain").getURI()));
+
+ }
+ if(domains.size() == 1){
+ return domains.get(0);
+ } else if(domains.size() > 1){
+ return new Intersection(domains);
+ }
return null;
}
@Override
public Description getRange(ObjectProperty objectProperty) {
- // TODO Auto-generated method stub
+ String query = String.format("select ?range WHERE {" +
+ "%s %s ?range. FILTER(isIRI(?range))" +
+ "}",
+ inAngleBrackets(objectProperty.getName()), inAngleBrackets(RDFS.range.getURI()));
+
+ ResultSet rs = executeQuery(query);
+ QuerySolution qs;
+ List<Description> ranges = new ArrayList<Description>();
+ while(rs.hasNext()){
+ qs = rs.next();
+ ranges.add(new NamedClass(qs.getResource("range").getURI()));
+
+ }
+ if(ranges.size() == 1){
+ return ranges.get(0);
+ } else if(ranges.size() > 1){
+ return new Intersection(ranges);
+ }
return null;
}
@@ -312,6 +483,7 @@
}
private ResultSet executeQuery(String query){
+ System.out.println(query);
QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query);
for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) {
queryExecution.addDefaultGraph(dgu);
@@ -338,5 +510,29 @@
private String inAngleBrackets(String s){
return "<" + s + ">";
}
+
+ public static void main(String[] args) {
+ String NS = "http://dbpedia.org/ontology/";
+ SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW());
+ SPARQLReasoner r = new SPARQLReasoner(ks);
+
+// ObjectProperty oP = new ObjectProperty(NS + "league");
+// for(Entry<Individual, SortedSet<Individual>> entry : r.getPropertyMembers(oP).entrySet()){
+// System.out.println(entry.getKey());
+// System.out.println(entry.getValue());
+// }
+//
+// DatatypeProperty dP = new DatatypeProperty(NS+ "areaLand");
+// for(Entry<Individual, SortedSet<Double>> entry : r.getDoubleDatatypeMembers(dP).entrySet()){
+// System.out.println(entry.getKey());
+// System.out.println(entry.getValue());
+// }
+
+ DatatypeProperty dP = new DatatypeProperty(NS+ "internationally");
+ for(Individual ind : r.getTrueDatatypeMembers(dP)){
+ System.out.println(ind);
+ }
+
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|