Skip to content

Commit

Permalink
Adding robot relax
Browse files Browse the repository at this point in the history
  • Loading branch information
caufieldjh committed Aug 16, 2024
1 parent 97b742b commit ef1ef05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/kg_bioportal/robot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def initialize_robot(robot_path: str) -> list:
return [robot_command, env]


def relax_ontology(
def robot_relax(
robot_path: str, input_path: str, output_path: str, robot_env: dict
) -> bool:
"""
Expand Down
26 changes: 20 additions & 6 deletions src/kg_bioportal/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import sys

from kg_bioportal.downloader import ONTOLOGY_LIST_NAME
from kg_bioportal.robot_utils import initialize_robot, robot_convert
from kg_bioportal.robot_utils import initialize_robot, robot_convert, robot_relax

# TODO: Don't repeat steps if the products already exist

class Transformer:

Expand Down Expand Up @@ -66,14 +67,14 @@ def transform_all(self) -> None:
]

if len(filepaths) == 0:
logging.ERROR(f"No ontologies found in {self.input_dir}.")
logging.error(f"No ontologies found in {self.input_dir}.")
sys.exit()
else:
logging.info(f"Found {len(filepaths)} ontologies to transform.")

for filepath in filepaths:
if not self.transform(filepath):
logging.ERROR(f"Error transforming {filepath}.")
logging.error(f"Error transforming {filepath}.")
else:
logging.info(f"Transformed {filepath}.")

Expand All @@ -92,14 +93,27 @@ def transform(self, ontology: str) -> bool:

logging.info(f"Transforming {ontology} to nodes and edges.")
ontology_name = os.path.splitext(os.path.basename(ontology))[0]
output_path = os.path.join(self.output_dir, f"{ontology_name}.json")
json_output_path = os.path.join(self.output_dir, f"{ontology_name}.json")

# Convert
if not robot_convert(
robot_path=self.robot_path,
input_path=ontology,
output_path=output_path,
output_path=json_output_path,
robot_env=self.robot_env,
):
status = False
status = True

# Relax
relaxed_outpath = os.path.join(self.output_dir, f"{ontology_name}_relaxed.json")
if not robot_relax(
robot_path=self.robot_path,
input_path=json_output_path,
output_path=relaxed_outpath,
robot_env=self.robot_env,
):
status = False
else:
status = True

return status

0 comments on commit ef1ef05

Please sign in to comment.