buildingmotif.dataclasses.validation#

Functions

diffset_to_templates(grouped_diffset)

Combine GraphDiff by focus node to generate a list of templates that reconcile what is "wrong" with the Graph with respect to the GraphDiffs.

Classes

GraphClassCardinality(focus, ...)

Represents a graph that is missing an expected number of instances of the given class.

GraphDiff(focus, validation_result, graph)

An abstraction of a SHACL Validation Result that can produce a template that resolves the difference between the expected and actual graph.

OrShape(focus, validation_result, graph, shapes)

Represents an entity that is missing one of several possible shapes, via sh:or

PathClassCount(focus, validation_result, ...)

Represents an entity missing paths to objects of a given type: $this <path> <object> .

PathShapeCount(focus, validation_result, ...)

Represents an entity missing paths to objects that match a given shape.

RequiredClass(focus, validation_result, ...)

Represents an entity that should be an instance of the class.

RequiredPath(focus, validation_result, ...)

Represents an entity missing a required property.

ValidationContext(shape_collections, ...)

Holds the necessary information for processing the results of SHACL validation.

class GraphDiff(focus: Optional[URIRef], validation_result: Graph, graph: Graph)[source]#

An abstraction of a SHACL Validation Result that can produce a template that resolves the difference between the expected and actual graph.

Each GraphDiff has a ‘focus’ that is the node in the model that the GraphDiff is about. If ‘focus’ is None, then the GraphDiff is about the model itself rather than a specific node

focus: Optional[URIRef]#
validation_result: Graph#
graph: Graph#
resolve(lib: Library) List[Template][source]#

Produces a list of templates to resolve this GraphDiff.

Parameters:

lib (Library) – the library to hold the templates

Returns:

templates that reconcile the GraphDiff

Return type:

List[Template]

reason() str[source]#

Human-readable explanation of this GraphDiff.

property failed_shape: Optional[URIRef]#

The URI of the Shape that failed

property failed_component: Optional[URIRef]#

The Constraint Component of the Shape that failed

format_count_error(max_count, min_count, path, object_type: Optional[str] = None) str[source]#

Format a count error message for a given object type and path.

Parameters:
  • max_count (int) – the maximum number of objects expected

  • min_count (int) – the minimum number of objects expected

  • object_type (str) – the type of object expected

  • path (str) – the path to the object

Returns:

the formatted error message

Return type:

str

class OrShape(focus: Optional[URIRef], validation_result: Graph, graph: Graph, shapes: Tuple[URIRef])[source]#

Represents an entity that is missing one of several possible shapes, via sh:or

shapes: Tuple[URIRef]#
reason() str[source]#

Human-readable explanation of this GraphDiff.

classmethod from_validation_report(report: Graph) List[OrShape][source]#

Construct OrShape objects from a SHACL validation report.

Parameters:

report (Graph) – the SHACL validation report

Returns:

a list of OrShape objects

Return type:

List[OrShape]

class PathClassCount(focus: Optional[URIRef], validation_result: Graph, graph: Graph, path: URIRef, minc: Optional[int], maxc: Optional[int], classname: URIRef)[source]#

Represents an entity missing paths to objects of a given type: $this <path> <object> . <object> a <classname> .

path: URIRef#
minc: Optional[int]#
maxc: Optional[int]#
classname: URIRef#
classmethod from_validation_report(report: Graph) List[PathClassCount][source]#

Construct PathClassCount objects from a SHACL validation report.

Parameters:

report (Graph) – the SHACL validation report

Returns:

a list of PathClassCount objects

Return type:

List[PathClassCount]

reason() str[source]#

Human-readable explanation of this GraphDiff.

resolve(lib: Library) List[Template][source]#

Produces a list of templates to resolve this GraphDiff.

Parameters:

lib (Library) – the library to hold the templates

Returns:

templates that reconcile the GraphDiff

Return type:

List[Template]

class PathShapeCount(focus: Optional[URIRef], validation_result: Graph, graph: Graph, path: URIRef, minc: Optional[int], maxc: Optional[int], shapename: URIRef, extra_body: Optional[Graph], extra_deps: Optional[Tuple])[source]#

Represents an entity missing paths to objects that match a given shape. $this <path> <object> . <object> a <shapename> .

path: URIRef#
minc: Optional[int]#
maxc: Optional[int]#
shapename: URIRef#
extra_body: Optional[Graph]#
extra_deps: Optional[Tuple]#
classmethod from_validation_report(report: Graph) Generator[PathShapeCount, None, None][source]#

