RDF lists and language-tagged literals
TripleModel maps list[T] fields to ordered rdf:List structures and set[T] fields to multiple objects on one predicate.
list[T] → rdf:List
Use a Python list when order matters and the graph should use an rdf:List head node (rdf:first / rdf:rest):
nick: list[str] = rdf_field("foaf:nick", default_factory=list)
from examples.doc._models import Person
person = Person(slug="alice", name="Alice", nick=["Al", "Alice"])
restored = Person.from_graph(person.to_graph(), person.subject_uri())
print(restored.nick)
Output:
['Al', 'Alice']
Sync modes clear the entire list structure when the field is None or [].
If the graph has more than one rdf:List head for the same predicate, import uses the first head only. Use on_duplicate="error" on import to surface ambiguous data; "ignore" suppresses the warning but does not merge lists.
set[T] → multiple objects
Use a set when you want several objects on the same predicate without an RDF list (order not guaranteed):
tag: set[str] = rdf_field("http://example.org/tag", default_factory=set)
See Multi-valued fields for sync and duplicate-object behaviour.