Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap "power" for "electrical" in complexity and flow shapes #425

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bricksrc/definitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ https://brickschema.org/schema/Brick#System_Status,Indicates properties of the a
https://brickschema.org/schema/Brick#TABS_Panel,See Thermally_Activated_Building_System_Panel,
https://brickschema.org/schema/Brick#TETRA_Room,"A room used for local two-way radio networks, e.g. the portable radios carried by facilities staff",
https://brickschema.org/schema/Brick#TVOC_Level_Sensor,A sensor measuring the level of all VOCs in air,
https://brickschema.org/schema/Brick#Tablet,"A flat, handheld mobile computer, usually with a touchscreen"
https://brickschema.org/schema/Brick#Tablet,"A flat, handheld mobile computer, usually with a touchscreen",
https://brickschema.org/schema/Brick#Tank,A container designed to hold or store fluids for various applications within a system.,
https://brickschema.org/schema/Brick#Team_Room,An office used by multiple team members for specific work tasks. Distinct from Conference Room,
https://brickschema.org/schema/Brick#Telecom_Room,A class of spaces used to support telecommuncations and IT equipment,
Expand Down
57 changes: 57 additions & 0 deletions bricksrc/deprecations.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@prefix bacnet: <http://data.ashrae.org/bacnet/2020#> .
@prefix brick: <https://brickschema.org/schema/Brick#> .
@prefix bsh: <https://brickschema.org/schema/BrickShape#> .
@prefix dcterms: <http://purl.org/dc/terms#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix qudt: <http://qudt.org/schema/qudt/> .
@prefix qudtqk: <http://qudt.org/vocab/quantitykind/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sdo: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix sosa: <http://www.w3.org/ns/sosa/> .
@prefix tag: <https://brickschema.org/schema/BrickTag#> .
@prefix unit: <http://qudt.org/vocab/unit/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# deprecations.ttl is reserved for non-class deprecations, e.g. entity properties

brick:powerComplexity brick:deprecation [
brick:deprecatedInVersion "1.3.1" ;
brick:deprecationMitigationMessage "powerComplexity is deprecated in favor of electricalComplexPower because the latter is more clear";
brick:deprecationMigitationRule [
a sh:NodeShape ;
sh:rule [
a sh:SPARQLRule ;
sh:construct """
CONSTRUCT {
$this brick:electricalComplexPower ?prop .
} WHERE {
$this brick:powerComplexity ?prop .
}""" ;
sh:prefixes brick: ;
] ;
sh:targetSubjectsOf brick:powerComplexity ;
] ;
] .

brick:powerFlow brick:deprecation [
brick:deprecatedInVersion "1.3.1" ;
brick:deprecationMitigationMessage "powerFlow is deprecated in favor of electricalFlow as the latter is more clear";
brick:deprecationMigitationRule [
a sh:NodeShape ;
sh:rule [
a sh:SPARQLRule ;
sh:construct """
CONSTRUCT {
$this brick:electricalFlow ?prop .
} WHERE {
$this brick:powerFlow ?prop .
}""" ;
sh:prefixes brick: ;
] ;
sh:targetSubjectsOf brick:powerFlow ;
] ;
] .
20 changes: 10 additions & 10 deletions bricksrc/entity_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@
"property_of": [BRICK.Equipment, BRICK.Location],
},
# electrical properties
BRICK.powerComplexity: {
SKOS.definition: Literal("Entity has this power complexity"),
SH.node: BSH.PowerComplexityShape,
RDFS.label: Literal("Power complexity"),
BRICK.electricalComplexPower: {
SKOS.definition: Literal("Associated electrical complexity with the entity"),
SH.node: BSH.ElectricalComplexPowerShape,
RDFS.label: Literal("electrical complex power type"),
"property_of": [BRICK.Equipment, BRICK.Point],
},
BRICK.powerFlow: {
BRICK.electricalFlow: {
SKOS.definition: Literal(
"Entity has this power flow relative to the building'"
"Entity has this electrical flow relative to the building'"
),
SH.node: BSH.PowerFlowShape,
RDFS.label: Literal("Power flow"),
SH.node: BSH.ElectricalFlowShape,
RDFS.label: Literal("Electrical flow direction"),
"property_of": [BRICK.Equipment, BRICK.Point],
},
BRICK.electricalPhases: {
Expand Down Expand Up @@ -448,8 +448,8 @@
},
},
BSH.VolumeShape: {"units": [UNIT.FT3, UNIT.M3], "datatype": BSH.NumericValue},
BSH.PowerComplexityShape: {"values": ["real", "reactive", "apparent"]},
BSH.PowerFlowShape: {"values": ["import", "export", "net", "absolute"]},
BSH.ElectricalComplexPowerShape: {"values": ["real", "reactive", "apparent"]},
BSH.ElectricalFlowShape: {"values": ["import", "export", "net", "absolute"]},
BSH.PhasesShape: {"values": ["A", "B", "C", "AB", "BC", "AC", "ABC"]},
BSH.PhaseCountShape: {"values": ["1", "2", "3", "Total"]},
BSH.CurrentFlowTypeShape: {"values": ["AC", "DC"]},
Expand Down
6 changes: 3 additions & 3 deletions examples/solar_array/solar_array.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ site:pv_meter a brick:Electrical_Meter ;
site:pv_daily_peak_power .

site:pv_power a brick:Electric_Power_Sensor ;
brick:powerFlow [ brick:value "export"^^xsd:string ] ;
brick:electricalFlow [ brick:value "export"^^xsd:string ] ;
brick:hasUnit unit:KiloW .

site:pv_energy a brick:Energy_Sensor ;
brick:powerFlow [ brick:value "export"^^xsd:string ] ;
brick:electricalFlow [ brick:value "export"^^xsd:string ] ;
brick:hasUnit unit:KiloW-HR .

site:pv_daily_peak_power a brick:Power_Sensor ;
brick:hasUnit unit:KiloW ;
brick:powerFlow [ brick:value "export"^^xsd:string ] ;
brick:electricalFlow [ brick:value "export"^^xsd:string ] ;
brick:aggregate [
brick:aggregationFunction "max" ;
brick:aggregationInterval "RP1D" ;
Expand Down
36 changes: 23 additions & 13 deletions generate_brick.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
from rdflib.namespace import XSD
from rdflib.collection import Collection

from bricksrc.ontology import define_ontology, ontology_imports, define_extension, BRICK_IRI_VERSION
from bricksrc.ontology import (
define_ontology,
ontology_imports,
define_extension,
BRICK_IRI_VERSION,
)


from bricksrc.namespaces import (
Expand Down Expand Up @@ -321,7 +326,9 @@ def define_classes(definitions, parent, pun_classes=False, graph=G):
graph.add((alias, OWL.equivalentClass, classname))
graph.add((alias, BRICK.aliasOf, classname))
if not has_label(alias, graph=graph):
graph.add((alias, RDFS.label, Literal(alias.split("#")[-1].replace("_", " "))))
graph.add(
(alias, RDFS.label, Literal(alias.split("#")[-1].replace("_", " ")))
)

# all other key-value pairs in the definition are
# property-object pairs
Expand Down Expand Up @@ -383,8 +390,8 @@ def define_entity_properties(definitions, superprop=None, graph=G):
assert (
"property_of" in defn
), f"{entprop} missing a 'property_of' annotation so Brick doesn't know where this property can be used"
assert (
_allowed_annotations.intersection(defn.keys())
assert _allowed_annotations.intersection(
defn.keys()
), f"{entprop} missing at least one of {_allowed_annotations} so Brick doesn't know what the values of this property can be"
assert RDFS.label in defn, f"{entprop} missing a RDFS.label annotation"
graph.add((entprop, A, BRICK.EntityProperty))
Expand Down Expand Up @@ -530,7 +537,9 @@ def define_shape_properties(definitions, graph=G):
vals = defn.pop("values")
if isinstance(vals[0], str):
Collection(
graph, enumeration, map(lambda x: Literal(x, datatype=XSD.string), vals)
graph,
enumeration,
map(lambda x: Literal(x, datatype=XSD.string), vals),
)
elif isinstance(vals[0], int):
Collection(
Expand Down Expand Up @@ -945,7 +954,10 @@ def handle_deprecations():

G.remove((BRICK.value, A, OWL.ObjectProperty))

# handle class deprecations
handle_deprecations()
# handle non-class deprecations
G.parse("bricksrc/deprecations.ttl")

logging.info("Adding class definitions")
add_definitions()
Expand Down Expand Up @@ -974,9 +986,7 @@ def handle_deprecations():
G.add((rule, SH.prefixes, BRICK_IRI_VERSION))

# remove ontology declarations
for ontology in G.subjects(
predicate=RDF.type, object=OWL.Ontology
):
for ontology in G.subjects(predicate=RDF.type, object=OWL.Ontology):
if ontology != BRICK_IRI_VERSION:
G.remove((ontology, RDF.type, OWL.Ontology))
G.remove((ontology, OWL.imports, None))
Expand All @@ -989,17 +999,17 @@ def handle_deprecations():
# TODO: add ontology definition
print(f"Reading in entity properties and/or class definitions from {filename}")
mod = importlib.import_module(filename)
if hasattr(mod, 'entity_properties'):
if hasattr(mod, "entity_properties"):
define_entity_properties(mod.entity_properties, graph=extension_graph)
if hasattr(mod, 'classes'):
if hasattr(mod, "classes"):
for parent, tree in mod.classes.items():
define_classes(tree, parent, graph=extension_graph)
if hasattr(mod, 'property_value_shapes'):
if hasattr(mod, "property_value_shapes"):
define_shape_properties(mod.property_value_shapes, graph=extension_graph)
if hasattr(mod, 'ontology_definition'):
if hasattr(mod, "ontology_definition"):
define_extension(extension_graph, mod.ontology_definition)

parts = Path('/'.join(filename.split('.')))
parts = Path("/".join(filename.split(".")))
dest = Path("extensions") / parts.with_suffix(".ttl")
os.makedirs(dest.parent, exist_ok=True)
print(f"Writing extension graph to {dest}")
Expand Down