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 ontolutils import Thing, urirefs, namespaces
from pydantic import EmailStr
from rdflib import FOAF
@namespaces(prov="http://www.w3.org/ns/prov#",
foaf="http://xmlns.com/foaf/0.1/")
@urirefs(Person='prov:Person',
firstName='foaf:firstName',
lastName=FOAF.lastName,
mbox='foaf:mbox')
class Person(Thing):
firstName: str
lastName: str = None
mbox: EmailStr = None
p = Person(id="cde4c79c-21f2-4ab7-b01d-28de6e4aade4",
firstName='John', lastName='Doe')
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#",
"lastName": "http://xmlns.com/foaf/0.1/",
"prov": "http://www.w3.org/ns/prov#",
"foaf": "http://xmlns.com/foaf/0.1/"
},
"@id": "cde4c79c-21f2-4ab7-b01d-28de6e4aade4",
"@type": "prov:Person",
"foaf:firstName": "John",
"lastName": "Doe"
}
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for ontolutils-0.2.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cab1403e7b9303665542ae317e14e379fcd36162c3b4e002dd8242a1e51ac196 |
|
MD5 | 2bc5ae44be2ca7032982d5e57018b09c |
|
BLAKE2b-256 | d7e92895efc5bb02a1ca542dca08633fa4227ba3b593b2a9eec2d250231cf46b |