shaclapi.api module#

This module offers the main functionalities of the shaclAPI to the user.

The shaclAPI uses Python’s multiprocessing capabilities for parallel execution of the SHACL validation during SPARQL query execution. Due to delays occurring when parsing SPARQL queries with rdflib for the first time in each process, importing this module or parts of it will start a process for each task-type the shaclAPI needs to execute. These processes will stay running and wait for tasks to process.

shaclapi.api.get_result_queue()[source]#

Convenience function to get a multiprocessing queue object, which can be used as a result_queue in shaclapi.api.run_multiprocessing().

Returns:

A queue usable in shaclapi.api.run_multiprocessing().

Return type:

python.multiprocessing.Queue

shaclapi.api.run_multiprocessing(pre_config, result_queue=None)[source]#

Main function of the shaclAPI: Given a dictionary of configuration keys (properties in shaclapi.config) with the configured values, the shaclAPI starts the parallel execution of the SHACL validation during SPARQL query execution, while applying the activated heuristics.

The following directed graph demonstrates the principal procedure. (Nodes represent tasks/processes and edges represent queues for colaboration):

_images/procedure.png
shaclapi.api.unify_target_shape(target_shape, query)[source]#

Given a target shape configuration (see shaclapi.config.target_shape) and a SPARQL query shaclapi.query.Query a reformatted version of the target shape configuration is returned. The format is {?var: list of target shapes}, where ?var is a variable occuring in the query.

Parameters:
  • target_shape (dict, list or string) – A target shape configuration (see shaclapi.config.target_shape)

  • query (shaclapi.query.Query) – The SPARQL query.

shaclapi.api.only_reduce_shape_schema(pre_config)[source]#

Only reduces the given SHACL shape schema based on the provided target shape.

The given SHACL shape schema is reduced to all shapes that are reachable from the provided target shape, i.e., they need to be validated in order to form a decision on the satisfaction of the instances of the target shape.

Returns:

A list with the names of the shapes in the reduced shape schema.

Return type:

list

shaclapi.api.overlap_reduced_schemas(pre_config, shape_one, shape_two)[source]#

Computes the percentage of overlap for two reduced shape schemas.

First, for both sets of shapes, the reduced shape schema is generated. Afterwards, the intersection of both shape schemas is computed. The percentage of overlap is the number of shapes in the intersection divided by the number of shapes in the smaller of the input shape schemas.

Returns:

The percentage of overlap in both reduced shape schemas based on the minimal number of shapes in the input shape schemas.

Return type:

float

shaclapi.api.validation_and_statistics(pre_config)[source]#

Validates a SHACL shape schema and provides additional statistics.

The SHACL shape schema is validated based on the provided configuration. That includes the path of the SHACL shape schema as well as the heuristics used to optimize the validation performance.

Returns:

  • JSON structure

  • {shape1 – {valid: #valid instances, invalid: #invalid instances, columns: [column name 1, column name 2, …], results: [[instance 1 data 1,instance 1 data 2, …], [instance 2 data 1,instance 2 data 2, …], …] }

  • shape2 ({…})

  • }

dict

The result includes per-shape counts of the valid and invalid instances as well as a Boolean per instance of the shape stating its satisfaction of the shape’s constraints.