A python package for reading units from a JSON-LD files and generating pint quantities.
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ontopint-0.1.1.tar.gz
(9.8 kB
view details)
Built Distribution
File details
Details for the file ontopint-0.1.1.tar.gz
.
File metadata
- Download URL: ontopint-0.1.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 712a8888984197c4d4fff99170560ec6c62183b459780f7e585ea62e1099a8e7 |
|
MD5 | 6f07afc1208d1b78a2cd35067df40a29 |
|
BLAKE2b-256 | 37bba53324842775cfb7866bff5bb56b0453a37051db4b1e76cec6d913c7af07 |
File details
Details for the file ontopint-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: ontopint-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b12ac8ec4701f9f77d3908cecdd35751ddc9ce1e36dc509ca43712a42236fa9b |
|
MD5 | f54ce2e6efe24b30ab87c17fc41e219e |
|
BLAKE2b-256 | 84f10fff492b6e4049d8bc0d0f20751814550cd5ba735f0ca45095fbf85a1df4 |