Skip to content

Instantly share code, notes, and snippets.

@gtfierro
Created July 24, 2020 17:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtfierro/aa5874ab049b89a3387d4fc559491beb to your computer and use it in GitHub Desktop.
Save gtfierro/aa5874ab049b89a3387d4fc559491beb to your computer and use it in GitHub Desktop.
@prefix apt: <apartment#> .
@prefix brick: <https://brickschema.org/schema/1.1/Brick#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
apt:bedroom a brick:Room ;
brick:isPartOf apt:bedroom_lighting,
apt:my_apartment,
apt:thermostat_zone .
apt:kitchen a brick:Room ;
brick:isPartOf apt:kitchen_lighting,
apt:my_apartment,
apt:thermostat_zone .
apt:living_room a brick:Room ;
brick:isPartOf apt:living_room_lighting,
apt:my_apartment,
apt:thermostat_zone .
apt:bedroom_lighting a brick:Lighting_Zone .
apt:kitchen_lighting a brick:Lighting_Zone .
apt:living_room_lighting a brick:Lighting_Zone .
brick:Apartment rdfs:subClassOf brick:Space .
apt:my_apartment a brick:Apartment .
apt:thermostat_zone a brick:HVAC_Zone .
from rdflib import Namespace, Graph
from brickschema.namespaces import BRICK, RDF, RDFS, A
"""
Define the graph that will hold all of the triples defining the apartment.
We define the 'apt' namespace to identify the entities that are part of the
apartment graph vs the entities/concepts that are part of Brick
"""
g = Graph()
APT = Namespace("apartment#")
g.bind("apt", APT)
g.bind("brick", BRICK)
g.bind("rdf", RDF)
g.bind("rdfs", RDFS)
"""
Brick doesn't currently have the notion of an Apartment yet, so we can define
it as a special kind of Space.
Create "my_apartment" as an instance of this new class.
"""
g.add((BRICK["Apartment"], RDFS.subClassOf, BRICK["Space"]))
g.add((APT["my_apartment"], A, BRICK["Apartment"]))
"""
Define the spatial elements of the apartment:
- 3 rooms (bedroom, kitchen, living room)
- 1 HVAC zone (all 3 rooms)
- 3 Lighting zones (1 per room)
"""
g.add((APT["thermostat_zone"], A, BRICK["HVAC_Zone"]))
g.add((APT["bedroom_lighting"], A, BRICK["Lighting_Zone"]))
g.add((APT["kitchen_lighting"], A, BRICK["Lighting_Zone"]))
g.add((APT["living_room_lighting"], A, BRICK["Lighting_Zone"]))
g.add((APT["bedroom"], A, BRICK["Room"]))
g.add((APT["bedroom"], BRICK.isPartOf, APT["my_apartment"]))
g.add((APT["bedroom"], BRICK.isPartOf, APT["thermostat_zone"]))
g.add((APT["bedroom"], BRICK.isPartOf, APT["bedroom_lighting"]))
g.add((APT["kitchen"], A, BRICK["Room"]))
g.add((APT["kitchen"], BRICK.isPartOf, APT["my_apartment"]))
g.add((APT["kitchen"], BRICK.isPartOf, APT["thermostat_zone"]))
g.add((APT["kitchen"], BRICK.isPartOf, APT["kitchen_lighting"]))
g.add((APT["living_room"], A, BRICK["Room"]))
g.add((APT["living_room"], BRICK.isPartOf, APT["my_apartment"]))
g.add((APT["living_room"], BRICK.isPartOf, APT["thermostat_zone"]))
g.add((APT["living_room"], BRICK.isPartOf, APT["living_room_lighting"]))
g.serialize("apartment.ttl", format="ttl")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment