brickschema package

Subpackages

Submodules

brickschema.bacnet module

brickschema.bacnet.clean_name(name)[source]
brickschema.bacnet.scan(ns: rdflib.namespace.Namespace = Namespace('urn:bacnet-scan/'), ip: Optional[str] = None) brickschema.graph.Graph[source]

Scan for BACnet devices on the provided network. If no network is provided, use the default scan logic which scans all available interfaces. Provide a network by indicating the IP address that BAC0 should bind to

The Optional ‘ns’ parameter provides a namespace for the graph containing the scanned results.

brickschema.graph module

The graph module provides a wrapper class + convenience methods for building and querying a Brick graph

class brickschema.graph.BrickBase(store: Union[Store, str] = 'default', identifier: Optional[Union[_ContextIdentifierType, str]] = None, namespace_manager: Optional[NamespaceManager] = None, base: Optional[str] = None, bind_namespaces: _NamespaceSetString = 'rdflib')[source]

Bases: rdflib.graph.Graph

expand(profile, backend=None, simplify=True, ontology_graph=None, iterative=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

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: List[rdflib.term.URIRef])[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)

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', ignore_prefixes=[])[source]

Start web server offering SPARQL queries and 1-click reasoning capabilities

Parameters
  • address (str) – <host>:<port> of the web server

  • ignore_prefixes (list[str]) – list of prefixes not to be added to the query editor’s namespace bindings.

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

to_networkx()[source]

Exports the graph as a NetworkX DiGraph. Edge labels are stored in the ‘name’ attribute :returns: networkx object representing this graph :rtype: graph (networkx.DiGraph)

validate(shape_graphs=None, default_brick_shapes=True, engine: str = 'pyshacl')[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

  • engine (str) – the SHACL engine to use. Options are ‘pyshacl’ and ‘topquadrant’. Defaults to ‘pyshacl’

Returns

(conforms, resultsGraph, resultsText) from pyshacl

class brickschema.graph.Graph(*args, load_brick=False, load_brick_nightly=False, brick_version='1.3', _delay_init=False, **kwargs)[source]

Bases: brickschema.graph.BrickBase

add(*triples)[source]

Adds triples to the graph. Triples should be 3-tuples of rdflib.Nodes (or alternatively 4-tuples if each triple has a context).

If the object 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 ;
] .

Otherwise, acts the same as rdflib.Graph.add

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

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, format=None)[source]

Imports the triples contained in the indicated file into the default 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)

class brickschema.graph.GraphCollection(*args, load_brick=False, load_brick_nightly=False, brick_version='1.3', **kwargs)[source]

Bases: rdflib.graph.Dataset, brickschema.graph.BrickBase

contexts(triple=None)[source]

Iterate over all contexts in the graph

If triple is specified, iterate over all contexts the triple is in.

property graph_names

Returns a list of the names of the graphs in the graph store

Returns

list of graph names

Return type

list

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_graph(filename: Optional[str] = None, source: Optional[io.IOBase] = None, format: Optional[str] = None, graph: Optional[rdflib.graph.Graph] = None, graph_name: Optional[rdflib.term.URIRef] = None)[source]

Imports the triples contained in the indicated file (or graph) into the graph. Names the graph using any owl:Ontology declaration found in the file or using the ‘graph_name’ argument if it is provided

Parameters
  • filename (str) – relative or absolute path to the file

  • source (file) – file-like object

  • graph (brickschema.Graph) – graph to load into the collection

  • graph_name (rdflib.URIRef) – name of the graph (defaults to owl:Ontology instance or ‘default’)

Returns

the graph loaded from parsing the input

Return type

parsed (rdflib.Graph)

remove_graph(graph_name)[source]

Removes the named graph from the graph store

Parameters

graph_name (str) – name of the graph to remove

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,

  • string. (otherwise, generate a random) –

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.3', 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

lookup_tagset(tagset)[source]

Returns the Brick classes and tagsets that are supersets OR subsets of the given tagsets

Parameters

tagset (list of str) – a list of tags

most_likely_tagsets(orig_s, num=- 1)[source]

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.3')[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.merge module

The merge module implements data integration methods for merging Brick graphs together. This is based on techniques described in ‘Shepherding Metadata Through the Building Lifecycle’ published in BuildSys 2020

brickschema.merge.cluster_by_type(g1, g2, namespace)[source]
brickschema.merge.console_label(deduper: dedupe.api.ActiveMatching) None[source]

Train a matcher instance (Dedupe, RecordLink, or Gazetteer) from the command line. Example

> deduper = dedupe.Dedupe(variables)
> deduper.prepare_training(data)
> dedupe.console_label(deduper)
brickschema.merge.flatten_features(features)[source]
brickschema.merge.get_common_types(g1, g2, namespace)[source]

Returns the list of types that are common to both graphs. A type is included if both graphs have instances of that type

brickschema.merge.get_entity_feature_vectors(g, namespace)[source]

Returns a dictionary of features for each entity in graph ‘g’.

Entities are any node with at least one rdf:type edge that is in the given namespace.

brickschema.merge.merge_type_cluster(g1, g2, namespace, similarity_threshold=0.9, merge_types=None)[source]
brickschema.merge.unify_entities(G, e1, e2)[source]

Replaces all instances of e2 with e1 in graph G

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.namespaces.bind_prefixes(graph, brick_version='1.3')[source]

Associate common prefixes with the 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
class brickschema.orm.Point(**kwargs)[source]

Bases: sqlalchemy.orm.decl_api.Base

SQLAlchemy ORM class for BRICK.Point; see SQLORM class for usage

equipment
equipment_id
location
location_id
name
type
class brickschema.orm.SQLORM(graph, connection_string='sqlite://brick_orm.db')[source]

Bases: object

A SQLAlchemy-based ORM for Brick models.

Currently, the ORM models Locations, Points and Equipment and the basic relationships between them.

brickschema.persistent module

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.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

class brickschema.web.Server(graph, ignore_prefixes=[])[source]

Bases: object

apply_reasoning(profile)[source]
bindings()[source]
home()[source]
query()[source]
start(address='localhost:8080')[source]

Module contents

Python package brickschema provides a set of tools, utilities and interfaces for working with, developing and interacting with Brick models.