Previous topic

Miscellaneous Utilities

Next topic

JSON Utils

This Page

SPARQL utils

The sparql module contains several functions that wrap commonly used SPARQL queries in Python code.

eltk.utils.sparql.getABoxTriples(graph)

Return all triples in a graph’

Parameter:graph (rdflib.graph.Graph) – the graph to search
Return type:list
eltk.utils.sparql.getBaseClasses(graph, cls_uri)
Parameters:
  • graph (rdflib.Graph.Graph) – the relevant graph to process
  • cls_uri (rdflib.URIRef.URIRef) – the URI of the particular class
Return type:

list

eltk.utils.sparql.getComments(graph, uri_string)

Return all comments associated with some URI

Parameters:
  • graph (rdflib.Graph.Graph) – the graph to search
  • uri_string (str) – a URI of some concept
Return type:

list

eltk.utils.sparql.getIndividuals(graph)

getIndividuals returns a dictionary where keys are URIRefs of individuals and values are lists of types (ie OWL class URIs)

Parameter:graph (rdflib.graph.Graph) – the relevant graph to process
Returns:(keys) individual URIs, (values) lists of types, OWL class URIs
Return type:dict
eltk.utils.sparql.getOWLClasses(graph)

Return all OWL Classes in a graph’

Parameter:graph (rdflib.graph.Graph) – the graph to search
Return type:list
eltk.utils.sparql.getOWLDatatypeProperties(graph)

Return all OWL DataProperties in a graph’

Parameter:graph (rdflib.graph.Graph) – the graph to search
Return type:list
eltk.utils.sparql.getOWLObjectProperties(graph)

Return all OWL ObjectProperties in a graph’

Parameter:graph (rdflib.graph.Graph) – the graph to search
Return type:list
eltk.utils.sparql.getSubClasses(graph, cls_uri)

Given an rdflib.graph.Graph and a URIRef of some OWL class, return a list of subclasses

Parameters:
  • graph (rdflib.graph.Graph) – the graph to search
  • cls_uri (rdflib.URIRef.URIRef) –
Return type:

list

eltk.utils.sparql.getUnitBasedOnForm(graph, form)

Return linguistic units accordings to a particular form

Parameters:
  • graph (rdflib.graph.Graph) – the relevant graph
  • form (str) – the form to search for
Return type:

list

eltk.utils.sparql.sparqlQuery(sparql_string, context)

sparqlQuery is a wrapper function for making queries over specific contexts within the store.

Parameters:
  • sparql_string (str) – Well formed SPARQL query
  • context (rdflib.Graph.Graph) – A graph
Returns:

A list of tuples containing the results

Return type:

list