Skip to content

Commit

Permalink
fix rec model, update other test
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Jan 31, 2024
1 parent 58a21a6 commit 0c09fb0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 67 deletions.
4 changes: 2 additions & 2 deletions examples/rec-with-brick/building.ttl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@prefix ex: <http://example.com#> .
@prefix rec: <https://w3id.org/rec/core/> .
@prefix brick: <https://brickschema.org/schema/1.1/Brick#> .
@prefix brick: <https://brickschema.org/schema/Brick#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

Expand Down Expand Up @@ -58,7 +58,7 @@ ex:AirTempSensor_RVAV1 a brick:Air_Temperature_Sensor ;
brick:isPointOf ex:RVAV1 .

ex:AirTempSetpoint_RVAV1 a brick:Temperature_Setpoint ;
brick:hasPoint ex:RVAV1 .
brick:isPointOf ex:RVAV1 .

ex:AirFlowSensor_RVAV1 a brick:Air_Flow_Sensor ;
brick:isPointOf ex:RVAV1 .
55 changes: 55 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Generates tests automatically
"""
import pytest
from rdflib import Namespace
import ontoenv
import brickschema
import glob
import sys

sys.path.append("..")
from bricksrc.namespaces import QUDT, RDF, RDFS, BRICK # noqa: E402
from bricksrc.namespaces import TAG, SKOS, A, OWL # noqa: E402


def pytest_generate_tests(metafunc):
Expand Down Expand Up @@ -41,3 +43,56 @@ def brick_with_imports():
g.bind("brick", BRICK)
env.import_dependencies(g)
return g


@pytest.fixture()
def simple_brick_model():
BLDG = Namespace("https://brickschema.org/schema/ExampleBuilding#")

g = brickschema.Graph()
g.load_file("Brick.ttl")
g.bind("rdf", RDF)
g.bind("owl", OWL)
g.bind("rdfs", RDFS)
g.bind("skos", SKOS)
g.bind("brick", BRICK)
g.bind("tag", TAG)
g.bind("bldg", BLDG)

# Create instances
g.add((BLDG.Coil_1, A, BRICK.Heating_Coil))
g.add((BLDG.AHU1, A, BRICK.Air_Handler_Unit))
g.add((BLDG.VAV1, A, BRICK.Variable_Air_Volume_Box))
g.add((BLDG.CH1, A, BRICK.Chiller))

# locations
g.add((BLDG.Zone1, A, BRICK.HVAC_Zone))
g.add((BLDG.Room1, A, BRICK.Room))
g.add((BLDG.Room2, A, BRICK.Room))

# points
g.add((BLDG.TS1, A, BRICK.Air_Temperature_Sensor))
g.add((BLDG.TS2, A, BRICK.Air_Temperature_Sensor))
g.add((BLDG.AFS1, A, BRICK.Air_Flow_Sensor))
g.add((BLDG.co2s1, A, BRICK.CO2_Level_Sensor))

g.add((BLDG.AFSP1, A, BRICK.Air_Flow_Setpoint))

g.add((BLDG.MAFS1, A, BRICK.Max_Air_Flow_Setpoint_Limit))

# establishing some relationships
g.add((BLDG.CH1, BRICK.feeds, BLDG.AHU1))
g.add((BLDG.AHU1, BRICK.feeds, BLDG.VAV1))
g.add((BLDG.VAV1, BRICK.hasPoint, BLDG.TS2))
g.add((BLDG.VAV1, BRICK.hasPoint, BLDG.AFS1))
g.add((BLDG.VAV1, BRICK.hasPoint, BLDG.AFSP1))

g.add((BLDG.VAV1, BRICK.feeds, BLDG.Zone1))
g.add((BLDG.Zone1, BRICK.hasPart, BLDG.Room1))
g.add((BLDG.Zone1, BRICK.hasPart, BLDG.Room2))

g.add((BLDG.TS1, BRICK.hasLocation, BLDG.Room1))

# lets us use both relationships
g.expand(profile="shacl")
return g
75 changes: 10 additions & 65 deletions tests/test_no_inference.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,10 @@
# Set of tests to demonstrate use of Brick *without* the use of a reasoner
import brickschema
from rdflib import RDF, RDFS, OWL, Namespace
from .util import make_readable
import sys

sys.path.append("..")
from bricksrc.namespaces import BRICK, TAG, SKOS, A # noqa: E402

BLDG = Namespace("https://brickschema.org/schema/ExampleBuilding#")

g = brickschema.Graph()
g.load_file("Brick.ttl")
g.bind("rdf", RDF)
g.bind("owl", OWL)
g.bind("rdfs", RDFS)
g.bind("skos", SKOS)
g.bind("brick", BRICK)
g.bind("tag", TAG)
g.bind("bldg", BLDG)

# Create instances
g.add((BLDG.Coil_1, A, BRICK.Heating_Coil))
g.add((BLDG.AHU1, A, BRICK.Air_Handler_Unit))
g.add((BLDG.VAV1, A, BRICK.Variable_Air_Volume_Box))
g.add((BLDG.CH1, A, BRICK.Chiller))

# locations
g.add((BLDG.Zone1, A, BRICK.HVAC_Zone))
g.add((BLDG.Room1, A, BRICK.Room))
g.add((BLDG.Room2, A, BRICK.Room))

# points
g.add((BLDG.TS1, A, BRICK.Air_Temperature_Sensor))
g.add((BLDG.TS2, A, BRICK.Air_Temperature_Sensor))
g.add((BLDG.AFS1, A, BRICK.Air_Flow_Sensor))
g.add((BLDG.co2s1, A, BRICK.CO2_Level_Sensor))

g.add((BLDG.AFSP1, A, BRICK.Air_Flow_Setpoint))

g.add((BLDG.MAFS1, A, BRICK.Max_Air_Flow_Setpoint_Limit))

# establishing some relationships
g.add((BLDG.CH1, BRICK.feeds, BLDG.AHU1))
g.add((BLDG.AHU1, BRICK.feeds, BLDG.VAV1))
g.add((BLDG.VAV1, BRICK.hasPoint, BLDG.TS2))
g.add((BLDG.VAV1, BRICK.hasPoint, BLDG.AFS1))
g.add((BLDG.VAV1, BRICK.hasPoint, BLDG.AFSP1))

g.add((BLDG.VAV1, BRICK.feeds, BLDG.Zone1))
g.add((BLDG.Zone1, BRICK.hasPart, BLDG.Room1))
g.add((BLDG.Zone1, BRICK.hasPart, BLDG.Room2))

g.add((BLDG.TS1, BRICK.hasLocation, BLDG.Room1))

# lets us use both relationships
g.expand(profile="shacl")


def test_query_equipment():
def test_query_equipment(simple_brick_model):
res = make_readable(
g.query(
simple_brick_model.query(
"""SELECT DISTINCT ?equip WHERE {
?equip rdf:type/rdfs:subClassOf* brick:Equipment .
}"""
Expand All @@ -68,9 +13,9 @@ def test_query_equipment():
assert len(res) == 4


def test_query_points():
def test_query_points(simple_brick_model):
res = make_readable(
g.query(
simple_brick_model.query(
"""SELECT DISTINCT ?point WHERE {
?point rdf:type/rdfs:subClassOf* brick:Point .
}"""
Expand All @@ -79,9 +24,9 @@ def test_query_points():
assert len(res) == 6


def test_query_sensors():
def test_query_sensors(simple_brick_model):
res = make_readable(
g.query(
simple_brick_model.query(
"""SELECT DISTINCT ?sensor WHERE {
?sensor rdf:type/rdfs:subClassOf* brick:Sensor .
}"""
Expand All @@ -90,10 +35,10 @@ def test_query_sensors():
assert len(res) == 4


def test_query_downstream_temperature():
def test_query_downstream_temperature(simple_brick_model):
# temp sensors downstream of AHU1
res = make_readable(
g.query(
simple_brick_model.query(
"""SELECT DISTINCT ?thing ?point WHERE {
bldg:AHU1 (brick:feeds|brick:hasPart)* ?thing .
?thing (brick:hasPoint|brick:isLocationOf) ?point .
Expand All @@ -104,10 +49,10 @@ def test_query_downstream_temperature():
assert len(res) == 2


def test_query_room_temp_sensors_ahu1():
def test_query_room_temp_sensors_ahu1(simple_brick_model):
# temp sensors downstream of AHU1
res = make_readable(
g.query(
simple_brick_model.query(
"""SELECT DISTINCT ?zone ?room ?sensor WHERE {
bldg:AHU1 brick:feeds+ ?zone .
?zone brick:hasPart ?room .
Expand Down
2 changes: 2 additions & 0 deletions tools/compare_versions/compare_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def get_root(version):
short_version = get_short_version(version)
if short_version == "1.3":
return "https://brickschema.org/schema/Brick#Class"
if short_version == "1.4":
return "https://brickschema.org/schema/Brick#Entity"
if semver.compare(version, "1.0.3") > 0: # if current version is newer than 1.0.3
return f"https://brickschema.org/schema/{short_version}/Brick#Class"
return f"https://brickschema.org/schema/{short_version}/BrickFrame#TagSet"
Expand Down

0 comments on commit 0c09fb0

Please sign in to comment.