ottr package¶
Subpackages¶
Submodules¶
ottr.generator module¶
-
class
ottr.generator.
OttrGenerator
(load_defaults: bool = True)¶ Bases:
object
An OttrGenerator can load OTTR templates definitions and expand them to produce RDF triples.
- Args:
load_defaults: True if default templates library should be loaded, False otherwise.
- Example:
>>> generator = OttrGenerator() >>> generator.load_templates("<http://example.org#Person> [ottr:IRI ?uri, ?firstName] :: { ottr:Triple (?uri, foaf:firstName, ?firstName ) } .") >>> generator.instanciate('<http://example.org#Person>(_:person, "Ann"@en)') >>> for triple in instances.execute(as_nt=True): >>> print(triple)
-
instanciate
(text: str, format: str = 'stottr') → ottr.generator.OttrInstances¶ Instance a set of OTTR instances.
- Args:
text: Set of OTTR instances in text format.
format: Format of the input instances. Defaults to sOTTR. Supported formats: sOTTR.
- Returns:
An instance of OttrInstances, that can be executed to generate RDF triples.
Throws: TypeError if the input format is not supported.
-
load_templates
(text: str, format: str = 'stottr') → None¶ Load a set of OTTR template definitions.
- Args:
text: Set of OTTR template definitions in text format.
format: Format of the input template definitions. Defaults to sOTTR. Supported formats: sOTTR.
Throws: TypeError if the input format is not supported.
-
class
ottr.generator.
OttrInstances
(exec_id: int, to_execute: List[Tuple[ottr.base.template.AbstractTemplate, Dict[rdflib.term.Variable, Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef]]]], all_templates: Dict[rdflib.term.URIRef, ottr.base.template.AbstractTemplate])¶ Bases:
object
Compiled OTTR instances, ready to be executed to produce RDF triples.
- Args:
exec_id: ID of the execution, used to unify blank nodes generation during template expansion.
to_execute: List of tuple (template, instance arguments) to execute.
all_templates: Map of all OTTR templates available at execution.
-
execute
(as_nt: bool = False) → Iterable[Tuple[Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef], Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef], Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef]]]¶ Execute the instances to produce RDF triples.
- Args:
as_nt: (optional) True if the results should be produced in n-triples format, False if they should be produced in RDFlib format.
- Yields:
RDF triples, in n-triples or rdflib format.
ottr.types module¶
This module contains common types encountered in the ottr package.
They are used for type annotations, as specified by PEP 484, PEP 526, PEP 544, PEP 586, PEP 589, and PEP 591.
Module contents¶
Manipulate OTTR Reasonable Ontology Templates in Python
-
class
ottr.
OttrGenerator
(load_defaults: bool = True)¶ Bases:
object
An OttrGenerator can load OTTR templates definitions and expand them to produce RDF triples.
- Args:
load_defaults: True if default templates library should be loaded, False otherwise.
- Example:
>>> generator = OttrGenerator() >>> generator.load_templates("<http://example.org#Person> [ottr:IRI ?uri, ?firstName] :: { ottr:Triple (?uri, foaf:firstName, ?firstName ) } .") >>> generator.instanciate('<http://example.org#Person>(_:person, "Ann"@en)') >>> for triple in instances.execute(as_nt=True): >>> print(triple)
-
instanciate
(text: str, format: str = 'stottr') → ottr.generator.OttrInstances¶ Instance a set of OTTR instances.
- Args:
text: Set of OTTR instances in text format.
format: Format of the input instances. Defaults to sOTTR. Supported formats: sOTTR.
- Returns:
An instance of OttrInstances, that can be executed to generate RDF triples.
Throws: TypeError if the input format is not supported.
-
load_templates
(text: str, format: str = 'stottr') → None¶ Load a set of OTTR template definitions.
- Args:
text: Set of OTTR template definitions in text format.
format: Format of the input template definitions. Defaults to sOTTR. Supported formats: sOTTR.
Throws: TypeError if the input format is not supported.