From bef7224f6de60258efd8f568c0d1471c25f66543 Mon Sep 17 00:00:00 2001 From: Ben Gyori Date: Fri, 6 Dec 2024 10:53:49 -0700 Subject: [PATCH] Add simpler client function for is_ontological_child --- mira/metamodel/utils.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/mira/metamodel/utils.py b/mira/metamodel/utils.py index 628585b79..a09f2507e 100644 --- a/mira/metamodel/utils.py +++ b/mira/metamodel/utils.py @@ -3,10 +3,13 @@ import sympy import re +import os import unicodedata -from typing import Any +from typing import Any, Optional from functools import lru_cache +import requests + from pydantic import GetCoreSchemaHandler from pydantic_core import core_schema @@ -102,3 +105,27 @@ def sanity_check_tm(tm): all_initial_names = {init.concept.name for init in tm.initials.values()} for concept in all_concept_names: assert concept in all_initial_names, f"missing initial condition for {concept}" + + +def is_ontological_child(child_curie: str, parent_curie: str, + api_url: Optional[str] = None): + if api_url: + base_url = api_url + elif os.environ.get("MIRA_REST_URL"): + base_url = os.environ.get("MIRA_REST_URL") + else: + try: + import pystow + base_url = pystow.get_config("mira", "rest_url") + except ImportError: + raise ValueError("api_url must be provided or MIRA_REST_URL must be set.") + base_url = base_url.rstrip("/") + "/api" \ + if not base_url.endswith("/api") else base_url + endpoint_url = base_url + '/is_ontological_child' + + res = requests.post(endpoint_url, json={"child_curie": child_curie, + "parent_curie": parent_curie}) + + res.raise_for_status() + res_json = res.json() + return res_json['is_child']