A library for working with the Brick ontology for buildings (brickschema.org)
Project description
Brick Ontology Python package
Documentation available at readthedocs
Installation
The brickschema
package requires Python >= 3.6. It can be installed with pip
:
pip install brickschema
The brickschema
package offers several installation configuration options for reasoning.
The default bundled OWLRL reasoner delivers correct results, but exhibits poor performance on large or complex ontologies (we have observed minutes to hours) due to its bruteforce implementation.
The Allegro reasoner has better performance and implements enough of the OWLRL profile to be useful. We execute Allegrograph in a Docker container, which requires the docker
package. To install support for the Allegrograph reasoner, use
pip install brickschema[allegro]
The reasonable Reasoner offers even better performance than the Allegro reasoner, but is currently only packaged for Linux platforms. (Note: no fundamental limitations here, just some packaging complexity due to cross-compiling the .so
). To install support for the reasonable Reasoner, use
pip install brickschema[reasonable]
OWLRL Inference
brickschema
makes it easier to employ OWLRL reasoning on your graphs. The package will automatically use the fastest available reasoning implementation for your system:
reasonable
(fastest, Linux-only for now):pip install brickschema[reasonable]
Allegro
(next-fastest, requires Docker):pip install brickschema[allegro]
- OWLRL (default, native Python implementation):
pip install brickschema
To use OWL inference, import the OWLRLInferenceSession
class (this automatically chooses the fastest reasoner; check out the inference module documentation for how to use a specific reasoner). Create a brickschema.Graph
with your ontology rules and instances loaded in and apply the reasoner's session to it:
from brickschema.graph import Graph
from brickschema.namespaces import BRICK
from brickschema.inference import OWLRLInferenceSession
g = Graph(load_brick=True)
g.load_file("test.ttl")
sess = OWLRLInferenceSession()
inferred_graph = sess.expand(g)
print(f"Inferred graph has {len(inferred_graph)} triples")
Haystack Inference
Requires a JSON export of a Haystack model.
First, export your Haystack model as JSON; we are using the public reference model carytown.json
.
Then you can use this package as follows:
import json
from brickschema.inference import HaystackInferenceSession
haysess = HaystackInferenceSession("http://project-haystack.org/carytown#")
model = json.load(open('carytown.json'))
model = haysess.infer_model(model)
print(len(model))
points = model.query("""SELECT ?point ?type WHERE {
?point rdf:type/rdfs:subClassOf* brick:Point .
?point rdf:type ?type
}""")
print(points)
SQL ORM
from brickschema.graph import Graph
from brickschema.namespaces import BRICK
from brickschema.orm import SQLORM, Location, Equipment, Point
# loads in default Brick ontology
g = Graph(load_brick=True)
# load in our model
g.load_file("test.ttl")
# put the ORM in a SQLite database file called "brick_test.db"
orm = SQLORM(g, connection_string="sqlite:///brick_test.db")
# get the points for each equipment
for equip in orm.session.query(Equipment):
print(f"Equpiment {equip.name} is a {equip.type} with {len(equip.points)} points")
for point in equip.points:
print(f" Point {point.name} has type {point.type}")
# filter for a given name or type
hvac_zones = orm.session.query(Location)\
.filter(Location.type==BRICK.HVAC_Zone)\
.all()
print(f"Model has {len(hvac_zones)} HVAC Zones")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for brickschema-0.1.2a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0edc406cb8c80d2a771b7665c25f5942732ffa319c0f1cf54689fdfcf6842de7 |
|
MD5 | d4679ad814e8b6bc27d177c8ad4f7a21 |
|
BLAKE2b-256 | f203cc8c35b95554d610229b0f744cdec4d0933b027eda4fb9e32da19a1cda8c |