Skip to content

query_utils

get_data_properties_plus_inherited_by_class_iri(kg, entity_iri)

Retrieves data properties plus the inherited ones, given an entity IRI

Parameters:

Name Type Description Default
kg Graph

Graph object to use when querying

required
entity_iri str

IRI of entity to query

required

Returns:

Name Type Description
List List

contains rows of data property IRIs and their range

Source code in exe_kg_lib/utils/query_utils.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def get_data_properties_plus_inherited_by_class_iri(kg: Graph, entity_iri: str) -> List:
    """
    Retrieves data properties plus the inherited ones, given an entity IRI
    Args:
        kg: Graph object to use when querying
        entity_iri: IRI of entity to query

    Returns:
        List: contains rows of data property IRIs and their range
    """
    property_list = list(get_data_properties_by_entity_iri(entity_iri, kg))
    method_parent_classes = list(query_method_parent_classes(kg, entity_iri))
    for method_class_result_row in method_parent_classes:
        property_list += list(get_data_properties_by_entity_iri(method_class_result_row[0], kg))

    return property_list

get_method_by_task_iri(kg, namespace_prefix, namespace, task_iri)

Retrieves a task's method, given a task IRI

Parameters:

Name Type Description Default
kg Graph

Graph object to use when querying

required
namespace_prefix str

namespace prefix to use when querying

required
namespace Namespace

namespace to use when querying

required
task_iri str

IRI of task to query

required

Returns:

Type Description
Optional[Entity]

Optional[Entity]: object containing found method's basic info is equal to None if method IRI wasn't found in KG

Source code in exe_kg_lib/utils/query_utils.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def get_method_by_task_iri(
    kg: Graph,
    namespace_prefix: str,
    namespace: Namespace,
    task_iri: str,
) -> Optional[Entity]:
    """
    Retrieves a task's method, given a task IRI
    Args:
        kg: Graph object to use when querying
        namespace_prefix: namespace prefix to use when querying
        namespace: namespace to use when querying
        task_iri: IRI of task to query

    Returns:
        Optional[Entity]: object containing found method's basic info
                          is equal to None if method IRI wasn't found in KG
    """
    query_result = get_first_query_result_if_exists(
        query_method_iri_by_task_iri,
        kg,
        namespace_prefix,
        task_iri,
    )
    if query_result is None:
        return None

    method_iri = str(query_result[0])

    query_result = get_first_query_result_if_exists(
        query_entity_parent_iri,
        kg,
        method_iri,
        namespace.AtomicMethod,
    )
    if query_result is None:
        return None

    method_parent_iri = str(query_result[0])

    return Entity(method_iri, Entity(method_parent_iri))

get_pipeline_and_first_task_iri(kg, namespace_prefix)

Retrieves the necessary information needed to start parsing a pipeline

Parameters:

Name Type Description Default
kg Graph

Graph object to use when querying

required
namespace_prefix str

namespace prefix to use when querying

required

Returns:

Type Description
Tuple[str, str, str]

Tuple[str, str, str]: contains the pipeline IRI, the input data path and the first task's IRI

Source code in exe_kg_lib/utils/query_utils.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def get_pipeline_and_first_task_iri(kg: Graph, namespace_prefix: str) -> Tuple[str, str, str]:
    """
    Retrieves the necessary information needed to start parsing a pipeline
    Args:
        kg: Graph object to use when querying
        namespace_prefix: namespace prefix to use when querying

    Returns:
        Tuple[str, str, str]: contains the pipeline IRI, the input data path and the first task's IRI
    """
    # assume one pipeline per file
    query_result = get_first_query_result_if_exists(
        query_pipeline_info,
        kg,
        namespace_prefix,
    )
    if query_result is None:
        print("Error: Pipeline info not found")
        exit(1)

    pipeline_iri, input_data_path, task_iri = query_result

    return str(pipeline_iri), str(input_data_path), str(task_iri)

Last update: October 20, 2023