brickschema package¶
Subpackages¶
Submodules¶
brickschema.graph module¶
The graph module provides a wrapper class + convenience methods for building and querying a Brick graph
-
class
brickschema.graph.
Graph
(*args, load_brick=False, load_brick_nightly=False, brick_version='1.2', **kwargs)[source]¶ Bases:
rdflib.graph.Graph
-
add
(*triples)[source]¶ Adds triples to the graph. Triples should be 3-tuples of rdflib.Nodes
If the last item of a triple is a list/tuple of length-2 lists/tuples, then this method will substitute a blank node as the object of the original triple, add the new triples, and add as many triples as length-2 items in the list with the blank node as the subject and the item[0] and item[1] as the predicate and object, respectively.
For example, calling add((X, Y, [(A,B), (C,D)])) produces the following triples:
X Y _b1 . _b1 A B . _b1 C D .
or, in turtle:
- X Y [
A B ; C D ;
] .
-
expand
(profile=None, backend=None, simplify=True)[source]¶ Expands the current graph with the inferred triples under the given entailment regime and with the given backend. Possible profiles are: - ‘rdfs’: runs RDFS rules - ‘owlrl’: runs full OWLRL reasoning - ‘vbis’: adds VBIS tags - ‘shacl’: does SHACL-AF reasoning (including tag inference, if the extension is loaded)
Possible backends are: - ‘reasonable’: default, fastest backend - ‘allegrograph’: uses Docker to interface with allegrograph - ‘owlrl’: native-Python implementation
Not all backend work with all profiles. In that case, brickschema will use the fastest appropriate backend in order to perform the requested inference.
To perform more than one kind of inference in sequence, use ‘+’ to join the profiles:
import brickschema g = brickschema.Graph() g.expand(profile=’rdfs+shacl’) # performs RDFS inference, then SHACL-AF inference g.expand(profile=’shacl+rdfs’) # performs SHACL-AF inference, then RDFS inference
# TODO: currently nothing is cached between expansions
-
from_haystack
(namespace, model)[source]¶ Adds to the graph the Brick triples inferred from the given Haystack model. The model should be a Python dictionary produced from the Haystack JSON export
- Parameters
model (dict) – a Haystack model
-
from_triples
(triples)[source]¶ Creates a graph from the given list of triples
- Parameters
triples (list of rdflib.Node) – triples to add to the graph
-
get_alignments
()[source]¶ Returns a list of Brick alignments
This currently just lists the alignments already loaded into brickschema, but may in the future pull a list of alignments off of an online resolver
-
get_extensions
()[source]¶ Returns a list of Brick extensions
This currently just lists the extensions already loaded into brickschema, but may in the future pull a list of extensions off of an online resolver
-
get_most_specific_class
(classlist)[source]¶ Given a list of classes (rdflib.URIRefs), return the ‘most specific’ classes This is a subset of the provided list, containing classes that are not subclasses of anything else in the list. Uses the class definitions in the graph to perform this task
- Parameters
classlist (list of rdflib.URIRef) – list of classes
- Returns
list of specific classes
- Return type
classlist (list of rdflib.URIRef)
-
load_alignment
(alignment_name)[source]¶ Loads the given alignment into the current graph by name. Use get_alignments() to get a list of alignments
-
load_extension
(extension_name)[source]¶ Loads the given extension into the current graph by name. Use get_extensions() to get a list of extensions
-
load_file
(filename=None, source=None)[source]¶ Imports the triples contained in the indicated file into the graph
- Parameters
filename (str) – relative or absolute path to the file
source (file) – file-like object
-
property
nodes
¶ Returns all nodes in the graph
- Returns
nodes in the graph
- Return type
nodes (list of rdflib.URIRef)
-
rebuild_tag_lookup
(brick_file=None)[source]¶ Rebuilds the internal tag lookup dictionary used for Brick tag->class inference. This is broken out as its own method because it is potentially an expensive operation.
-
serve
(address='127.0.0.1:8080')[source]¶ Start web server offering SPARQL queries and 1-click reasoning capabilities
- Parameters
address (str) – <host>:<port> of the web server
-
simplify
()[source]¶ Removes redundant and axiomatic triples and other detritus that is produced as a side effect of reasoning. Simplification consists of the following steps: - remove all “a owl:Thing”, “a owl:Nothing” triples - remove all “a <blank node” triples - remove all “X owl:sameAs Y” triples
-
validate
(shape_graphs=None, default_brick_shapes=True)[source]¶ Validates the graph using the shapes embedded w/n the graph. Optionally loads in normative Brick shapes and externally defined shapes
- Parameters
shape_graphs (list of rdflib.Graph or brickschema.graph.Graph) – merges these graphs and includes them in the validation
default_brick_shapes (bool) – if True, loads in the default Brick shapes packaged with brickschema
- Returns
(conforms, resultsGraph, resultsText) from pyshacl
-
brickschema.inference module¶
-
class
brickschema.inference.
HaystackInferenceSession
(namespace)[source]¶ Bases:
brickschema.inference.TagInferenceSession
Wraps TagInferenceSession to provide inference of a Brick model from a Haystack model. The haystack model is expected to be encoded as a dictionary with the keys “cols” and “rows”; I believe this is a standard Haystack JSON export.
-
infer_entity
(tagset, identifier=None, equip_ref=None)[source]¶ Produces the Brick triples representing the given Haystack tag set
- Parameters
tagset (list of str) – a list of tags representing a Haystack entity
equip_ref (str) – reference to an equipment if one exists
- Keyword Arguments
identifier (str) – if provided, use this identifier for the entity,
generate a random string. (otherwise,) –
-
infer_model
(model)[source]¶ Produces the inferred Brick model from the given Haystack model :param model: a Haystack model :type model: dict
- Returns
- a Graph object containing the
inferred triples in addition to the regular graph
- Return type
graph (brickschema.graph.Graph)
-
-
class
brickschema.inference.
OWLRLAllegroInferenceSession
[source]¶ Bases:
object
Provides methods and an inferface for producing the deductive closure of a graph under OWL-RL semantics. WARNING this may take a long time
Uses the Allegrograph reasoning implementation
-
expand
(graph)[source]¶ Applies OWLRL reasoning from the Python owlrl library to the graph
- Parameters
graph (brickschema.graph.Graph) – a Graph object containing triples
-
-
class
brickschema.inference.
OWLRLNaiveInferenceSession
[source]¶ Bases:
object
Provides methods and an inferface for producing the deductive closure of a graph under OWL-RL semantics. WARNING this may take a long time
-
expand
(graph)[source]¶ Applies OWLRL reasoning from the Python owlrl library to the graph
- Parameters
graph (brickschema.graph.Graph) – a Graph object containing triples
-
-
class
brickschema.inference.
OWLRLReasonableInferenceSession
[source]¶ Bases:
object
Provides methods and an inferface for producing the deductive closure of a graph under OWL-RL semantics. WARNING this may take a long time
-
expand
(graph)[source]¶ Applies OWLRL reasoning from the Python reasonable library to the graph
- Parameters
graph (brickschema.graph.Graph) – a Graph object containing triples
-
-
class
brickschema.inference.
TagInferenceSession
(load_brick=True, brick_version='1.2', rebuild_tag_lookup=False, approximate=False, brick_file=None)[source]¶ Bases:
object
Provides methods and an interface for inferring Brick classes from sets of Brick tags. If you want to work with non-Brick tags, you will need to use a wrapper class (see HaystackInferenceSession)
-
expand
(graph)[source]¶ Infers the Brick class for entities with tags; tags are indicated by the brick:hasTag relationship. :param graph: a Graph object containing triples :type graph: brickschema.graph.Graph
Returns the Brick classes and tagsets that are supersets OR subsets of the given tagsets
- Parameters
tagset (list of str) – a list of tags
Returns the list of likely classes for a given set of tags, as well as the list of tags that were ‘leftover’, i.e. not used in the inference of a class
- Parameters
tagset (list of str) – a list of tags
num (int) – number of likely tagsets to be returned; -1 returns all
- Returns
a 2-element tuple containing (1) most_likely_classes (list of str): list of Brick classes and (2) leftover (set of str): list of tags not used
- Return type
results (tuple)
-
-
class
brickschema.inference.
VBISTagInferenceSession
(alignment_file=None, master_list_file=None, brick_version='1.2')[source]¶ Bases:
object
Add appropriate VBIS tag annotations to the entities inside the provided Brick model
Algorithm: - get all Equipment entities in the Brick model (VBIs currently only deals w/ equip)
- Parameters
alignment_file (str) – use the given Brick/VBIS alignment file. Defaults to a pre-packaged version.
master_list_file (str) – use the given VBIS tag master list. Defaults to a pre-packaged version.
brick_version (string) – the MAJOR.MINOR version of the Brick ontology to load into the graph. Only takes effect for the load_brick argument
- Returns
A VBISTagInferenceSession object
-
expand
(graph)[source]¶ - Parameters
graph (brickschema.graph.Graph) – a Graph object containing triples
-
lookup_brick_class
(vbistag)[source]¶ Returns all Brick classes that are appropriate for the given VBIS tag
- Parameters
vbistag (str) – the VBIS tag that we want to retrieve Brick classes for. Pattern search is not supported yet
- Returns
list of the Brick classes that match the VBIS tag
- Return type
brick_classes (list of rdflib.URIRef)
brickschema.namespaces module¶
The namespaces module provides pointers to standard Brick namespaces and related ontology namespaces wrapper class and convenience methods for a Brick graph
brickschema.orm module¶
ORM for Brick
-
class
brickschema.orm.
Equipment
(**kwargs)[source]¶ Bases:
sqlalchemy.orm.decl_api.Base
SQLAlchemy ORM class for BRICK.Equipment; see SQLORM class for usage
-
location
¶
-
location_id
¶
-
name
¶
-
points
¶
-
type
¶
-
-
class
brickschema.orm.
Location
(**kwargs)[source]¶ Bases:
sqlalchemy.orm.decl_api.Base
SQLAlchemy ORM class for BRICK.Location; see SQLORM class for usage
-
equipment
¶
-
name
¶
-
points
¶
-
type
¶
-
brickschema.tagmap module¶
-
brickschema.tagmap.
tagmap
= {'active': ['real'], 'ahu': ['AHU'], 'airhandlingequip': ['AHU'], 'airterminalunit': ['terminal', 'unit'], 'apparent': ['power'], 'atmospheric': ['pressure'], 'avg': ['average'], 'barometric': ['pressure'], 'chillermechanismtype': ['chiller'], 'cmd': ['command'], 'co': ['CO'], 'co2': ['CO2'], 'condenserlooptype': ['condenser'], 'cooling': ['cool'], 'coolingcoil': ['cool', 'coil', 'equip'], 'coolingonly': ['cool'], 'coolingtower': ['cool', 'tower', 'equip'], 'delta': ['differential'], 'device': ['equip'], 'economizing': ['economizer'], 'elec': ['electrical'], 'elecheat': ['heat'], 'equip': ['equipment'], 'evaporator': ['evaporative'], 'fcu': ['FCU'], 'freq': ['frequency'], 'fueloil': ['fuel', 'oil'], 'fueloilheating': ['heat'], 'fumehood': ['fume', 'hood'], 'heatexchanger': ['heat', 'exchanger', 'equip'], 'heating': ['heat'], 'heatingcoil': ['heat', 'coil', 'equip'], 'heatpump': ['heat', 'exchanger', 'equip'], 'heatwheel': ['heat', 'wheel'], 'hvac': ['HVAC'], 'lighting': ['lighting', 'equip'], 'lights': ['lighting'], 'lightsgroup': ['lighting'], 'luminous': ['luminance'], 'meterscopetype': ['meter', 'equip'], 'mixing': ['mixed'], 'naturalgas': ['natural', 'gas'], 'occ': ['occupied'], 'precipitation': ['rain'], 'roof': ['rooftop'], 'rooftop': ['rooftop'], 'rotaryscrew': ['compressor'], 'rtu': ['RTU'], 'sitemeter': ['meter', 'equip'], 'sp': ['setpoint'], 'state': ['status'], 'steamheating': ['heat'], 'submeter': ['meter', 'equip'], 'temp': ['temperature'], 'unocc': ['unoccupied'], 'variableairvolume': ['vav'], 'vav': ['VAV'], 'volt': ['voltage']}¶ # get values for:
ahuZoneDeliveryType AHU airCooling Air airVolumeAdjustabilityType Air chilledBeam Chilled chilledBeamZone Chilled chilledWaterCooling Chilled chillerMechanismType Chiller condenserClosedLoop Condenser condenserCooling Condenser condenserLoopType Condenser condenserOpenLoop Condenser diverting Direction
brickschema.validate module¶
The validate module implements a wrapper of pySHACL to validate an ontology graph against the default Brick Schema constraints (called shapes) and user-defined shapes.
-
class
brickschema.validate.
Validator
(useBrickSchema=True, useDefaultShapes=True, brick_version='1.2')[source]¶ Bases:
object
Validates a data graph against Brick Schema and basic SHACL constraints for Brick. Allows extra constraints specific to the user’s ontology.
-
class
Result
(conforms, violationGraphs, textOutput)[source]¶ Bases:
object
The type of returned object by validate() method
-
validate
(data_graph, shacl_graphs=[], ont_graphs=[], inference='rdfs', abort_on_error=False, advanced=True, meta_shacl=True, debug=False)[source]¶ Validates data_graph against shacl_graph and ont_graph.
- Parameters
shacl_graphs – extra shape graphs in additon to BrickShape.ttl
ont_graphs – extra ontology graphs in addtion to Brick.ttl
- Returns
object of Result class (conforms, violationGraphs, textOutput)
-
class
brickschema.web module¶
Brickschema web module. This embeds a Flask webserver which provides a local web server with: - SPARQL interpreter + query result visualization - buttons to perform inference
TODO: - implement https://www.w3.org/TR/sparql11-protocol/ on /query
Module contents¶
Python package brickschema provides a set of tools, utilities and interfaces for working with, developing and interacting with Brick models.