franz.openrdf.query package

Submodules

franz.openrdf.query.dataset module

class franz.openrdf.query.dataset.Dataset(contexts=None)

Bases: object

Records a set of default and named graphs that can restrict the scope of a query.

__init__(contexts=None)

Initialize self. See help(type(self)) for accurate signature.

addDefaultGraph(uri)
addNamedGraph(uri)
asQuery(excludeNullContext)
clear()
getDefaultGraphs()
getNamedGraphs()
removeDefaultGraph(uri)
removeNamedGraph(uri)

franz.openrdf.query.pandas_support module

franz.openrdf.query.pandas_support.rows_to_pandas(rows, column_names)
franz.openrdf.query.pandas_support.term_to_pandas(term)

franz.openrdf.query.query module

class franz.openrdf.query.query.BooleanQuery(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)

Bases: franz.openrdf.query.query.Query

A query that returns a boolean.

evaluate()

Execute the embedded query against the RDF store.

Returns:A boolean.
Return type:bool
class franz.openrdf.query.query.GraphQuery(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)

Bases: franz.openrdf.query.query.Query

A query that returns statements (see Statement).

evaluate(output=None, output_format=RDFFormat.TABLE: Table)

Execute the embedded query against the RDF store.

Parameters:
  • output (str|file|int|bool) – A file name, file descriptor or a file-like object to save the results to (optional). True can be used as a synonym for stdout.
  • output_format (RDFFormat) – Serialization format for output. The default is TABLE.
Returns:

An iterator over statements or None (if output is used)..

Return type:

GraphQueryResult

class franz.openrdf.query.query.Query(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)

Bases: object

A query on a repository that can be formulated in one of the supported query languages (for example SeRQL or SPARQL). It allows one to predefine bindings in the query to be able to reuse the same query with different bindings.

__init__(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)

Initialize a query object.

Parameters:
  • queryLanguage (QueryLanguage) – Query syntax - the default is SPARQL.
  • query (string) – Query text
  • baseURI (URI) – Prefix used to relsove relative URIs. Default: chosen by the server.
  • queryString (string) – Legacy name of the ‘query’ parameter.
evaluate_generic_query(count=False, accept=None, callback=None, analyze=False, analysisTechnique=None, analysisTimeout=None, update=False)

Evaluate a SPARQL or PROLOG query, which may be a ‘select’, ‘construct’, ‘describe’ or ‘ask’ query (in the SPARQL case). Return an appropriate response.

Parameters:
  • count (bool) – If True return only the count of the query results.
  • accept (string) – Set to 'application/sparql-results+xml' or 'application/sparql-results+json' to retrieve the result as a string in the specified format. The default is to return a QueryResult object.
  • analyze (bool) – If True perform query analysis for SPARQL queries.
  • analysisTechnique (string) – Control the method of analysis. Can be either “executed” (default). meaning that the query will be executed to perform dynamic analysis, or "static".
  • analysisTimeout (float) – Number of second to run the query if executed for analysis.
  • update (bool) – If True this is an update query and the result will be a boolean.
Returns:

The result can be either: - A boolean (for update queries). - A dictionary containing the results. - A string (if accept was passed). - An integer (if count=True).

Return type:

dict|string|int|bool

getBindings()

Retrieve the bindings that have been set on this query.

Returns:A dictionary of bindings.
Return type:dict[string, Value]
getDataset()

Get the dataset against which this query will operate.

Returns:Dataset.
Return type:Dataset
getIncludeInferred()

Check whether this query will return inferred statements. :return: True if inferred triples are included, False otherwise. :rtype: bool

removeBinding(name)

Removes a previously set binding on the supplied variable. Calling this method with an unbound variable name has no effect.

Parameters:name (string) – Variable name.
setBinding(name, value)

Binds the specified variable to the supplied value. Any value that was previously bound to the specified value will be overwritten.

Parameters:
  • name (string) – Variable name.
  • value (Value|basestring) – New value for the variable. If a string is passed it will be converted to a literal.
setBindings(dict)

Set multiple variable bindings.

Parameters:dict (dict[string, Value]) – A dictionary of bindings.
setCheckVariables(setting)

Determine whether the presence of variables in the select clause not referenced in a triple is flagged.

Parameters:setting (bool) – True if variables should be checked, False otherwise.
setConnection(connection)

Internal call to embed the connection into the query.

setContexts(contexts)

Assert a set of contexts (named graphs) that filter all triples.

Parameters:contexts (list[URI|string]) – List of graph URIs.
setDataset(dataset)

Select the dataset against which to evaluate this query, overriding any dataset that is specified in the query itself.

Parameters:dataset (Dataset) – A dataset object.
setIncludeInferred(includeInferred)

Determine whether evaluation results of this query should include inferred statements.

The default setting is True.

Parameters:includeInferred (bool) – If True include inferred triples in query results.
class franz.openrdf.query.query.QueryLanguage(name)

Bases: object

PROLOG = QueryLanguage.PROLOG
SPARQL = QueryLanguage.SPARQL
__init__(name)

Initialize self. See help(type(self)) for accurate signature.

getName()
registered_languages = [QueryLanguage.SPARQL, QueryLanguage.PROLOG]
static valueOf(name)
static values()
class franz.openrdf.query.query.TupleQuery(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)

Bases: franz.openrdf.query.query.Query

A query that returns tuples (i.e. sets of variable bindings).

analyze(analysisTechnique=None, analysisTimeout=None)

Analyze the query.

Analysis is only available for SPARQL queries.

Parameters:
  • analysisTechnique (string) – Control the method of analysis. Can be either “executed” (default). meaning that the query will be executed to perform dynamic analysis, or "static".
  • analysisTimeout (float) – Number of second to run the query if executed for analysis.
Returns:

