buildingmotif.dataclasses.model#
Classes
|
This class mirrors |
- class Model(_id: int, _name: str, _description: str, graph: Graph, _bm: BuildingMOTIF, _manifest_id: int)[source]#
This class mirrors
database.tables.DBModel
.- graph: Graph#
- classmethod create(name: str, description: str = '') Model [source]#
Create a new model.
- Parameters:
name (str) – new model name
description (str) – new model description
- Returns:
new model
- Return type:
- classmethod load(id: Optional[int] = None, name: Optional[str] = None) Model [source]#
Get model from database by id or name.
- Parameters:
id (Optional[int], optional) – model id, defaults to None
name (Optional[str], optional) – model name, defaults to None
- Raises:
Exception – if neither id nor name provided
- Returns:
model
- Return type:
- property id: Optional[int]#
- property name#
- property description#
- add_triples(*triples: Tuple[Node, Node, Node]) None [source]#
Add the given triples to the model.
- Parameters:
triples (Triple) – a sequence of triples to add to the graph
- add_graph(graph: Graph) None [source]#
Add the given graph to the model.
- Parameters:
graph (rdflib.Graph) – the graph to add to the model
- validate(shape_collections: Optional[List[ShapeCollection]] = None, 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:
shape_collections (List[ShapeCollection]) – a list of ShapeCollections against which the graph should be validated. If an empty list or None is provided, the model will be validated against the model’s manifest.
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:
- compile(shape_collections: List[ShapeCollection])[source]#
Compile the graph of a model against a set of ShapeCollections.
- Parameters:
shape_collections (List[ShapeCollection]) – list of ShapeCollections to compile the model against
- Returns:
copy of model’s graph that has been compiled against the ShapeCollections
- Return type:
Graph
- test_model_against_shapes(shape_collections: List[ShapeCollection], 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:
shape_collections – list of ShapeCollections needed to run shapes
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]
- get_manifest() ShapeCollection [source]#
Get ShapeCollection from model.
- Returns:
model’s shape collection
- Return type:
- update_manifest(manifest: ShapeCollection)[source]#
Updates the manifest for this model by adding in the contents of the shape graph inside the provided SHapeCollection
- Parameters:
manifest (ShapeCollection) – the ShapeCollection containing additional shapes against which to validate this model