Skip to content

Commit 044b683

Browse files
Add additional ontology imports (#501)
* fix/compare_versions_tool * add ref schema and REC imports * add brickpatches * fixing up location haspart constraints * updating REC * bump deps * working on rec/brick * fixing prefixes and rules * bump ontoenv * initialie quantities * Merging quantities * fixing use of ontoenv * fix ontoenv usage for tests * more rec changes --------- Co-authored-by: Filip Henrik Larsen <[email protected]>
1 parent db76a6e commit 044b683

File tree

13 files changed

+4562
-12
lines changed

13 files changed

+4562
-12
lines changed

bricksrc/location.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,10 @@
628628
},
629629
"constraints": {
630630
BRICK.hasPart: [
631-
BRICK.Room,
632631
BRICK.Space,
632+
BRICK.Wing,
633+
BRICK.Outdoor_Area,
634+
BRICK.Floor,
633635
],
634636
},
635637
},

bricksrc/namespaces.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
SOSA = Namespace("http://www.w3.org/ns/sosa/")
1616
VCARD = Namespace("http://www.w3.org/2006/vcard/ns#")
1717
S223 = Namespace("http://data.ashrae.org/standard223#")
18+
REC = Namespace("https://w3id.org/rec#")
1819

1920
# QUDT namespaces
2021
QUDT = Namespace("http://qudt.org/schema/qudt/")
@@ -52,3 +53,4 @@ def bind_prefixes(g):
5253
g.bind("bacnet", BACNET)
5354
g.bind("ifc", IFC)
5455
g.bind("s223", S223)
56+
g.bind("rec", REC)

bricksrc/ontology.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rdflib import Literal, BNode, URIRef
33
from rdflib.collection import Collection
44

5-
from .namespaces import DCTERMS, SDO, RDFS, RDF, OWL, BRICK, SH, XSD, REF
5+
from .namespaces import DCTERMS, SDO, RDFS, RDF, OWL, BRICK, SH, XSD, REF, REC
66
from .version import BRICK_VERSION, BRICK_FULL_VERSION
77

88
# defines metadata about the Brick ontology
@@ -38,11 +38,14 @@
3838
"qudtoverlay": "http://qudt.org/2.1/schema/shacl/overlay/qudt",
3939
"unit": "http://qudt.org/2.1/vocab/unit",
4040
"bacnet": "http://data.ashrae.org/bacnet/2020",
41+
"ref": "https://brickschema.org/schema/Brick/ref",
42+
"rec": "https://w3id.org/rec",
43+
"recimports": "https://w3id.org/rec/recimports",
44+
"brickpatches": "https://w3id.org/rec/brickpatches",
4145
"quantitykind": "http://qudt.org/2.1/vocab/quantitykind",
4246
"qudtsou": "http://qudt.org/2.1/vocab/sou",
4347
"qudtdv": "http://qudt.org/2.1/vocab/dimensionvector",
4448
"qudtprefix": "http://qudt.org/2.1/vocab/prefix",
45-
"ref": "https://brickschema.org/schema/Brick/ref",
4649
}
4750

4851
shacl_namespace_declarations = [
@@ -76,6 +79,10 @@
7679
SH.namespace: Literal(str(REF), datatype=XSD.anyURI),
7780
SH.prefix: Literal("ref"),
7881
},
82+
{
83+
SH.namespace: Literal("https://w3id.org/rec#", datatype=XSD.anyURI),
84+
SH.prefix: Literal("rec"),
85+
},
7986
]
8087

8188
BRICK_IRI_VERSION = URIRef(f"https://brickschema.org/schema/{BRICK_VERSION}/Brick")

bricksrc/quantities.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from brickschema.graph import Graph
2+
from ontoenv import OntoEnv
23
from rdflib import Literal, URIRef
34
from .namespaces import SKOS, OWL, RDFS, BRICK, QUDTQK, QUDTDV, QUDT, UNIT
45

5-
6+
env = OntoEnv(initialize=True, search_dirs=["support/"])
67
g = Graph()
78
g.load_file("support/VOCAB_QUDT-QUANTITY-KINDS-ALL-v2.1.ttl")
89
g.load_file("support/VOCAB_QUDT-UNITS-ALL-v2.1.ttl")
910
g.bind("qudt", QUDT)
1011
g.bind("qudtqk", QUDTQK)
11-
g.expand(profile="shacl", backend="topquadrant")
12+
13+
env.import_dependencies(g)
14+
g.expand("shacl", backend="topquadrant")
1215

1316

1417
def get_units(qudt_quantity):

bricksrc/rules.ttl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,34 @@ bsh:hasSubstance a sh:NodeShape ;
444444
.
445445

446446

447+
# rule to add rec:includes when a brick:Collection contains a brick:Equipment
448+
bsh:CollectionIncludesEquipment a sh:NodeShape ;
449+
sh:targetClass brick:Collection, brick:System, brick:Equipment ;
450+
sh:rule [
451+
a sh:SPARQLRule ;
452+
sh:construct """
453+
CONSTRUCT {
454+
$this rec:includes ?eq .
455+
}
456+
WHERE {
457+
$this brick:hasPart ?eq .
458+
{
459+
?eq rdf:type/rdfs:subClassOf* brick:Equipment .
460+
}
461+
UNION
462+
{
463+
?eq rdf:type/rdfs:subClassOf* brick:Collection .
464+
}
465+
UNION
466+
{
467+
?eq rdf:type/rdfs:subClassOf* brick:System .
468+
}
469+
}
470+
""" ;
471+
sh:prefixes <https://brickschema.org/schema/1.3/Brick> ;
472+
] ;
473+
.
474+
447475
# add unidirectional charging to all EVsE chargers as a default value
448476
# UNLESS there is already a brick:electricVehicleChargerDirectionality attribute
449477
# on ports associated with the charger

examples/last_known_value/last_known_value.ttl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@prefix unit: <http://qudt.org/vocab/unit/> .
55
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
66
@prefix bacnet: <http://data.ashrae.org/bacnet/2020#> .
7+
@prefix rec: <https://w3id.org/rec#> .
78
@prefix owl: <http://www.w3.org/2002/07/owl#> .
89

910
bldg: a owl:Ontology ;
@@ -20,8 +21,9 @@ bldg:sensor1 a brick:Air_Temperature_Sensor ;
2021
bacnet:object-name "BLDG-Z410-ZATS" ;
2122
bacnet:objectOf bldg:sample-device ;
2223
] ;
23-
brick:lastKnownValue [
24-
brick:value "72.0"^^xsd:float ;
24+
brick:lastKnownValue bldg:sensor1_reading1 .
25+
26+
bldg:sensor1_reading1 a rec:TemperatureObservation ;
27+
brick:value "72.0"^^xsd:double ;
2528
brick:timestamp "2020-01-01T00:00:00Z"^^xsd:dateTime ;
26-
] ;
27-
.
29+
rec:sourcePoint bldg:sensor1 .

examples/solar_array/solar_array.ttl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
@prefix brick: <https://brickschema.org/schema/Brick#> .
33
@prefix unit: <http://qudt.org/vocab/unit/> .
44
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
5+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
6+
7+
<urn:example> a owl:Ontology ;
8+
owl:imports <https://brickschema.org/schema/1.3/Brick> .
59

610
# shared efficiency rating
711
site:panel_efficiency a brick:EfficiencyShape ;

generate_brick.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ def handle_deprecations():
10891089

10901090
# create new directory for storing imports
10911091
os.makedirs("imports", exist_ok=True)
1092-
env = ontoenv.OntoEnv(initialize=True)
1092+
env = ontoenv.OntoEnv(initialize=True, search_dirs=["support/"])
10931093
for name, uri in ontology_imports.items():
10941094
depg, loc = env.resolve_uri(str(uri))
10951095
depg.serialize(Path("imports") / f"{name}.ttl", format="ttl")
@@ -1100,3 +1100,9 @@ def handle_deprecations():
11001100
if not valid:
11011101
print(report)
11021102
sys.exit(1)
1103+
1104+
# validate Brick
1105+
# valid, _, report = pyshacl.validate(data_graph=G, advanced=True, allow_warnings=True)
1106+
# if not valid:
1107+
# print(report)
1108+
# sys.exit(1)

support/SCHEMA_QUDT_NoOWL-v2.1.ttl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ qudt:QuantityType-value
17611761
qudt:QuantityValue
17621762
a rdfs:Class ;
17631763
a sh:NodeShape ;
1764-
rdfs:comment "A <i>Quantity Value</i> expresses the magnitude and kind of a quantity and is given by the product of a numerical value <code>n</code> and a unit of measure <code>U</code>. The number multiplying the unit is referred to as the numerical value of the quantity expressed in that unit. Refer to <a href=\"http://physics.nist.gov/Pubs/SP811/sec07.html\">NIST SP 811 section 7</a> for more on quantity values."^^rdf:HTML ;
1764+
rdfs:comment ""^^rdf:HTML ;
17651765
rdfs:isDefinedBy <http://qudt.org/2.1/schema/shacl/qudt> ;
17661766
rdfs:label "Quantity value" ;
17671767
rdfs:subClassOf qudt:Concept ;

0 commit comments

Comments
 (0)