Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove run ROBOT mesure on full ontology #135

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
84 changes: 57 additions & 27 deletions util/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -342,41 +343,70 @@ 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: str,
o_out_path: str,
o_metrics_path: str,
base_iris: List[str],
*,
make_base: bool,
anitacaron marked this conversation as resolved.
Show resolved Hide resolved
robot_prefixes: Optional[Dict[str, str]] = None,
robot_opts: str = "-v",
) -> None:
"""
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)

callstring = ["robot", "merge", "-i", o_path]

if robot_opts:
anitacaron marked this conversation as resolved.
Show resolved Hide resolved
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",]
anitacaron marked this conversation as resolved.
Show resolved Hide resolved
)

# 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 subprocess.CalledProcessError as e:
logging.error("Preparing %s for dashboard failed: %s", o_path, str(e))

anitacaron marked this conversation as resolved.
Show resolved Hide resolved

def count_up(dictionary, value):
if value not in dictionary:
Expand Down
Loading