Reference
This part of the project documentation provides information about the technical implementation of the LODKit project.
lodkit.triple_tools.ttl_constructor
LODKit Triple utilities.
plist
Bases: ttl
Deprecated alias to ttl.
This is for backwards api compatibility only. Since ttl also implements Turtle object lists now, refering to the class as "plist" is inaccurate/misleading.
Source code in lodkit/triple_tools/ttl_constructor.py
92 93 94 95 96 97 98 99 100 101 102 |
|
ttl
Triple constructor implementing a Turtle-like interface.
Source code in lodkit/triple_tools/ttl_constructor.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
__init__(uri, *predicate_object_pairs, graph=None)
Initialize a ttl triple constructor.
The callable interface aims to provide a Python representation fo Turtle predicate and object list syntax.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
_TripleSubject
|
The subject of a triple |
required |
*predicate_object_pairs |
tuple[URIRef, _TripleObject | list | Iterator | Self | str | tuple[_TripleObject, ...]]
|
Predicate-object pairs |
()
|
graph |
Graph | None
|
An optional rdflib.Graph instance |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Examples:
triples: Iterator[lodkit._Triple] = ttl(
URIRef('https://subject'),
(RDF.type, URIRef('https://some_type')),
(RDFS.label, Literal('label 1'), 'label 2'),
(RDFS.seeAlso, [(RDFS.label, 'label 3')]),
(RDFS.isDefinedBy, ttl(URIRef('https://subject_2'), (RDF.type, URI('https://another_type'))))
)
graph: Graph = triples.to_graph()
Source code in lodkit/triple_tools/ttl_constructor.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
__iter__()
Generate an iterator of tuple-based triple representations.
Source code in lodkit/triple_tools/ttl_constructor.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
__next__()
Return the next triple from the iterator.
Source code in lodkit/triple_tools/ttl_constructor.py
77 78 79 |
|
to_graph(graph=None)
Generate a graph instance from a ttl Iterator.
Source code in lodkit/triple_tools/ttl_constructor.py
81 82 83 84 85 86 87 88 89 |
|
lodkit.uri_tools.uriclass
LODKit uriclass: A dataclass inspired URI constructor mechanism.
uriclass
Dataclass-inspired URI constructor.
Class-level attributes are converted to URIs according to uri_constructor. For class attributes with just type information, URIs are constructed using UUIDs, for class attributes with string values, URIs are constructed using hashing based on that string.
Examples:
@uriclass(Namespace("https://test.org/test/"))
class uris:
x1: str
y1 = "hash value 1"
y2 = "hash value 1"
print(uris.x1) # Namespace("https://test.org/test/<UUID>")
print(uris.y1 == uris.y2) # True
Source code in lodkit/uri_tools/uriclass.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
make_uriclass(cls_name, namespace, fields, uri_constructor=mkuri_factory)
Constructor for dynamic URI class creation.
make_uriclass provides functionality structurally equivalent to @uriclass, but fields are read from an Iterable[str | tuple[str, str]].
Examples:
uris = make_uriclass(
cls_name="TestURIFun",
namespace="https://test.org/test/",
fields=("x", ("y1", "hash value 1"), ("y2", "hash value 1")),
)
print(uris.x1) # Namespace("https://test.org/test/<UUID>")
print(uris.y1 == uris.y2) # True
Source code in lodkit/uri_tools/uriclass.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|