Brick-vocab-mapper
pip install brickmapper
This package is a simple wrapper around the OpenAI embeddings API to assist in producing vocabulary mappings between external vocabs (like Haystack protos, gbXML equipment names, or internal naming schems) and Brick classes.
You will need an OpenAI API key to compute your own embeddings. This costs money,
but is very cheap (much less than $1) to do for hundreds of terms.
We cache embeddings in .index files to avoid hitting the API again.
The brick.index file in this repo will allow you to run the example below without any OpenAI API calls.
You must provide your external vocabulary to the Brick mapper tool as a list of dictonaries.
Each dictionary defines key-value pairs of a single concept; this dictionary must contain a key called name which contains
the unique name of the term to be mapped.
There are two kinds of mappings that can be produced by the package:
stable: a stable mapping performs a 1-1 matching of external terms to Brick classes; it does not permit overlapsunstable: an unstable mapping allows 1 external term to match multiple Brick classes and vice-versa
Haystack Protos Example
from brickmapper import Mapper
from rdflib import BRICK
import urllib.request
import csv
defns = []
# read haystack proto definitions off their website
request = urllib.request.Request("https://project-haystack.org/download/protos.csv", headers={'User-Agent': "Python script"})
response = urllib.request.urlopen(request)
rdr = csv.DictReader(response.read().decode('utf8').splitlines())
for row in rdr:
# save each proto (e.g. 'air temp sensor point') as a dictionary
defns.append({'name': row['proto']})
# create a new Mapper object which knows about the definitions. This will
# access OpenAI to compute embeddings if necessary
m = Mapper(defns, "haystack_proto.index")
# define which set of Brick classes we want to match against
# all points which aren't parameters (these have similar enough names it can confuse the mapping)
points = m.get_brick_classes(BRICK.Point, [BRICK.Parameter])
# all equipment in Brick
equips = m.get_brick_classes(BRICK.Equipment)
# concatenate these two lists of Brick classes
bcs = points + equips
# compute a 'stable' mapping (1:1 mapping)
stable = m.get_mapping(bcs, allow_collisions=False)
# compute an 'unstable' mapping that allows 1:n and n:1 matches
unstable = m.get_mapping(bcs, allow_collisions=True)
# loop through and print the stable/unstable matches
for k,v in unstable.items():
print(f"{k}:\n\tunstable: {v}\n\tstable: {stable.get(k)}")
Gives output like:
flue hot water heat valve cmd point:
unstable: https://brickschema.org/schema/Brick#Domestic_Hot_Water_Valve
stable: https://brickschema.org/schema/Brick#Hot_Water_Valve
steam bypass pump point:
unstable: https://brickschema.org/schema/Brick#Bypass_Valve
stable: https://brickschema.org/schema/Brick#Bypass_Valve
makeup water entering valve actuator equip:
unstable: https://brickschema.org/schema/Brick#Makeup_Water_Valve
stable: https://brickschema.org/schema/Brick#Makeup_Water_Valve
makeup water entering pipe equip:
unstable: https://brickschema.org/schema/Brick#Eye_Wash_Station
stable: https://brickschema.org/schema/Brick#Eye_Wash_Station
steam leaving pump point:
unstable: https://brickschema.org/schema/Brick#Emergency_Wash_Station
stable: https://brickschema.org/schema/Brick#Steam_Baseboard_Radiator
infiltration well equip:
unstable: https://brickschema.org/schema/Brick#Intrusion_Detection_Equipment
stable: https://brickschema.org/schema/Brick#Intrusion_Detection_Equipment
economizer damper actuator equip:
unstable: https://brickschema.org/schema/Brick#Economizer_Damper
stable: https://brickschema.org/schema/Brick#Economizer_Damper
steam leaving point:
unstable: https://brickschema.org/schema/Brick#Steam_Distribution
stable: https://brickschema.org/schema/Brick#Steam_Distribution
flue equip:
unstable: https://brickschema.org/schema/Brick#Fire_Safety_Equipment
stable: https://brickschema.org/schema/Brick#Fire_Safety_Equipment
condenser water entering pump equip:
unstable: https://brickschema.org/schema/Brick#Condenser_Water_Pump
stable: https://brickschema.org/schema/Brick#Condenser_Water_Pump
TODOs
- incorporate common abbreviations & support embedding of them
Metadata
Release files for brickmapper 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| brickmapper-0.1.3.tar.gz | 6.0 kB | Without provenance | Details for brickmapper-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| brickmapper-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for brickmapper-0.1.3-py3-none-any.whl |
Total release size: 12.4 kB
Release files / brickmapper-0.1.3.tar.gz
| Download URL | brickmapper-0.1.3.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11618e3a9bed66dd5f94f09d7cb406469edb62eb505344c90181c254b0e0c5d6
|
|
BLAKE2b-256 checksum How to use checksums |
6da657628a34bec81c6aeb2c364faad584b9d93c706def7fa1387a0b26935288
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0
|
Release files / brickmapper-0.1.3-py3-none-any.whl
| Download URL | brickmapper-0.1.3-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
155a8322771bef966d9d7f6616ac1f517311e34eb4385ee362e923073dfd581d
|
|
BLAKE2b-256 checksum How to use checksums |
659ccd233a5294116ade15d4f0c25178afad22d7061e6c2bddddccf611610508
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0
|
Security for brickmapper 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.