Skip to content
65 changes: 39 additions & 26 deletions util/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
logging.error("Preparing %s for dashboard failed: %s", o_path, str(e))


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