buildingmotif.dataclasses.shape_collection#

Classes

ShapeCollection(_id, graph, _bm)

This class mirrors database.tables.DBShapeCollection.

class ShapeCollection(_id: int, graph: Graph, _bm: BuildingMOTIF)[source]#

This class mirrors database.tables.DBShapeCollection.

graph: Graph#
classmethod create() ShapeCollection[source]#

Create a new ShapeCollection.

Returns:

new ShapeCollection

Return type:

ShapeCollection

classmethod load(id: int) ShapeCollection[source]#

Get ShapeCollection from database by id.

Parameters:

id (int) – ShapeCollection id

Returns:

ShapeCollection

Return type:

ShapeCollection

property id: Optional[int]#
property graph_name: Optional[URIRef]#

Returns the name of the graph (subject of “a owl:Ontology”) if one exists

add_triples(*triples: Tuple[Node, Node, Node]) None[source]#

Add the given triples to the graph.

Parameters:

triples (Triple) – a sequence of triples to add to the graph

add_graph(graph: Graph) None[source]#

Add the given graph to the ShapeCollection.

Parameters:

graph (rdflib.Graph) – the graph to add to the ShapeCollection

resolve_imports(recursive_limit: int = - 1, error_on_missing_imports: bool = True) ShapeCollection[source]#

Resolves owl:imports to as many levels as requested.

By default, all owl:imports are recursively resolved. This limit can be changed to 0 to suppress resolving imports, or to 1..n to handle recursion up to that limit.

Parameters:
  • recursive_limit (int, optional) – how many levels of owl:imports to resolve, defaults to -1 (all)

  • 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:

a new ShapeCollection with the types resolved

Return type:

ShapeCollection

get_shapes_of_definition_type(definition_type: URIRef, include_labels=False) Union[List[URIRef], List[Tuple[URIRef, str]]][source]#

Get subjects present in shape of the definition type.

Parameters:

definition_type (URIRef) – desired definition type

Returns:

subjects

Return type:

List[URIRef]

get_shapes_of_domain(domain: URIRef) List[URIRef][source]#

Get subjects present in shape of domain type.

Parameters:

domain (URIRef) – desired domain

Returns:

subjects

Return type:

List[URIRef]

get_shapes_about_class(rdf_type: URIRef, contexts: Optional[List[ShapeCollection]] = None) List[URIRef][source]#

Returns a list of shapes that either target the given class (or superclasses of it), or otherwise only apply to URIs of the given type.

Parameters:
  • rdf_type (URIRef) – an OWL class

  • contexts (List["ShapeCollection"], optional) – list of ShapeCollections that help determine the class structure

Returns:

a list of shapes in this ShapeCollection that concern that class

Return type:

List[URIRef]

shape_to_query(shape: URIRef) str[source]#

This method takes a URI representing a SHACL shape as an argument and returns a SPARQL query selecting the information which would be used to satisfy that SHACL shape. This uses the following rules: - <shape> sh:targetClass <class> -> ?target rdf:type/rdfs:subClassOf* <class> - <shape> sh:property [ sh:path <path>; sh:class <class>; sh:name <name> ] ->

?target <path> ?name . ?name rdf:type/rdfs:subClassOf* <class>

  • <shape> sh:property [ sh:path <path>; sh:hasValue <value>] ->

    ?target <path> <value>