org.dllearner.kb.sparql
Class SPARQLTasks

java.lang.Object
  extended by org.dllearner.kb.sparql.SPARQLTasks

public class SPARQLTasks
extends Object

Convenience class for SPARQL queries initialized with a SparqlEndpoint. A Cache can also be used to further improve query time. Some methods allow basic reasoning

Author:
Sebastian Hellmann, Jens Lehmann

Constructor Summary
SPARQLTasks(Cache cache, SparqlEndpoint sparqlEndpoint)
           
SPARQLTasks(SparqlEndpoint sparqlEndpoint)
           
 
Method Summary
 boolean ask(String askQueryString)
           
 Set<NamedClass> getAllClasses()
           
 Set<DatatypeProperty> getAllDataProperties()
           
 Set<ObjectProperty> getAllObjectProperties()
           
 SortedSet<String> getClassesForInstance(String instance, int sparqlResultLimit)
          get all direct Classes of an instance.
 SortedSet<String> getDomainInstances(String role, int sparqlResultLimit)
          Returns all instances that are in the prefield (subject) of the property/role.
 SortedSet<String> getParallelClasses(String classURI, int limit)
           
static SPARQLTasks getPredefinedSPARQLTasksWithCache(String endpointName)
           
 SortedSet<String> getRangeInstances(String role, int sparqlResultLimit)
          Returns all instances that are fillers of the property/role.
 SparqlEndpoint getSparqlEndpoint()
           
static SortedSet<String> getStringSetForVariableFromResultSet(com.hp.hpl.jena.query.ResultSetRewindable rs, String variable)
           
 SortedSet<String> getSubClasses(String classURI, int maxDepth)
          gets a SortedSet of all subclasses up to a certain depth TODO the mentioned method does not exist conceptRewrite(String descriptionKBSyntax, SparqlEndpoint se, Cache c, boolean simple )
 SortedSet<String> getSuperClasses(String classURI, int maxDepth)
          get all superclasses up to a certain depth, 1 means direct superclasses only.
 Entity guessResourceType(String resource)
           
 String query(String sparqlQueryString)
          low level, executes query returns JSON.
 int queryAsCount(String sparqlQueryString)
          variable must be ?
 SortedSet<RDFNodeTuple> queryAsRDFNodeTuple(String sparqlQueryString, String var1, String var2)
           
 com.hp.hpl.jena.query.ResultSetRewindable queryAsResultSet(String sparqlQueryString)
          low level, executes query returns ResultSet.
 SortedSet<String> queryAsSet(String sparqlQueryString, String variable)
          little higher level, executes query ,returns all resources for a variable.
 SortedSet<StringTuple> queryAsTuple(String subject, boolean filterLiterals)
          Deprecated. 
 SortedSet<StringTuple> queryAsTuple(String sparqlQueryString, String var1, String var2)
          Deprecated. 
 SortedSet<String> queryPatternAsSet(String subject, String predicate, String object, String variable, int sparqlResultLimit, boolean distinct)
          query a pattern with a standard SPARQL query.
 SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject(String role, String object, int sparqlResultLimit)
          Retrieves all resource for a fixed role and object.
 SortedSet<String> retrieveInstancesForClassDescription(String conceptKBSyntax, int sparqlResultLimit)
          get all instances for a complex concept / class description in KBSyntax.
 SortedSet<String> retrieveInstancesForClassDescriptionIncludingSubclasses(String conceptKBSyntax, int sparqlResultLimit, int maxDepth)
          same as retrieveInstancesForClassDescription including RDFS Reasoning.
 SortedSet<String> retrieveInstancesForSKOSConcept(String skosConcept, int sparqlResultLimit)
          all instances for a SKOS concept.
 SortedSet<String> retrieveObjectsForSubjectAndRole(String subject, String role, int sparqlResultLimit)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SPARQLTasks

