# Path: indra/ontology/standardize.py
# def standardize_agent_name(agent, standardize_refs=True, ontology=None,
#                            ns_order=None):
#     """Standardize the name of an Agent based on grounding information.
# 
#     The priority of which namespace is used as the bases for the
#     standard name depends on
# 
#     Parameters
#     ----------
#     agent : indra.statements.Agent
#         An INDRA Agent whose name attribute should be standardized based
#         on grounding information.
#     standardize_refs : Optional[bool]
#         If True, this function assumes that the Agent's db_refs need to
#         be standardized, e.g., HGNC mapped to UP.
#         Default: True
#     ontology : Optional[indra.ontology.IndraOntology]
#         An IndraOntology object, if not provided, the default BioOntology
#         is used.
#     ns_order : Optional[list]
#         A list of namespaces which are in order of priority with higher
#         priority namespaces appearing earlier in the list.
# 
#     Returns
#     -------
#     bool
#         True if a new name was set, False otherwise.
#     """
#     # If the Agent is None, we return immediately
#     if agent is None:
#         return False
#     # If we want to standardize the Agent's db_refs, we call this now
#     if standardize_refs:
#         agent.db_refs = standardize_db_refs(agent.db_refs, ontology=ontology)
#     # We next try to get a standard name based on the Agent's grounding
#     standard_name = get_standard_name(agent.db_refs, ontology=ontology,
#                                       ns_order=ns_order)
#     # If we got a proper standard name, we apply it
#     if standard_name:
#         agent.name = standard_name
#         return True
#     return False
# 
# Path: indra/config.py
# def get_config(key, failure_ok=True):
#     """Get value by key from config file or environment.
# 
#     Returns the configuration value, first checking the environment
#     variables and then, if it's not present there, checking the configuration
#     file.
# 
#     Parameters
#     ----------
#     key : str
#         The key for the configuration value to fetch
#     failure_ok : Optional[bool]
#         If False and the configuration is missing, an IndraConfigError is
#         raised. If True, None is returned and no error is raised in case
#         of a missing configuration. Default: True
# 
#     Returns
#     -------
#     value : str or None
#         The configuration value or None if the configuration value doesn't
#         exist and failure_ok is set to True.
#     """
#     err_msg = "Key %s not in environment or config file." % key
#     if key in os.environ:
#         return os.environ[key]
#     elif key in CONFIG_DICT:
#         val = CONFIG_DICT[key]
#         # We interpret an empty value in the config file as a failure
#         if val is None and not failure_ok:
#             msg = 'Key %s is set to an empty value in config file.' % key
#             raise IndraConfigError(msg)
#         else:
#             return val
#     elif not failure_ok:
#         raise IndraConfigError(err_msg)
#     else:
#         return None
# 
# def has_config(key):
#     """Returns whether the configuration value for the given kehy is present.
# 
#     Parameters
#     ----------
#     key : str
#         The key for the configuration value to fetch
# 
#     Returns
#     -------
#     value : bool
#         Whether the configuration value is present
#     """
#     return get_config(key, failure_ok=True) is not None


import logging
import requests
from copy import deepcopy
from typing import Any, Callable, List, Mapping, Optional, Tuple
from urllib.parse import urljoin
from indra.ontology.standardize \
    import standardize_agent_name
from indra.config import get_config, has_config
from indra.pipeline import register_pipeline
        from gilda import ground
        from gilda import get_models
"""This module implements a client to the Gilda grounding web service,
and contains functions to help apply it during the course of INDRA assembly."""



logger = logging.getLogger(__name__)

grounding_service_url = get_config('GILDA_URL', failure_ok=True) \
    if has_config('GILDA_URL') else 'http://grounding.indra.bio/'



# Path: indra/ontology/standardize.py
# def standardize_agent_name(agent, standardize_refs=True, ontology=None,
#                            ns_order=None):
#     """Standardize the name of an Agent based on grounding information.
# 
#     The priority of which namespace is used as the bases for the
#     standard name depends on
# 
#     Parameters
#     ----------
#     agent : indra.statements.Agent
#         An INDRA Agent whose name attribute should be standardized based
#         on grounding information.
#     standardize_refs : Optional[bool]
#         If True, this function assumes that the Agent's db_refs need to
#         be standardized, e.g., HGNC mapped to UP.
#         Default: True
#     ontology : Optional[indra.ontology.IndraOntology]
#         An IndraOntology object, if not provided, the default BioOntology
#         is used.
#     ns_order : Optional[list]
#         A list of namespaces which are in order of priority with higher
#         priority namespaces appearing earlier in the list.
# 
#     Returns
#     -------
#     bool
#         True if a new name was set, False otherwise.
#     """
#     # If the Agent is None, we return immediately
#     if agent is None:
#         return False
#     # If we want to standardize the Agent's db_refs, we call this now
#     if standardize_refs:
#         agent.db_refs = standardize_db_refs(agent.db_refs, ontology=ontology)
#     # We next try to get a standard name based on the Agent's grounding
#     standard_name = get_standard_name(agent.db_refs, ontology=ontology,
#                                       ns_order=ns_order)
#     # If we got a proper standard name, we apply it
#     if standard_name:
#         agent.name = standard_name
#         return True
#     return False
# 
# Path: indra/config.py
# def get_config(key, failure_ok=True):
#     """Get value by key from config file or environment.
# 
#     Returns the configuration value, first checking the environment
#     variables and then, if it's not present there, checking the configuration
#     file.
# 
#     Parameters
#     ----------
#     key : str
#         The key for the configuration value to fetch
#     failure_ok : Optional[bool]
#         If False and the configuration is missing, an IndraConfigError is
#         raised. If True, None is returned and no error is raised in case
#         of a missing configuration. Default: True
# 
#     Returns
#     -------
#     value : str or None
#         The configuration value or None if the configuration value doesn't
#         exist and failure_ok is set to True.
#     """
#     err_msg = "Key %s not in environment or config file." % key
#     if key in os.environ:
#         return os.environ[key]
#     elif key in CONFIG_DICT:
#         val = CONFIG_DICT[key]
#         # We interpret an empty value in the config file as a failure
#         if val is None and not failure_ok:
#             msg = 'Key %s is set to an empty value in config file.' % key
#             raise IndraConfigError(msg)
#         else:
#             return val
#     elif not failure_ok:
#         raise IndraConfigError(err_msg)
#     else:
#         return None
# 
# def has_config(key):
#     """Returns whether the configuration value for the given kehy is present.
# 
#     Parameters
#     ----------
#     key : str
#         The key for the configuration value to fetch
# 
#     Returns
#     -------
#     value : bool
#         Whether the configuration value is present
#     """
#     return get_config(key, failure_ok=True) is not None


# Path: indra/preassembler/grounding_mapper/gilda.py
import logging
import requests
from copy import deepcopy
from typing import Any, Callable, List, Mapping, Optional, Tuple
from urllib.parse import urljoin
from indra.ontology.standardize \
    import standardize_agent_name
from indra.config import get_config, has_config
from indra.pipeline import register_pipeline
        from gilda import ground
        from gilda import get_models

"""This module implements a client to the Gilda grounding web service,
and contains functions to help apply it during the course of INDRA assembly."""



logger = logging.getLogger(__name__)

grounding_service_url = get_config('GILDA_URL', failure_ok=True) \
    if has_config('GILDA_URL') else 'http://grounding.indra.bio/'



def get_grounding(