ontopint
A python package for reading & writing units from a JSON-LD files and generating pint quantities.
How it works
import ontopint
# jsonld input with 'value' and 'unit' mapped to qudt terms
data = {
"@context": {
"qudt": "http://qudt.org/schema/qudt/",
"qunit": "http://qudt.org/vocab/unit/",
"qkind": "http://qudt.org/vocab/quantkind/",
"unit": {
"@id": "qudt:hasUnit",
"@type": "@id"
},
"quantity": {
"@id": "qudt:hasQuantityKind",
"@type": "@id"
},
"value": "qudt:value"
},
"value": 4.0,
"unit": "qunit:CentiM"
}
# convert the value + unit pairs to pint.Quantity
data = ontopint.parse_units(data)
print(data)
"""
{
'@context': {...},
'value': <Quantity(4.0, 'centimeter')>
}
"""
# do something with pint
data["value"] += 3 * ontopint.ureg.meter
data["value"] = data["value"].to(ontopint.ureg.meter)
print(data)
"""
{
'@context': {...},
'value': <Quantity(3.04, 'meter')>
}
"""
# export the result as jsonld
data = ontopint.export_units(data)
print(data)
"""
{
"@context": {
"qudt": "http://qudt.org/schema/qudt/",
"qunit": "http://qudt.org/vocab/unit/",
"qkind": "http://qudt.org/vocab/quantkind/",
"unit": {
"@id": "qudt:hasUnit",
"@type": "@id"
},
"quantity": {
"@id": "qudt:hasQuantityKind",
"@type": "@id"
},
"value": "qudt:value"
},
"value": 3.04,
"unit": "qunit:M"
}
"""
Note: more complex examples can be found at tests/data
Metadata
Release files for ontopint 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ontopint-0.1.1.tar.gz | 9.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ontopint-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.8 kB
Release files / ontopint-0.1.1.tar.gz
| Download URL | ontopint-0.1.1.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
712a8888984197c4d4fff99170560ec6c62183b459780f7e585ea62e1099a8e7
|
|
BLAKE2b-256 checksum How to use checksums |
37bba53324842775cfb7866bff5bb56b0453a37051db4b1e76cec6d913c7af07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|
Release files / ontopint-0.1.1-py3-none-any.whl
| Download URL | ontopint-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b12ac8ec4701f9f77d3908cecdd35751ddc9ce1e36dc509ca43712a42236fa9b
|
|
BLAKE2b-256 checksum How to use checksums |
84f10fff492b6e4049d8bc0d0f20751814550cd5ba735f0ca45095fbf85a1df4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|