check_query_identifiers.py

View code on Github

Check the queries within Scribe-Data to make sure the language and data type are correct.

Examples

>>> python3 src/scribe_data/check/check_query_identifiers.py
scribe_data.check.check_query_identifiers.is_valid_language(query_file: Path, lang_qid: str) bool[source]

Validate the language QID against the expected QID for the directory.

Parameters:
query_filePath

The path to the SPARQL query file being validated.

lang_qidstr

The QID of the language extracted from the SPARQL query.

Returns:
bool

True if the language QID is valid, otherwise False.

Examples

> is_valid_language(Path(“path/to/query.sparql”), “Q123456”) True

scribe_data.check.check_query_identifiers.is_valid_data_type(query_file: Path, data_type_qid: str) bool[source]

Validate the data type QID against the expected QID for the directory.

Parameters:
query_filePath

The path to the SPARQL query file being validated.

data_type_qidstr

The QID of the data type extracted from the SPARQL query.

Returns:
bool

True if the data type QID is valid, otherwise False.

Examples

> is_valid_data_type(Path(“path/to/query.sparql”), “Q654321”) True

scribe_data.check.check_query_identifiers.extract_qid_from_sparql(file_path: Path, pattern: str) str[source]

Extract the QID from a SPARQL query file based on the provided pattern.

Parameters:
file_pathPath

The path to the SPARQL query file from which to extract the QID.

patternstr

The regex pattern used to match the QID (either for language or data type).

Returns:
str

The extracted QID if found, otherwise None.

Raises:
FileNotFoundError

If the specified file does not exist.

scribe_data.check.check_query_identifiers.check_query_identifiers() None[source]

Validate SPARQL queries in the language data directory to check for correct language and data type QIDs.