buildingmotif.dataclasses.library#

Classes

Library(_id, _name, _bm)

This class mirrors database.tables.DBLibrary.

class Library(_id: int, _name: str, _bm: BuildingMOTIF)[source]#

This class mirrors database.tables.DBLibrary.

classmethod create(name: str, overwrite: Optional[bool] = True) Library[source]#

Create new Library.

Parameters:
  • name (str) – library name

  • overwrite (Optional[bool]) – if True, overwrite the existing copy of the library.

Returns:

new library

Return type:

Library

classmethod load(db_id: Optional[int] = None, ontology_graph: Optional[Union[str, Graph]] = None, directory: Optional[str] = None, name: Optional[str] = None, overwrite: Optional[bool] = True, infer_templates: Optional[bool] = True, run_shacl_inference: Optional[bool] = True) Library[source]#

Loads a library from the database or an external source. When specifying a path to load a library or ontology_graph from, paths within the buildingmotif.libraries module will be prioritized if they resolve.

Parameters:
  • db_id (Optional[int], optional) – the unique id of the library in the database, defaults to None

  • ontology_graph (Optional[str|rdflib.Graph], optional) – a path to a serialized RDF graph. Supports remote ontology URLs, defaults to None

  • directory (Optional[str], optional) – a path to a directory containing a library, or an rdflib graph, defaults to None

  • name (Optional[str], optional) – the name of the library inside the database, defaults to None

  • overwrite (Optional[true], optional) – if true, replace any existing copy of the library, defaults to True

  • infer_templates (Optional[bool], optional) – if true, infer shapes from the ontology graph, defaults to True

  • run_shacl_inference (Optional[bool], optional) – if true, run SHACL inference on the ontology graph, using the BuildingMOTIF SHACL engine, defaults to True

Returns:

the loaded library

Return type:

Library

Raises:

Exception – if the library cannot be loaded

classmethod load_from_libraries_yml(filename: str)[source]#

Loads multiple libraries from a properly-formatted ‘libraries.yml’ file. Does not return a Library! You will need to load the libraries by name in order to get the dataclasses.Library object. We recommend loading libraries directly, one-by-one, in most cases. This method is here to support the commandline tool.

Parameters:

filename (str) – the filename of the YAML file to load library names from

Return type:

None

property id: Optional[int]#
property name: str#
property graph_imports: List[URIRef]#

Get the list of owl:imports for this library’s shape collection

create_template(name: str, body: Optional[Graph] = None, optional_args: Optional[List[str]] = None) Template[source]#

Create template in this library.

Parameters:
  • name (str) – name

  • body (rdflib.Graph) – template body

  • optional_args (list[str]) – optional parameters for the template

Returns:

created template

Return type:

Template

get_templates() List[Template][source]#

Get templates from library.

Returns:

list of templates

Return type:

List[Template]

get_shape_collection() ShapeCollection[source]#

Get ShapeCollection from library.

Returns:

library’s shape collection

Return type:

ShapeCollection

get_template_by_name(name: str) Template[source]#

Get template by name from library.

Parameters:

name (str) – template name

Raises:

ValueError – if template not in library

Returns:

template

Return type:

Template