Construct PathShapeCount objects from a SHACL validation report.

Parameters:

report (Graph) – the SHACL validation report

Returns:

a list of PathShapeCount objects

Return type:

List[PathShapeCount]

reason() str[source]#

Human-readable explanation of this GraphDiff.

resolve(lib: Library) List[Template][source]#

Produces a list of templates to resolve this GraphDiff.

class RequiredPath(focus: Optional[URIRef], validation_result: Graph, graph: Graph, path: URIRef, minc: Optional[int], maxc: Optional[int])[source]#

Represents an entity missing a required property.

path: URIRef#
minc: Optional[int]#
maxc: Optional[int]#
classmethod from_validation_report(report: Graph) List[RequiredPath][source]#

Construct RequiredPath objects from a SHACL validation report.

Parameters:

report (Graph) – the SHACL validation report

Returns:

a list of RequiredPath objects

Return type:

List[RequiredPath]

reason() str[source]#

Human-readable explanation of this GraphDiff.

resolve(lib: Library) List[Template][source]#

Produces a list of templates to resolve this GraphDiff.

Parameters:

lib (Library) – the library to hold the templates

Returns:

templates that reconcile the GraphDiff

Return type:

List[Template]

class RequiredClass(focus: Optional[URIRef], validation_result: Graph, graph: Graph, classname: URIRef)[source]#

Represents an entity that should be an instance of the class.

classname: URIRef#
reason() str[source]#

Human-readable explanation of this GraphDiff.

resolve(lib: Library) List[Template][source]#

Produces a list of templates to resolve this GraphDiff.

Parameters:

lib (Library) – the library to hold the templates

Returns:

templates that reconcile the GraphDiff

Return type:

List[Template]

class GraphClassCardinality(focus: Optional[URIRef], validation_result: Graph, graph: Graph, classname: URIRef, expectedCount: int)[source]#

Represents a graph that is missing an expected number of instances of the given class.

classname: URIRef#
expectedCount: int#
reason() str[source]#

Human-readable explanation of this GraphDiff.

resolve(lib: Library) List[Template][source]#

Produces a list of templates to resolve this GraphDiff.

Parameters:

lib (Library) – the library to hold the templates

Returns:

templates that reconcile the GraphDiff

Return type:

List[Template]

class ValidationContext(shape_collections: List[ShapeCollection], shapes_graph: Graph, valid: bool, report: Graph, report_string: str, model: Model)[source]#

Holds the necessary information for processing the results of SHACL validation.

shape_collections: List[ShapeCollection]#
shapes_graph: Graph#
valid: bool#
report: Graph#
report_string: str#
model: Model#
property diffset: Dict[Optional[URIRef], Set[GraphDiff]]#

The unordered set of GraphDiffs produced from interpreting the input SHACL validation report.

as_templates() List[Template][source]#

Produces the set of templates that reconcile the GraphDiffs from the SHACL validation report.

Returns:

reconciling templates

Return type:

List[Template]

get_broken_entities() Set[URIRef][source]#

Get the set of entities that are broken in the model.

Returns:

set of entities that are broken

Return type:

Set[URIRef]

get_diffs_for_entity(entity: URIRef) Set[GraphDiff][source]#

Get the set of diffs for a specific entity.

Parameters:

entity (URIRef) – the entity to get diffs for

Returns:

set of diffs for the entity

Return type:

Set[GraphDiff]

get_reasons_with_severity(severity: Union[URIRef, str]) Dict[Optional[URIRef], Set[GraphDiff]][source]#

Like diffset, but only includes ValidationResults with the given severity. Permitted values are: - SH.Violation or “Violation” for violations - SH.Warning or “Warning” for warnings - SH.Info or “Info” for info

Parameters:

severity (Union[URIRef|str]) – the severity to filter by

Returns:

a dictionary of focus nodes to the reasons with the given severity

Return type:

Dict[Optional[URIRef], Set[GraphDiff]]

diffset_to_templates(grouped_diffset: Dict[Optional[URIRef], Set[GraphDiff]]) List[Template][source]#

Combine GraphDiff by focus node to generate a list of templates that reconcile what is “wrong” with the Graph with respect to the GraphDiffs.

Parameters:

diffset (Set[GraphDiff]) – a set of diffs produced by _report_to_diffset

Returns:

list of templates that should resolve the SHACL violations when populated

Return type:

List[Template]