From 77960020c6b7586b04019bbbf00948b027a08800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Meynadier?= Date: Mon, 18 May 2026 17:34:56 +0200 Subject: [PATCH 1/2] Generate serializations of the full graph Currently we generate the graph serialization as split files. https://github.com/TheBIPM/SI_Digital_Framework/issues/26 suggests that some users would find it useful to have the whole graph in one single file. This proposal generates "sirp_full.ttl" and "sirp_full.jsonld" alongside the splitted serializations. --- src/si_ref_point/main.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/si_ref_point/main.py b/src/si_ref_point/main.py index 57a98e3..eae3391 100644 --- a/src/si_ref_point/main.py +++ b/src/si_ref_point/main.py @@ -19,6 +19,7 @@ import datetime from pathlib import Path from zipfile import ZipFile +from rdflib import Graph def get_parser(): @@ -120,6 +121,28 @@ def main(force_output_dir_to=None): with open(hashdest, 'w') as fp: fp.write(hashstr) + # Generate full graphs outputs + # Just merging graphs in memory could lead to blank-nodes collisions, so + # instead parse the TTL files we just wrote as suggested here + # https://rdflib.readthedocs.io/en/7.1.1/merging.html + + full_graph = Graph() + for ttl_file in file_generator.keys(): + full_graph.parse(ttl_dir / (ttl_file + ".ttl")) + for srl in serializations: + filedest = os.path.join(srl['dir'], 'sirp_full.' + srl['ext']) + full_graph.serialize(format=srl['fmt'], destination=filedest) + # generate hash for file and write it alongside + h = hashlib.new('sha256') + with open(filedest, encoding="UTF8") as fp: + h.update(fp.read().encode()) + hashstr = h.hexdigest() + hashdest = os.path.join(srl['dir'], 'sirp_full.sha256') + with open(hashdest, 'w') as fp: + fp.write(hashstr) + + + logging.info(f"TTL and JSON-LD files written to ./{ttl_dir}/ and ./{jsonld_dir}/, respectively") if args.generate_RDF: output['si'].serialize( From 01a8ac2e69b27d2fe6911f76a5416a513dbf771b Mon Sep 17 00:00:00 2001 From: Cristhian PAREDES Date: Wed, 20 May 2026 09:38:59 +0200 Subject: [PATCH 2/2] added console message for the full graph generation --- src/si_ref_point/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/si_ref_point/main.py b/src/si_ref_point/main.py index eae3391..ff9cfb4 100644 --- a/src/si_ref_point/main.py +++ b/src/si_ref_point/main.py @@ -127,6 +127,7 @@ def main(force_output_dir_to=None): # https://rdflib.readthedocs.io/en/7.1.1/merging.html full_graph = Graph() + logging.info(f"generating full sirp graph") for ttl_file in file_generator.keys(): full_graph.parse(ttl_dir / (ttl_file + ".ttl")) for srl in serializations: @@ -140,6 +141,7 @@ def main(force_output_dir_to=None): hashdest = os.path.join(srl['dir'], 'sirp_full.sha256') with open(hashdest, 'w') as fp: fp.write(hashstr) + logging.info("..done")