From 363f9d28870a4671755b9cd99fd4475870677761 Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Fri, 11 Oct 2024 11:55:32 -0300 Subject: [PATCH 1/9] remove run mesure on full ontology --- util/lib.py | 67 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/util/lib.py b/util/lib.py index 2211ab5..33bd449 100644 --- a/util/lib.py +++ b/util/lib.py @@ -342,41 +342,54 @@ def load_yaml(filepath): return data -def robot_prepare_ontology(o_path, o_out_path, o_metrics_path, base_iris, make_base, robot_prefixes={}, robot_opts="-v"): - logging.info(f"Preparing {o_path} for dashboard.") - - callstring = ['robot', 'merge', '-i', o_path] - +def robot_prepare_ontology( + o_path, + o_out_path, + o_metrics_path, + base_iris, + make_base, + robot_prefixes=None, + robot_opts="-v" +): + """ + Run ROBOT mesure on the base, but generate it first if not available + """ + logging.info("Preparing %s for dashboard.", o_path) + + callstring = ["robot", "merge", "-i", o_path] + if robot_opts: callstring.append(f"{robot_opts}") - - ### Measure stuff - callstring.extend(['measure']) - for prefix in robot_prefixes: - callstring.extend(['--prefix', f"{prefix}: {robot_prefixes[prefix]}"]) - callstring.extend(['--metrics', 'extended-reasoner','-f','yaml','-o',o_metrics_path]) - - ## Extract base + + if robot_prefixes is None: + robot_prefixes = {} + + # Extract base if not available if make_base: - callstring.extend(['remove']) + callstring.extend(["remove"]) for s in base_iris: - callstring.extend(['--base-iri',s]) - callstring.extend(["--axioms", "external", "--trim", "false", "-p", "false"]) - - ### Measure stuff on base - callstring.extend(['measure']) + callstring.extend(["--base-iri", s]) + callstring.extend( + ["--axioms", "external", "--trim", "false", "-p", "false"] + ) + + # Measure stuff + callstring.extend(["measure"]) for prefix in robot_prefixes: - callstring.extend(['--prefix', f"{prefix}: {robot_prefixes[prefix]}"]) - callstring.extend(['--metrics', 'extended-reasoner','-f','yaml','-o',f"{o_metrics_path}.base.yml"]) - - ## Output - callstring.extend(['merge', '--output', o_out_path]) + callstring.extend(["--prefix", f"{prefix}: {robot_prefixes[prefix]}"]) + callstring.extend( + ["--metrics", "extended-reasoner", "-f", "yaml", "-o", o_metrics_path] + ) + + # Output + callstring.extend(["merge", "--output", o_out_path]) logging.info(callstring) - + try: check_call(callstring) - except Exception as e: - raise Exception(f"Preparing {o_path} for dashboard failed...", e) + except Exception: + logging.error("Preparing %s for dashboard failed...", o_path) + def count_up(dictionary, value): if value not in dictionary: From 02f59c3c2a776830f9e6023f1d86e4fe27cbf4d6 Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 14 Oct 2024 15:32:57 -0300 Subject: [PATCH 2/9] adding more detailed error information to the log message: --- util/lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/lib.py b/util/lib.py index 33bd449..33ad69e 100644 --- a/util/lib.py +++ b/util/lib.py @@ -387,8 +387,8 @@ def robot_prepare_ontology( try: check_call(callstring) - except Exception: - logging.error("Preparing %s for dashboard failed...", o_path) + except Exception as e: + logging.error("Preparing %s for dashboard failed: %s", o_path, str(e)) def count_up(dictionary, value): From bd11739bab90253ea5f3ceb942904d5ceb5f03f7 Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 14 Oct 2024 15:50:12 -0300 Subject: [PATCH 3/9] Add trailing commas for improved maintainability --- util/lib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/lib.py b/util/lib.py index 33ad69e..942fafe 100644 --- a/util/lib.py +++ b/util/lib.py @@ -349,7 +349,7 @@ def robot_prepare_ontology( base_iris, make_base, robot_prefixes=None, - robot_opts="-v" + robot_opts="-v", ): """ Run ROBOT mesure on the base, but generate it first if not available @@ -370,7 +370,7 @@ def robot_prepare_ontology( for s in base_iris: callstring.extend(["--base-iri", s]) callstring.extend( - ["--axioms", "external", "--trim", "false", "-p", "false"] + ["--axioms", "external", "--trim", "false", "-p", "false",] ) # Measure stuff @@ -378,7 +378,7 @@ def robot_prepare_ontology( for prefix in robot_prefixes: callstring.extend(["--prefix", f"{prefix}: {robot_prefixes[prefix]}"]) callstring.extend( - ["--metrics", "extended-reasoner", "-f", "yaml", "-o", o_metrics_path] + ["--metrics", "extended-reasoner", "-f", "yaml", "-o", o_metrics_path,] ) # Output From 4b5dac81fa1d7b6096c2e7d75432c45a3ca279a4 Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 14 Oct 2024 15:57:22 -0300 Subject: [PATCH 4/9] Update the function signature and docstring --- util/lib.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/util/lib.py b/util/lib.py index 942fafe..5c821ed 100644 --- a/util/lib.py +++ b/util/lib.py @@ -8,6 +8,7 @@ import urllib.request from datetime import datetime from subprocess import check_call +from typing import Dict, List, Optional import requests import yaml @@ -343,16 +344,31 @@ def load_yaml(filepath): def robot_prepare_ontology( - o_path, - o_out_path, - o_metrics_path, - base_iris, - make_base, - robot_prefixes=None, + o_path: str, + o_out_path: str, + o_metrics_path: str, + base_iris: List[str], + make_base: bool, + robot_prefixes: Optional[Dict[str, str]] = None, robot_opts="-v", -): +) -> None: """ - Run ROBOT mesure on the base, but generate it first if not available + Prepare an ontology for the dashboard by running ROBOT commands. + + This function merges the input ontology, optionally extracts a base version, + measures metrics, and outputs the prepared ontology. + + Args: + o_path (str): Path to the input ontology file. + o_out_path (str): Path to save the output ontology file. + o_metrics_path (str): Path to save the metrics file. + base_iris (List[str]): List of base IRIs to use for extraction. + make_base (bool): Whether to extract a base version of the ontology. + robot_prefixes (Optional[Dict[str, str]]): Dictionary of prefix mappings for ROBOT. + robot_opts (str): Additional ROBOT options. + + Returns: + None """ logging.info("Preparing %s for dashboard.", o_path) From 4fbab319938263ce774afbeb6e9c345fa38044fa Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 14 Oct 2024 16:03:51 -0300 Subject: [PATCH 5/9] Uses a more specific exception type (subprocess.CalledProcessError) --- util/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/lib.py b/util/lib.py index 5c821ed..e0fafcf 100644 --- a/util/lib.py +++ b/util/lib.py @@ -403,7 +403,7 @@ def robot_prepare_ontology( try: check_call(callstring) - except Exception as e: + except subprocess.CalledProcessError as e: logging.error("Preparing %s for dashboard failed: %s", o_path, str(e)) From cb901dda3679dee84a816ca5a2f9a0267d033550 Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 14 Oct 2024 20:37:42 +0100 Subject: [PATCH 6/9] Add missing type annotation for robot_opts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- util/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/lib.py b/util/lib.py index e0fafcf..d24fb98 100644 --- a/util/lib.py +++ b/util/lib.py @@ -350,7 +350,7 @@ def robot_prepare_ontology( base_iris: List[str], make_base: bool, robot_prefixes: Optional[Dict[str, str]] = None, - robot_opts="-v", + robot_opts: str = "-v", ) -> None: """ Prepare an ontology for the dashboard by running ROBOT commands. From fb2bc61e8721cbfa81f5f1159e7673cce687704e Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 14 Oct 2024 16:56:46 -0300 Subject: [PATCH 7/9] Make make_base a keyword-only argument The boolean positional argument make_base can lead to unclear function calls, as it's not immediately apparent what the boolean value represents. --- util/lib.py | 1 + 1 file changed, 1 insertion(+) diff --git a/util/lib.py b/util/lib.py index e0fafcf..c30819e 100644 --- a/util/lib.py +++ b/util/lib.py @@ -348,6 +348,7 @@ def robot_prepare_ontology( o_out_path: str, o_metrics_path: str, base_iris: List[str], + *, make_base: bool, robot_prefixes: Optional[Dict[str, str]] = None, robot_opts="-v", From eeab0210eb41b68694ed5960d03e23b58df40e94 Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 14 Oct 2024 21:25:58 +0100 Subject: [PATCH 8/9] Use logging.exception for enhanced error reporting Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- util/lib.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/lib.py b/util/lib.py index 99294f6..b880d25 100644 --- a/util/lib.py +++ b/util/lib.py @@ -405,8 +405,7 @@ def robot_prepare_ontology( try: check_call(callstring) except subprocess.CalledProcessError as e: - logging.error("Preparing %s for dashboard failed: %s", o_path, str(e)) - + logging.exception("Preparing %s for dashboard failed: %s", o_path, str(e)) def count_up(dictionary, value): if value not in dictionary: From d37bf34eaab059b537ddb82d6488b2df096cf54f Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 14 Oct 2024 21:44:44 +0100 Subject: [PATCH 9/9] Remove redundant exception argument in logging.exception Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- util/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/lib.py b/util/lib.py index b880d25..916abb4 100644 --- a/util/lib.py +++ b/util/lib.py @@ -405,7 +405,7 @@ def robot_prepare_ontology( try: check_call(callstring) except subprocess.CalledProcessError as e: - logging.exception("Preparing %s for dashboard failed: %s", o_path, str(e)) + logging.exception("Preparing %s for dashboard failed", o_path) def count_up(dictionary, value): if value not in dictionary: