Utility library for the work with ontologies.
Project description
Ontolutils - Object-oriented "Things"
This package helps you in generating ontology-related objects and let's you easily create JSON-LD files.
Quickstart
Installation
Install the package:
pip install ontolutils
Usage
Imagine you want to describe a prov:Person
with a first name, last name and an email address but writing
the JSON-LD file yourself is too cumbersome and you want validation of the parsed parameters. The package
lets you design classes, which describe ontology classes like this:
from pydantic import EmailStr, Field
from ontolutils import Thing, urirefs, namespaces
from pydantic import HttpUrl
@namespaces(prov="http://www.w3.org/ns/prov#",
foaf="http://xmlns.com/foaf/0.1/")
@urirefs(Person='prov:Person',
firstName='foaf:firstName',
last_name='foaf:lastName',
mbox='foaf:mbox')
class Person(Thing):
firstName: str
last_name: str = Field(default=None, alias="lastName") # you may provide an alias
mbox: EmailStr = None
orcidId: HttpUrl = Field(default=None, alias="foaf:orcidId",
json_schema_extra={'use_as_id': True}) # use this as ID if available
p = Person(id="https://orcid.org/0000-0001-8729-0482",
firstName='Matthias', last_name='Probst')
# as we have set an alias, we can also use "lastName":
p = Person(id="https://orcid.org/0000-0001-8729-0482",
firstName='Matthias', lastName='Probst')
# The jsonld representation of the object will be the same in both cases:
p.model_dump_jsonld()
Now, you can instantiate the class and use the model_dump_jsonld()
method to get a JSON-LD string:
{
"@context": {
"owl": "http://www.w3.org/2002/07/owl#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"prov": "http://www.w3.org/ns/prov#",
"foaf": "http://xmlns.com/foaf/0.1/"
},
"@id": "https://orcid.org/0000-0001-8729-0482",
"@type": "prov:Person",
"foaf:firstName": "Matthias",
"foaf:lastName": "Probst"
}
Documentation
Please visit the documentation for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ontolutils-0.6.2.tar.gz
.
File metadata
- Download URL: ontolutils-0.6.2.tar.gz
- Upload date:
- Size: 99.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd86bdb837605a3bc3980743bceef59b5af7ebe02c2b3cee2522f7cd505f0142 |
|
MD5 | e7838784212f0e9d04ab7ae24af28c7b |
|
BLAKE2b-256 | ec78609b4d36d6504ff328e7a20bde2a0603177a42c6db8bba5a6b139ca2bb8d |
File details
Details for the file ontolutils-0.6.2-py3-none-any.whl
.
File metadata
- Download URL: ontolutils-0.6.2-py3-none-any.whl
- Upload date:
- Size: 97.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e953564fae034e46a96d08fad347c9e356b8c150399050ce5531223fe0f9f9e1 |
|
MD5 | 80d8bbd697a370192ffdfc098f865b4b |
|
BLAKE2b-256 | dc00ae9d47b14c917e1043865d115a57a65237c893d887f3d967d7b05a646c98 |