buildingmotif.dataclasses.compiled_model

buildingmotif.dataclasses.compiled_model#

Classes

CompiledModel(model, shape_collections, ...)

This class represents a model that has been compiled against a set of ShapeCollections.

class CompiledModel(model: Model, shape_collections: List[ShapeCollection], compiled_graph: Graph, shacl_engine: str = 'default')[source]#

This class represents a model that has been compiled against a set of ShapeCollections.

model: Model#
shape_collections: List[ShapeCollection]#
property graph: Graph#
validate_model_against_shapes(shapes_to_test: List[URIRef], target_class: URIRef) Dict[URIRef, ValidationContext][source]#

Validates the model against a list of shapes and generates a validation report for each.

Parameters:
  • shapes_to_test (List[URIRef]) – list of shape URIs to validate the model against

  • target_class (URIRef) – the class upon which to run the selected shapes

Returns:

a dictionary that relates each shape to test URIRef to a ValidationContext

Return type:

Dict[URIRef, ValidationContext]

validate(error_on_missing_imports: bool = True) ValidationContext[source]#

Validates this model against the given list of ShapeCollections. If no list is provided, the model will be validated against the model’s “manifest”. If a list of shape collections is provided, the manifest will not be automatically included in the set of shape collections.

Loads all of the ShapeCollections into a single graph.

Parameters:

error_on_missing_imports (bool, optional) – if True, raises an error if any of the dependency ontologies are missing (i.e. they need to be loaded into BuildingMOTIF), defaults to True

Returns:

An object containing useful properties/methods to deal with the validation results

Return type:

ValidationContext

defining_shape_collection(shape: URIRef) Optional[ShapeCollection][source]#

Given a shape, return the ShapeCollection that defines it. The search is limited to the ShapeCollections that were used to compile this model.

Parameters:

shape (rdflib.URIRef) – the shape to search for

Returns:

the ShapeCollection that defines the shape, or None if the shape is not defined

Return type:

Optional[ShapeCollection]

shape_to_table(shape: URIRef, table: str, conn)[source]#

Turn the shape into a SPARQL query and execute it on the model’s graph, storing the results in a table.

Parameters:
  • shape (rdflib.URIRef) – the shape to query

  • table (str) – the name of the table to store the results in

  • conn (sqlalchemy.engine.base.Connection) – the connection to the database

shape_to_df(shape: URIRef) DataFrame[source]#

Turn the shape into a SPARQL query and execute it on the model’s graph, storing the results in a dataframe.

Parameters:

shape (rdflib.URIRef) – the shape to query

Returns:

the results of the query

Return type:

pd.DataFrame