From 4aa952da6ec8791b51183bbcf14a74b53ce2b7de Mon Sep 17 00:00:00 2001 From: Alejandro Villar Date: Wed, 17 Jan 2024 13:22:39 +0100 Subject: [PATCH] Add SPARQL GSP push to entrypoint.py --- ogc/bblocks/entrypoint.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ogc/bblocks/entrypoint.py b/ogc/bblocks/entrypoint.py index ecf6d2e..8f64d57 100644 --- a/ogc/bblocks/entrypoint.py +++ b/ogc/bblocks/entrypoint.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import os import shutil import subprocess import sys @@ -8,7 +9,7 @@ from ogc.na.util import load_yaml from ogc.bblocks.postprocess import postprocess -from ogc.na import ingest_json +from ogc.na import ingest_json, update_vocabs from ogc.bblocks.util import get_github_repo @@ -158,6 +159,7 @@ annotated_path = Path(args.annotated_path) imported_registers = [] register_additional_metadata = {} + sparql_conf = {} if bb_config_file and bb_config_file.is_file(): bb_config = load_yaml(filename=bb_config_file) id_prefix = bb_config.get('identifier-prefix', id_prefix) @@ -180,6 +182,8 @@ if register_name: register_additional_metadata['name'] = register_name + sparql_conf = bb_config.get('sparql') + base_url = args.base_url github_base_url = args.github_base_url git_repo_path = None @@ -225,6 +229,7 @@ print(f"Running semantic uplift of {register_file}", file=sys.stderr) print(f" - {register_jsonld_fn}", file=sys.stderr) print(f" - {register_ttl_fn}", file=sys.stderr) + # TODO: Entailments ingest_json.process_file(register_file, context_fn=uplift_context_file, jsonld_fn=register_jsonld_fn, @@ -241,4 +246,18 @@ f"{args.generated_docs_path}/slate/", ]) + # 4. Push to triplestore + sparql_gsp = sparql_conf.get('push') + if sparql_gsp: + print(f"Pushing {register_ttl_fn} to SPARQL GSP at {sparql_gsp}", file=sys.stderr) + if os.environ.get('SPARQL_USERNAME'): + auth = (os.environ['SPARQL_USERNAME'], os.environ.get('SPARQL_PASSWORD')) + else: + auth = None + sparql_graph = sparql_conf.get('graph') or base_url + update_vocabs.load_vocab(register_ttl_fn, + graph_store=sparql_gsp, + graph_uri=sparql_graph, + auth_details=auth) + print(f"Finished Building Blocks postprocessing", file=sys.stderr)