Skip to content

kg_edit_utils

update_metric_values(exe_kg, task_output_dict, bottom_level_namespace, top_level_namespace)

Updates the metric values in the given ExeKG.

Parameters:

Name Type Description Default
exe_kg Graph

The knowledge graph to update.

required
task_output_dict Dict[str, Union[str, int, float, bool]]

A dictionary containing the task output names and values.

required
bottom_level_namespace Namespace

The bottom level namespace for the output entity IRI.

required
top_level_namespace Namespace

The top level namespace for the hasValue property.

required

Returns:

Type Description
None

None

Source code in exe_kg_lib/utils/kg_edit_utils.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def update_metric_values(
    exe_kg: Graph,
    task_output_dict: Dict[str, Union[str, int, float, bool]],
    bottom_level_namespace: Namespace,
    top_level_namespace: Namespace,
) -> None:
    """
    Updates the metric values in the given ExeKG.

    Args:
        exe_kg (Graph): The knowledge graph to update.
        task_output_dict (Dict[str, Union[str, int, float, bool]]): A dictionary containing the task output names and values.
        bottom_level_namespace (Namespace): The bottom level namespace for the output entity IRI.
        top_level_namespace (Namespace): The top level namespace for the hasValue property.

    Returns:
        None
    """
    for task_output_name, task_output_value in task_output_dict.items():
        if "DataOutScore" in task_output_name:
            output_entity_iri = URIRef(bottom_level_namespace + task_output_name)
            exe_kg.remove(
                (
                    output_entity_iri,
                    URIRef(top_level_namespace.hasValue),
                    None,
                )
            )
            exe_kg.add(
                (
                    output_entity_iri,
                    URIRef(top_level_namespace.hasValue),
                    field_value_to_literal(task_output_value),
                )
            )

update_pipeline_input_path(exe_kg, pipeline_iri, new_input_data_path, top_level_namespace)

Updates the input data path of a pipeline in the given ExeKG.

Parameters:

Name Type Description Default
exe_kg Graph

The knowledge graph to update.

required
pipeline_iri Union[str, URIRef]

The IRI of the pipeline to update.

required
new_input_data_path str

The new input data path to set for the pipeline.

required
top_level_namespace Namespace

The namespace containing the relevant RDF predicates.

required

Returns:

Type Description
None

None

Source code in exe_kg_lib/utils/kg_edit_utils.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def update_pipeline_input_path(
    exe_kg: Graph,
    pipeline_iri: Union[str, URIRef],
    new_input_data_path: str,
    top_level_namespace: Namespace,
) -> None:
    """
    Updates the input data path of a pipeline in the given ExeKG.

    Args:
        exe_kg (Graph): The knowledge graph to update.
        pipeline_iri (Union[str, URIRef]): The IRI of the pipeline to update.
        new_input_data_path (str): The new input data path to set for the pipeline.
        top_level_namespace (Namespace): The namespace containing the relevant RDF predicates.

    Returns:
        None
    """
    exe_kg.remove(
        (
            URIRef(pipeline_iri),
            URIRef(top_level_namespace.hasInputDataPath),
            None,
        )
    )
    exe_kg.add(
        (
            URIRef(pipeline_iri),
            URIRef(top_level_namespace.hasInputDataPath),
            field_value_to_literal(new_input_data_path),
        )
    )