shaclapi.query module#

class shaclapi.query.Query(query_string, target_var=None, namespace_manager=None)[source]#

Bases: object

copy()[source]#
property query_object#
property triples#
property target_var#
property namespace_manager#
property variables#
property PV#
static prepare_query(query, namespace_manager=None)[source]#

Query must be slightly modified to fit the conditions of travshacl, rdflib, …

Parameters:

query (string) – Initial select query

Returns:

Valid Query-Object for further processing

Return type:

Query

is_starshaped()[source]#
make_starshaped()[source]#
extract_filter_terms()[source]#
extract_values_terms()[source]#
extract_triples()[source]#

Entry point for a recursive run over a sparql.algebra, which represents a query as nested dictionaries. :returns: List of triples (s, p, o) where each term is given by its internal rdflib representation (e.g.: Variable(‘?subject’)) :rtype: list

as_target_query(target_var, replace_prefixes=False)[source]#

Creates a target query based on the given query_string, where the projection is reduced to the target_var only and (optionally) the prefixes are replaced and removed.

Parameters:

replace_prefixes (bool, optional) – Highlights if prefixes should be replaced or not. Defaults to True.

Returns:

A target query corresponding to the query_string

Return type:

string

intersect(target_var, oldTargetQuery) str[source]#

Merges two queries using intersection

static target_query_from_triples(triples: set, filters: Optional[list] = None, values: Optional[list] = None, namespace_manager=None)[source]#
static query_from_parts(PV: list, distinct: bool, triples: set, filters: Optional[list] = None, values: Optional[list] = None, namespace_manager=None)[source]#
get_statement()[source]#
as_result_query()[source]#
get_predicates(replace_prefixes=True, ignore_inv=True)[source]#

Returns a list of all predicates appearing in the query_string. Optionally replacing prefixes and/or ignoring the paths’ directions.

Parameters:
  • replace_prefixes (bool, optional) – Highlights whether prefixes should be replaced or not. Defaults to True.

  • ignore_inv (bool, optional) – Highlights whether path directions can be ignored. Defaults to True.

Returns:

A list of all predicates/paths

Return type:

list(string)

get_triples(replace_prefixes=True)[source]#

Returns a list of all triples appearing in the query_string. Optionally replacing prefixes.

Parameters:

replace_prefixes (bool, optional) – Highlights whether prefixes should be replaced or not. Defaults to True.

Returns:

A list of all triples where each triple is a tuple or three strings (‘subject’, ‘predicate’, ‘object)

Return type:

list

get_variables_from_pred(pred)[source]#

Assumption star-shaped query with target variables only as subject!