sparql.py

View code on Github

Functions for running SPARQL queries within the query check process.

scribe_data.wikidata.check_query.sparql.sparql_context(url: str) SPARQLWrapper.SPARQLWrapper[source]

Configure a SPARQL context.

A context allows the execution of SPARQL queries.

Parameters:
urlstr

A valid URL of a SPARQL endpoint.

Returns:
SPARQLWrapper

The context.

scribe_data.wikidata.check_query.sparql.execute(query: QueryFile, limit: int, context: SPARQLWrapper.SPARQLWrapper, tries: int = 3) dict[source]

Execute a SPARQL query in a given context.

Parameters:
queryQueryFile

The SPARQL query to run.

limitint

The maximum number of results a query should return.

contextSPARQLWrapper

The SPARQL context.

triesint

The maximum number of times the query should be executed after failure.

Returns:
dict

The results of the query.