Load Brick relationships from schema

This commit is contained in:
rileywong311
2023-07-29 17:18:58 -07:00
committed by Riley Wong
parent b662d6f08e
commit b9211e2a93
2 changed files with 19 additions and 9 deletions
@@ -56,15 +56,7 @@ def get_brick_roots(self, context):
def get_brick_relations(self, context): # this will be queried from graph
return [("https://brickschema.org/schema/Brick#hasLocation", "hasLocation", ""),
("https://brickschema.org/schema/Brick#isLocationOf", "isLocationOf", ""),
("https://brickschema.org/schema/Brick#hasPart", "hasPart", ""),
("https://brickschema.org/schema/Brick#isPartOf", "isPartOf", ""),
("https://brickschema.org/schema/Brick#hasPoint", "hasPoint", ""),
("https://brickschema.org/schema/Brick#isPointOf", "isPointOf", ""),
("https://brickschema.org/schema/Brick#feeds", "feeds", ""),
("https://brickschema.org/schema/Brick#isFedBy", "isFedBy", ""),
("http://www.w3.org/2000/01/rdf-schema#label", "label", "")]
return BrickStore.relationships
class Brick(PropertyGroup):
+18
View File
@@ -286,6 +286,7 @@ class Brick(blenderbim.core.tool.Brick):
BrickStore.path = filepath
BrickStore.load_namespaces()
BrickStore.load_entity_classes()
BrickStore.load_relationships()
@classmethod
def new_brick_file(cls):
@@ -298,6 +299,7 @@ class Brick(blenderbim.core.tool.Brick):
BrickStore.graph.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
BrickStore.load_namespaces()
BrickStore.load_entity_classes()
BrickStore.load_relationships()
@classmethod
def pop_brick_breadcrumb(cls):
@@ -363,6 +365,7 @@ class BrickStore:
namespaces = []
root_classes = ["Equipment", "Location", "System", "Point"]
entity_classes = {}
relationships = []
@staticmethod
def purge():
@@ -371,6 +374,7 @@ class BrickStore:
BrickStore.path = None
BrickStore.namespaces = []
BrickStore.entity_classes = {}
BrickStore.relationships = []
@classmethod
def get_project(cls):
@@ -407,6 +411,20 @@ class BrickStore:
for uri in sorted([x[0].toPython() for x in query]):
BrickStore.entity_classes[root_class].append((uri, uri.split("#")[-1], ""))
@classmethod
def load_relationships(cls):
query = BrickStore.graph.query(
"""
PREFIX brick: <https://brickschema.org/schema/Brick#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?relation WHERE {
?relation rdfs:subPropertyOf brick:Relationship .
}
"""
)
for uri in sorted([x[0].toPython() for x in query]):
BrickStore.relationships.append((uri, uri.split("#")[-1], ""))
@classmethod
def set_history_size(cls, size):
cls.history_size = size