authors: @modeller and @bradeneliason
date: September 2021
This repo is the simplest TypeQL model of a units library. It contains the code and data needed to load a minimum example. It imports data froma series of csv, making it easy to add your own units.
Units are defined by their string value, for example "kN.m", or "m2". This "unit" attribute, is also owned as a key by the unit_details
relation, which contains all of the details for that particular unit. These details include conversion attributes, to enable conversion to the metric base unit.
To create a measure, one needs to simply have a quantity and connect the unit to it in the schema
measure isa attribute, value long, has unit
Then, on import one just uses the simple syntax
insert $m isa measure; $m 103.25; $m has unit "kPa";
Units are of different types:
The unit is also connected to the dimensions, which define that measure. These dimensions also have the base unit name, attached to them. In addition to the usual SI dimensions (time, length, mass, current, temperature, moles, luminosity), there are two extra ones added for non-dimensional measures (radians, composition). The non-dimensional composition measures also connect to the unit they are compared on, for example m3/m3 has acomposition dimension of 1, and a length dimension of 3.
Non-base units, like "in2", are automatically connected to their base unit, "m2", so that conversions can be set up. At the moment, conversions are not implemented, as we are waiting for calculations before implementing them.
For this schema all tolerance types are converted into bilateral form with an upper and a lower tolernace value. How the upper and lower tolerance values are interpreted depends on two boolean values is_absolute
and is_offset
:
is_absolute
is true the upper and lower tolerance value have the same units as the nominal value, otherwise the upper and lower tolerances are interpreted as a scaling factor of the nominal value. is_offset
is true, the limits of the tolernace is computed by adding the upper and lower tolernace to the nominal value, otherwise, the upper and lower tolerance stand alone as the limits. The table below shows how the tolerance 10±1
can be represented in four ways.
is_absolute true |
is_absolute false |
|
---|---|---|
is_offset true |
+1 -1 |
(×) +0.1 -0.1 |
is_offset false |
11 9 |
(×) 1.10 0.90 |
To install the repo make sure that pipenv is installed in your Python.
The implementation is tested on Python 3.8.
TypeDB must be running, and the system is setup to use the localhost. If you are using a different server, then its address need to be inserted in the clean_and_load.py.
pipenv shell
pipenv install
python clean_and_load.py
The installation implements some example measures, and these can be easily extended by adjusting the csv files from the spreadsheet