Analysis result as a dictionary.

Return type:

dict

evaluate(count=False, output=None, output_format=TupleFormat.TABLE: Table)

Execute the embedded query against the RDF store.

Return an iterator that produces for each step a tuple of values (resources and literals) corresponding to the variables or expressions in a ‘select’ clause (or its equivalent).

Parameters:
  • count (bool) – If True return the number of result rows instead of the usual iterator.
  • output (str|file|int|bool) – A file name, file descriptor or a file-like object to save the results to (optional). True can be used as a synonym for stdout.
  • output_format (RDFFormat) – Serialization format for output. The default is TABLE.
Returns:

Either an iterator over results, an integer (the number of results, if count is used) or None (if output is used).

Return type:

TupleQueryResult|int

class franz.openrdf.query.query.UpdateQuery(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)

Bases: franz.openrdf.query.query.Query

An update query.

evaluate()

Execute the embedded update against the RDF store.

Returns:True if the query changed the store, False otherwise.
Return type:bool

franz.openrdf.query.queryresult module

class franz.openrdf.query.queryresult.Binding

Bases: franz.openrdf.query.queryresult.Binding

getName()

Gets the name of the binding (e.g. the variable name).

getValue()

Gets the value of the binding. The returned value is never equal to None, such a “binding” is considered to be unbound.

class franz.openrdf.query.queryresult.GraphQueryResult(string_tuples)

Bases: franz.openrdf.query.repositoryresult.RepositoryResult, franz.openrdf.query.queryresult.QueryResult

A graph query result is an iterator over the Statements.

__init__(string_tuples)

Initialize self. See help(type(self)) for accurate signature.

class franz.openrdf.query.queryresult.ListBindingSet(variable_names)

Bases: object

A BindingSet is a set of named value bindings, which is used to represent a single query solution. Values are indexed by name of the binding which typically corresponds to the names of the variables used in the projection of the original query.

ListBindingSet emulates an RDF4J BindingSet, a Python dictionary and a list simultaneously. The internal datastructure is a pair of lists.

__init__(variable_names)

Initialize self. See help(type(self)) for accurate signature.

getBinding(bindingName)

Gets the binding with the specified name from this BindingSet.

getBindingNames()

Gets the names of the bindings in this BindingSet.

getRow()

Return a list of strings representing the values of the current row. This exists mostly for debugging (otherwise, we would return terms instead of strings).

getValue(bindingName)

Gets the value of the binding with the specified name from this BindingSet. Throws exception if ‘bindingName’ is not legal.

hasBinding(bindingName)

Checks whether this BindingSet has a binding with the specified name.

iterator()

Creates an iterator over the bindings in this BindingSet. This only returns bindings with non-null values. An implementation is free to return the bindings in arbitrary order.

Currently, we only support Python-style iteration over BindingSet dictionaries, so this (Java-style) iterator method is not implemented.

size()

Returns the number of bindings in this BindingSet.

class franz.openrdf.query.queryresult.QueryResult

Bases: object

Super type of all query result types (TupleQueryResult, GraphQueryResult, etc. Evaluates as a Python iterator

close()

Release resources used by this query result.

class franz.openrdf.query.queryresult.TupleQueryResult(variable_names, string_tuples)

Bases: franz.openrdf.query.queryresult.QueryResult

A representation of a variable-binding query result as a sequence of BindingSet objects. Each query result consists of zero or more solutions, each of which represents a single query solution as a set of bindings. Note: take care to always close a TupleQueryResult after use to free any resources it keeps hold of.

__init__(variable_names, string_tuples)

Initialize self. See help(type(self)) for accurate signature.

close()

Release resources used by this query result.

getBindingNames()

Get the names of the bindings, in order of projection.

Returns:A list of names.
Return type:list[string]
rowCount()
toPandas()

franz.openrdf.query.repositoryresult module

class franz.openrdf.query.repositoryresult.RepositoryResult(string_tuples, subjectFilter=None, tripleIDs=False)

Bases: object

An iterable collection of statements.

A RepositoryResult is a result collection of objects (for example org.openrdf.model.Statement, org.openrdf.model.Namespace, or org.openrdf.model.Resource objects) that can be iterated over. It keeps an open connection to the backend for lazy retrieval of individual results. Additionally it has some utility methods to fetch all results and add them to a collection.

By default, a RepositoryResult is not necessarily a (mathematical) set: it may contain duplicate objects. Duplicate filtering can be enabled using enableDuplicateFilter(), but this should not be used lightly as the filtering mechanism is potentially memory-intensive.

A RepositoryResult needs to be closed using close() after use to free up any resources (open connections, read locks, etc.) it has on the underlying repository.

__init__(string_tuples, subjectFilter=None, tripleIDs=False)

Initialize self. See help(type(self)) for accurate signature.

addTo(collection)

Add all objects of this RepositoryResult to the supplied collection.

The RepositoryResult is fully consumed and automatically closed by this operation.

Parameters:collection (set|list) – The collection to add the results to. It can be a list or a set.
asList()

Returns a list containing all objects of this RepositoryResult in order of iteration.

The RepositoryResult is fully consumed and automatically closed by this operation. :return: List of statements. :rtype: list[Statement]

close()

Shut down the iterator to be sure the resources are freed up.

It is safe to call this method multiple times.

enableDuplicateFilter()

Switch on duplicate filtering while iterating over objects.

The RepositoryResult will keep track of the previously returned objects in a set and on calling next() will ignore any objects that already occur in this set.

Caution: use of this filtering mechanism is potentially memory-intensive.

static normalize_quad(stringTuple)
static normalize_quint(stringTuple)
rowCount()

Get the number of statements in this result object.

Returns:The number of results in this iterator.
toPandas(include_graph=True)

Module contents