franz.openrdf.query package¶
Submodules¶
franz.openrdf.query.dataset module¶
franz.openrdf.query.query module¶
-
class
franz.openrdf.query.query.
BooleanQuery
(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)[source]¶ Bases:
franz.openrdf.query.query.Query
A query that returns a boolean.
-
class
franz.openrdf.query.query.
GraphQuery
(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)[source]¶ Bases:
franz.openrdf.query.query.Query
A query that returns statements (see
Statement
).-
evaluate
(output=None, output_format=RDFFormat.TABLE: Table)[source]¶ 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: - output (str|file|int|bool) – A file name, file descriptor or a file-like
object to save the results to
(optional).
-
-
class
franz.openrdf.query.query.
Query
(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)[source]¶ Bases:
object
A query on a {@link 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)[source]¶ 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)[source]¶ 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 aQueryResult
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 (ifcount=True
).Return type: dict|string|int|bool
- count (bool) – If
-
getBindings
()[source]¶ Retrieve the bindings that have been set on this query.
Returns: A dictionary of bindings. Return type: dict[string, Value]
-
getDataset
()[source]¶ Get the dataset against which this query will operate.
Returns: Dataset. Return type: Dataset
-
getIncludeInferred
()[source]¶ Check whether this query will return inferred statements. :return:
True
if inferred triples are included,False
otherwise. :rtype: bool
-
removeBinding
(name)[source]¶ 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)[source]¶ 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)[source]¶ Set multiple variable bindings.
Parameters: dict (dict[string, Value]) – A dictionary of bindings.
-
setCheckVariables
(setting)[source]¶ 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.
-
setContexts
(contexts)[source]¶ Assert a set of contexts (named graphs) that filter all triples.
Parameters: contexts (list[URI|string]) – List of graph URIs.
-
-
class
franz.openrdf.query.query.
QueryLanguage
(name)[source]¶ Bases:
object
-
PROLOG
= QueryLanguage.PROLOG¶
-
SPARQL
= QueryLanguage.SPARQL¶
-
registered_languages
= [QueryLanguage.SPARQL, QueryLanguage.PROLOG]¶
-
-
class
franz.openrdf.query.query.
TupleQuery
(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)[source]¶ Bases:
franz.openrdf.query.query.Query
A query that returns tuples (i.e. sets of variable bindings).
-
analyze
(analysisTechnique=None, analysisTimeout=None)[source]¶ Analyze the query.
Analysis is only available for SPARQL queries.
Parameters: Returns: Analysis result as a dictionary.
Return type:
-
evaluate
(count=False, output=None, output_format=TupleFormat.TABLE: Table)[source]¶ 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) orNone
(ifoutput
is used).Return type: TupleQueryResult|int
- count (bool) – If
-
-
class
franz.openrdf.query.query.
UpdateQuery
(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)[source]¶ Bases:
franz.openrdf.query.query.Query
An update query.
franz.openrdf.query.queryresult module¶
-
class
franz.openrdf.query.queryresult.
GraphQueryResult
(string_tuples)[source]¶ Bases:
franz.openrdf.query.repositoryresult.RepositoryResult
,franz.openrdf.query.queryresult.QueryResult
A graph query result is an iterator over the Statements.
-
class
franz.openrdf.query.queryresult.
ListBindingSet
(variable_names)[source]¶ 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.
-
getRow
()[source]¶ 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)[source]¶ Gets the value of the binding with the specified name from this BindingSet. Throws exception if ‘bindingName’ is not legal.
-
hasBinding
(bindingName)[source]¶ Checks whether this BindingSet has a binding with the specified name.
-
iterator
()[source]¶ 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.
-
-
class
franz.openrdf.query.queryresult.
QueryResult
[source]¶ Bases:
object
Super type of all query result types (TupleQueryResult, GraphQueryResult, etc. Evaluates as a Python iterator
-
class
franz.openrdf.query.queryresult.
TupleQueryResult
(variable_names, string_tuples)[source]¶ 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.
franz.openrdf.query.repositoryresult module¶
-
class
franz.openrdf.query.repositoryresult.
RepositoryResult
(string_tuples, subjectFilter=None, tripleIDs=False)[source]¶ 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
, ororg.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 {{@link #enableDuplicateFilter() switched on}, but this should not be used lightly as the filtering mechanism is potentially memory-intensive.
A RepositoryResult needs to be {@link #close() closed} after use to free up any resources (open connections, read locks, etc.) it has on the underlying repository.
-
addTo
(collection)[source]¶ 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
()[source]¶ 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
()[source]¶ Shut down the iterator to be sure the resources are freed up.
It is safe to call this method multiple times.
-
enableDuplicateFilter
()[source]¶ 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.
-