Skip to content

kg_validation_utils

check_kg_executability(kg, shacl_shapes_s)

Checks the executability of a KG by validating it against a set of SHACL shapes.

Parameters:

Name Type Description Default
kg Union[Graph, str]

The KG to be validated. It can be either an rdflib.Graph object or a string representing the path to the KG file.

required
shacl_shapes_s str

The SHACL shapes to validate the KG against.

required

Raises:

Type Description
KGValidationError

If the KG is not executable, an exception is raised with an error message.

Returns:

Name Type Description
None None

This function does not return any value.

Source code in exe_kg_lib/utils/kg_validation_utils.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def check_kg_executability(kg: Union[rdflib.Graph, str], shacl_shapes_s: str) -> None:
    """
    Checks the executability of a KG by validating it against a set of SHACL shapes.

    Args:
        kg (Union[rdflib.Graph, str]): The KG to be validated. It can be either an rdflib.Graph object or a string representing the path to the KG file.
        shacl_shapes_s (str): The SHACL shapes to validate the KG against.

    Raises:
        KGValidationError: If the KG is not executable, an exception is raised with an error message.

    Returns:
        None: This function does not return any value.
    """
    r = validate(data_graph=kg, shacl_graph=shacl_shapes_s)
    conforms, _, results_text = r
    if not conforms:
        raise KGValidationError(
            f"{results_text}\n\nThe KG is not executable. To ensure executability of the KG as an ML pipeline, please fix the above error(s) and try again."
        )
    return