From 29e4d7b80aa5829f662e113ecf8514f3ede35b37 Mon Sep 17 00:00:00 2001 From: vennyy3 Date: Wed, 1 Jul 2026 13:47:45 +0200 Subject: [PATCH 1/4] documentation for serialize and deserialize --- py_maplib/maplib/__init__.pyi | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/py_maplib/maplib/__init__.pyi b/py_maplib/maplib/__init__.pyi index 63db10ae..d8375b6b 100644 --- a/py_maplib/maplib/__init__.pyi +++ b/py_maplib/maplib/__init__.pyi @@ -538,10 +538,27 @@ class Model: def serialize(self, path: Union[Path, str]): - ... + """ + Serialization of triples and cat map + + Usage: + >>> m.read("triples.nt") + >>> m.serialize("serialized") + + :param path: The path to where the folder containing the triples should be created + """ def deserialize(path: Union[Path, str]="./serialized_triples", storage_folder: Union[Path, str] = None) -> "Model": - ... + """ + Deserialization of serialized triples and cat map + + Usage: + >>> m.deserialize("serialized", storage_folder="disk") + + :param path: The path to the folder where the serialized triples and cat map is stored + :param storage_folder: The target path and folder name where the deserialized triples should be stored + :return: A model. + """ def add_template(self, template: Union["Template", str]): From b3d60bb11c5fb987b5fc9057ce70a88c0b768196 Mon Sep 17 00:00:00 2001 From: vennyy3 Date: Wed, 1 Jul 2026 13:50:00 +0200 Subject: [PATCH 2/4] example for udf --- py_maplib/maplib/__init__.pyi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/py_maplib/maplib/__init__.pyi b/py_maplib/maplib/__init__.pyi index d8375b6b..b5a3c6ec 100644 --- a/py_maplib/maplib/__init__.pyi +++ b/py_maplib/maplib/__init__.pyi @@ -1207,6 +1207,11 @@ class Model: input_types: list[Union[RDFType,str, IRI]] = None ): """ + Add a user-defined function + + Usage: + >>> m.add_udf("urn:maplib:findabc", g, xsd.boolean, [xsd.string]) + :param iri: IRI of the UDF, e.g. "urn:maplib:myfunc" :param func: A callable (DataFrame) -> DataFrame :param output_type: The RDF type of the output. Either an RDFType (e.g. RDFType.IRI, RDFType.Literal(xsd.string)) or an IRI (e.g. xsd.integer) From fad532e0e2ceedf3e08e1e555a0b3aa6671f2b65 Mon Sep 17 00:00:00 2001 From: vennyy3 Date: Wed, 1 Jul 2026 13:53:28 +0200 Subject: [PATCH 3/4] remove unused imports --- py_maplib/maplib/__init__.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/py_maplib/maplib/__init__.pyi b/py_maplib/maplib/__init__.pyi index b5a3c6ec..6d3181cd 100644 --- a/py_maplib/maplib/__init__.pyi +++ b/py_maplib/maplib/__init__.pyi @@ -1,5 +1,3 @@ -import pathlib -import string from pathlib import Path from typing import Any, Union, List, Dict, Optional, Callable, Literal as LiteralType from polars import DataFrame From 8427998e53bc7e72cd72f4883c39a9812d5ed88d Mon Sep 17 00:00:00 2001 From: vennyy3 Date: Wed, 1 Jul 2026 15:15:28 +0200 Subject: [PATCH 4/4] improved example of add_udf --- py_maplib/maplib/__init__.pyi | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/py_maplib/maplib/__init__.pyi b/py_maplib/maplib/__init__.pyi index 6d3181cd..e315ffc7 100644 --- a/py_maplib/maplib/__init__.pyi +++ b/py_maplib/maplib/__init__.pyi @@ -537,7 +537,7 @@ class Model: def serialize(self, path: Union[Path, str]): """ - Serialization of triples and cat map + Serialization of named graphs in the Model object Usage: >>> m.read("triples.nt") @@ -548,7 +548,7 @@ class Model: def deserialize(path: Union[Path, str]="./serialized_triples", storage_folder: Union[Path, str] = None) -> "Model": """ - Deserialization of serialized triples and cat map + Deserialization of serialized graphs Usage: >>> m.deserialize("serialized", storage_folder="disk") @@ -1206,9 +1206,24 @@ class Model: ): """ Add a user-defined function - Usage: + The user defined function that is provided should take in a Polars DataFrame as an argument. + This dataframe will have one column for each argument ("0", "1" and so on). + The function should add a column (e.g. "out") to the DataFrame, and return it. + >>> def g(df: pl.DataFrame) -> pl.DataFrame: + >>> df = df.with_columns( + >>> (pl.col("0").str.contains("abc")).alias("out") + >>> ) + >>> return df + >>> m.add_udf("urn:maplib:findabc", g, xsd.boolean, [xsd.string]) + >>> result = m.query(''' + ... SELECT * { + ... ?a ?s1 . + ... BIND((?s1) AS ?found) + ... } + ... ''') + ... print(result) :param iri: IRI of the UDF, e.g. "urn:maplib:myfunc" :param func: A callable (DataFrame) -> DataFrame