Manipulate OTTR Reasonable Ontology Templates in Python
Project description
pyOTTR
Manipulate OTTR Reasonable Ontology Templates in Python.
Supported features:
Non blank, Optional and default values for template parameters.
RDF and RDFS templates from the OTTR template library are loaded by default.
In development:
Support for OWL templates from the template library
Installation
Using pip (recommended)
pip install ottr
Manual installation
git clone cd pyOTTR/ python setup.py install
Getting started
The main class to manipulate is OttrGenerator, which is used to load OTTR templates and expand template instances. So, in practice, you only need to create a new generator, load some templates and then execute your instances to produce RDF triples.
By default, all templates from the OTTR template library are loaded when the generator is created.
from ottr import OttrGenerator
# An OttrGenerator is used to load templates and expand instances
generator = OttrGenerator()
# Load a simple OTTR template definition
generator.load_templates("""
@prefix ex: <http://example.org#>.
ex:FirstName [ottr:IRI ?uri, ?firstName] :: {
ottr:Triple (?uri, foaf:firstName, ?firstName )
} .
ex:Person[ ?firstName ] :: {
ottr:Triple (_:person, rdf:type, foaf:Person ),
ex:FirstName (_:person, ?firstName)
} .
""")
# Parse and prepare an instance for execution
instances = generator.instanciate("""
@prefix ex: <http://example.org#>.
ex:Person("Ann").
""")
# Execute the instance, which yield RDF triples
# The following prints (_:person0, rdf:type, foaf:Person) and (_:person0, foaf:firstName, "Ann")
for s, p, o in instances.execute(as_nt=True):
print("# ----- RDF triple ----- #")
print((s, p, o)
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
File details
Details for the file ottr-0.0.1.tar.gz
.
File metadata
- Download URL: ottr-0.0.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5050f20ce329fc3ccee5aa9c9603d4853961d572bcd1aae15e7245c6d37c06aa |
|
MD5 | d5d89935205a43905238e748ac68e639 |
|
BLAKE2b-256 | c55a249ef88441ffcb64a198cb1c7f743cb7e7d278a56e1181903f19b02ee4fa |