Design Patterns#
This file contains the Turtle code supporting the set of design patterns presented in the User Documentation site, in the section titled “Modeling Design Patterns”
Source#
The model was created using TopQuadrant TopBraid Composer Maestro Edition.
Downloads#
Queries#
Model Components#
Parent Class |
Class |
Instances |
---|---|---|
6 |
||
5 |
||
4 |
||
4 |
||
2 |
||
1 |
||
12 |
||
21 |
||
19 |
||
5 |
||
6 |
||
4 |
||
4 |
||
3 |
Load and Validate Model#
This code uses the BuildingMOTIF library to load the 223P ontology and the model file into a temporary in-memory instance. It then validates the model against the ontology. If the model is invalid, it will print the validation report.
To run this code, you need to have Java installed on your system. If you do not have Java installed, you can remove the shacl_engine='topquadrant'
parameter from the BuildingMOTIF
constructor.
Be warned that without the shacl_engine='topquadrant'
parameter, the validation process will be slower.
Note
BuildingMOTIF installation
To install the buildingmotif
library, you can use the following command:
pip install 'buildingmotif[topquadrant] @ git+https://github.com/NREL/buildingmotif.git@develop'
If you do not have Java installed, you can use the following command to install the library:
pip install 'buildingmotif @ git+https://github.com/NREL/buildingmotif.git@develop'
from buildingmotif import BuildingMOTIF
from buildingmotif.dataclasses import Library, Model
import logging
# Create a BuildingMOTIF object. If you do not have Java installed, remove the "shacl_engine" parameter
bm = BuildingMOTIF('sqlite://', shacl_engine='topquadrant', log_level=logging.ERROR)
# load 223P library. We will load a recent copy from the models.open223.info
# git repository; later, we will load this from the location of the actual standard
s223 = Library.load(ontology_graph="https://github.com/open223/models.open223.info/raw/main/ontologies/223p.ttl")
# load the model into the BuildingMOTIF instance
model = Model.create("urn:design-patterns")
model.graph.parse("https://models.open223.info/design-patterns.ttl")
# validate the model against 223P ontology
ctx = model.validate([s223.get_shape_collection()], error_on_missing_imports=False)
# print the validation result
print(f"Model is valid: {ctx.valid}")
# if the model is invalid, print the validation report
if not ctx.valid:
print(ctx.report_string[:1000]) # first 1000 characters of the report
# BuildingMOTIF can also interpret the report to provide recommendations on fixes
for focus_node, diffs in ctx.get_reasons_with_severity("Violation").items():
if len(diffs) == 0:
continue
print(focus_node)
for diff in diffs:
print(" - " + diff.reason())
Model is valid: 0
@prefix ns3: <http://data.ashrae.org/standard223#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
[] a sh:ValidationReport ;
sh:conforms false ;
sh:result [ a sh:ValidationResult ;
sh:focusNode <http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Motor3InletCP> ;
sh:resultMessage "s223: A ConnectionPoint must be associated with exactly one Substance-Medium using the relation hasMedium." ;
sh:resultPath ns3:hasMedium ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape <urn:well-known/4c703953> ],
[ a sh:ValidationResult ;
sh:focusNode <http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Motor2InletCP> ;
sh:resultMessage "s223: A ConnectionPoint must be associated with exactly one Substance-Medium using the relation hasMedium." ;
sh:re
http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#BreakerOutletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#BreakerOutletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Circuit1
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Circuit1 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Constituent-Electricity on path http://data.ashrae.org/standard223#hasMedium
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Circuit1 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch1
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch1 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch1 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Constituent-Electricity on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#JunctionInletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#JunctionInletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Motor3InletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Motor3InletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#JunctionOutletCP1
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#JunctionOutletCP1 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Motor2InletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Motor2InletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario4#LightActuator
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario4#LightActuator needs between 1 and None instances of http://data.ashrae.org/standard223#ActuatableProperty on path http://data.ashrae.org/standard223#actuatedByProperty
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#JunctionOutletCP2
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#JunctionOutletCP2 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#JunctionOutletCP3
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#JunctionOutletCP3 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Junction
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Junction needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch2
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch2 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch2 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Constituent-Electricity on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Motor3InletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Motor3InletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Circuit1
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Circuit1 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Constituent-Electricity on path http://data.ashrae.org/standard223#hasMedium
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Circuit1 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#BreakerOutletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#BreakerOutletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Motor1InletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Motor1InletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Motor2InletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario7#Motor2InletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch3
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch3 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Constituent-Electricity on path http://data.ashrae.org/standard223#hasMedium
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#CircuitBranch3 needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Motor1InletCP
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario8#Motor1InletCP needs between 1 and 1 instances of http://data.ashrae.org/standard223#Substance-Medium on path http://data.ashrae.org/standard223#hasMedium
http://data.ashrae.org/standard223/1.0/data/patterns-scenario6#LightActuator
- http://data.ashrae.org/standard223/1.0/data/patterns-scenario6#LightActuator needs between 1 and None instances of http://data.ashrae.org/standard223#ActuatableProperty on path http://data.ashrae.org/standard223#actuatedByProperty