public SPARQLTasks(SparqlEndpoint sparqlEndpoint)
Parameters:
sparqlEndpoint - the Endpoint the sparql queries will be send to

SPARQLTasks

public SPARQLTasks(Cache cache,
                   SparqlEndpoint sparqlEndpoint)
Parameters:
cache - a cache object
sparqlEndpoint - the Endpoint the sparql queries will be send to
Method Detail

getSuperClasses

public SortedSet<String> getSuperClasses(String classURI,
                                         int maxDepth)
get all superclasses up to a certain depth, 1 means direct superclasses only.

Parameters:
classURI - the uri of the class with no quotes for which the superclasses will be retrieved
maxDepth - how far the RDF graph will be explored (1 means only direct SuperClasses)
Returns:
a Sorted String Set of all ClassNames, including the starting class

getParallelClasses

public SortedSet<String> getParallelClasses(String classURI,
                                            int limit)

getSubClasses

public SortedSet<String> getSubClasses(String classURI,
                                       int maxDepth)
gets a SortedSet of all subclasses up to a certain depth TODO the mentioned method does not exist conceptRewrite(String descriptionKBSyntax, SparqlEndpoint se, Cache c, boolean simple )

Parameters:
classURI - An URI string with no quotes
maxDepth -
Returns:
TreeSet of subclasses including classURI

retrieveDISTINCTSubjectsForRoleAndObject

public SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject(String role,
                                                                  String object,
                                                                  int sparqlResultLimit)
Retrieves all resource for a fixed role and object. These instances are distinct. QUALITY: buggy because role doesn't work sometimes get subject with fixed role and object

Parameters:
role - An URI string with no quotes
object - An URI string with no quotes
sparqlResultLimit - Limits the ResultSet size
Returns:
SortedSet with the resulting subjects

retrieveObjectsForSubjectAndRole

public SortedSet<String> retrieveObjectsForSubjectAndRole(String subject,
                                                          String role,
                                                          int sparqlResultLimit)
Parameters:
subject - An URI string with no quotes
role - An URI string with no quotes
sparqlResultLimit - Limits the ResultSet size
Returns:
SortedSet with the resulting objects

retrieveInstancesForSKOSConcept

public SortedSet<String> retrieveInstancesForSKOSConcept(String skosConcept,
                                                         int sparqlResultLimit)
all instances for a SKOS concept.

Parameters:
skosConcept - An URI string with no quotes
sparqlResultLimit - Limits the ResultSet size
Returns:
SortedSet with the instances

retrieveInstancesForClassDescription

public SortedSet<String> retrieveInstancesForClassDescription(String conceptKBSyntax,
                                                              int sparqlResultLimit)
get all instances for a complex concept / class description in KBSyntax.

Parameters:
conceptKBSyntax - A description string in KBSyntax
sparqlResultLimit - Limits the ResultSet size
Returns:
SortedSet with the instance uris

retrieveInstancesForClassDescriptionIncludingSubclasses

public SortedSet<String> retrieveInstancesForClassDescriptionIncludingSubclasses(String conceptKBSyntax,
                                                                                 int sparqlResultLimit,
                                                                                 int maxDepth)
same as retrieveInstancesForClassDescription including RDFS Reasoning.

Parameters:
conceptKBSyntax - A description string in KBSyntax
sparqlResultLimit - Limits the ResultSet size
Returns:
SortedSet with the instance uris

getClassesForInstance

public SortedSet<String> getClassesForInstance(String instance,
                                               int sparqlResultLimit)
get all direct Classes of an instance.

Parameters:
instance - An URI string with no quotes
sparqlResultLimit - Limits the ResultSet size

getDomainInstances

public SortedSet<String> getDomainInstances(String role,
                                            int sparqlResultLimit)
Returns all instances that are in the prefield (subject) of the property/role. Cave: These have to fulfill the following requirements: 1. They are not literals 2. They have at least a Class assigned 3. DISTINCT is used in the query TODO there might be a better name for the function

