From 860349cf5867192f8e3772d04b039ea4460638d5 Mon Sep 17 00:00:00 2001 From: Luka van der Plas Date: Tue, 23 Jul 2024 14:49:04 +0200 Subject: [PATCH] docstrings + formatting --- backend/collect/api.py | 2 +- backend/collect/graphs.py | 7 +++++++ backend/collect/rdf_models.py | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/collect/api.py b/backend/collect/api.py index c865765a..d2696b8d 100644 --- a/backend/collect/api.py +++ b/backend/collect/api.py @@ -61,4 +61,4 @@ def get_graph(self, request: Request, collection: str, **kwargs) -> Graph: g += collection_obj._class_triples() g += EDPOPCollection.records._stored_triples(collection_obj) - return g \ No newline at end of file + return g diff --git a/backend/collect/graphs.py b/backend/collect/graphs.py index c4b39c69..e1ebcf3a 100644 --- a/backend/collect/graphs.py +++ b/backend/collect/graphs.py @@ -28,6 +28,13 @@ def list_to_graph_collection(items: List[Node], items_node: IdentifiedNode) -> G def collection_triples(graph: Graph, list_node: IdentifiedNode) -> Triples: + ''' + Select all triples that make up an RDF collection in a graph. + + This collects the chain of `rdf:first` / `rdf:rest` relations that make up the + collection. + ''' + triples = list(graph.triples((list_node, RDF.first, None))) triples += list(graph.triples((list_node, RDF.rest, None))) diff --git a/backend/collect/rdf_models.py b/backend/collect/rdf_models.py index 5db692dd..c9ff9a9f 100644 --- a/backend/collect/rdf_models.py +++ b/backend/collect/rdf_models.py @@ -10,6 +10,10 @@ ) class CollectionMembersField(RDFField): + ''' + Field for the records that are contained in an EDPOP collection. + ''' + def get(self, instance: RDFModel): g = self.get_graph(instance) items = next(g.objects(instance.uri, AS.items), None)