Parameters:
role - An URI of a property/role
sparqlResultLimit - ResultSet limit
Returns:
A String Set of instances

getRangeInstances

public SortedSet<String> getRangeInstances(String role,
                                           int sparqlResultLimit)
Returns all instances that are fillers of the property/role. Cave: These have to fulfill the following requirements: 1. The fillers are not literals 2. The fillers have at least a Class assigned 3. DISTINCT is used in the query TODO there might be a better name for the function

Parameters:
role - An URI of a property/role
sparqlResultLimit - ResultSet limit
Returns:
A String Set of instances

queryPatternAsSet

public SortedSet<String> queryPatternAsSet(String subject,
                                           String predicate,
                                           String object,
                                           String variable,
                                           int sparqlResultLimit,
                                           boolean distinct)
query a pattern with a standard SPARQL query. The Query will be of the form SELECT * WHERE { subject predicate object } LIMIT X. It has a high degree of freedom, but only one variabla can be retrieved. usage example 1 : queryPatternAsSet( "?subject", "", "?object", "subject" ). retrieves all subjects, that have the role, somerole usage example 1 : queryPatternAsSet( "?subject", "", "?object", "object" ). retrieves all objects, that have the role, somerole

Parameters:
subject - An URI string enclosed in <> or a SPARQL variable e.g. "?subject"
predicate - An URI string enclosed in <> or a SPARQL variable e.g. "?predicate"
object - An URI string enclosed in <> or a SPARQL variable e.g. "?object"
variable - The variable to be retrieved and put into the SortedSet
sparqlResultLimit - 0 means all
distinct - determines whether distinct is used
Returns:
a String Set with the Bindings of the variable in variable

queryAsTuple

@Deprecated
public SortedSet<StringTuple> queryAsTuple(String subject,
                                                      boolean filterLiterals)
Deprecated. 


queryAsTuple

@Deprecated
public SortedSet<StringTuple> queryAsTuple(String sparqlQueryString,
                                                      String var1,
                                                      String var2)
Deprecated. 


queryAsRDFNodeTuple

public SortedSet<RDFNodeTuple> queryAsRDFNodeTuple(String sparqlQueryString,
                                                   String var1,
                                                   String var2)

queryAsSet

public SortedSet<String> queryAsSet(String sparqlQueryString,
                                    String variable)
little higher level, executes query ,returns all resources for a variable.

Parameters:
sparqlQueryString - The query
variable - The single variable used in the query

queryAsResultSet

public com.hp.hpl.jena.query.ResultSetRewindable queryAsResultSet(String sparqlQueryString)
low level, executes query returns ResultSet.

Parameters:
sparqlQueryString - The query
Returns:
jena ResultSet

queryAsCount

public int queryAsCount(String sparqlQueryString)
variable must be ?count

Parameters:
sparqlQueryString -
Returns:
-1 on failure count on success

query

public String query(String sparqlQueryString)
low level, executes query returns JSON.

Parameters:
sparqlQueryString - The query

ask

public boolean ask(String askQueryString)

getStringSetForVariableFromResultSet

public static SortedSet<String> getStringSetForVariableFromResultSet(com.hp.hpl.jena.query.ResultSetRewindable rs,
                                                                     String variable)

getSparqlEndpoint

public SparqlEndpoint getSparqlEndpoint()

getPredefinedSPARQLTasksWithCache

public static SPARQLTasks getPredefinedSPARQLTasksWithCache(String endpointName)

guessResourceType

public Entity guessResourceType(String resource)

getAllObjectProperties

public Set<ObjectProperty> getAllObjectProperties()

getAllDataProperties

public Set<DatatypeProperty> getAllDataProperties()

getAllClasses

public Set<NamedClass> getAllClasses()


SourceForge.net Logo DL-Learner is licenced under the terms of the GNU General Public License.
Copyright © 2007-2011 Jens Lehmann