# Path: indra/ontology/standardize.py
# def standardize_db_refs(db_refs, ontology=None, ns_order=None):
#     """Return a standardized db refs dict for a given db refs dict.
# 
#     Parameters
#     ----------
#     db_refs : dict
#         A dict of db refs that may not be standardized, i.e., may be
#         missing an available UP ID corresponding to an existing HGNC ID.
#     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
#     -------
#     dict
#         The db_refs dict with standardized entries.
#     """
#     if ontology is None:
#         from indra.ontology.bio import bio_ontology
#         ontology = bio_ontology
# 
#     # We iterate over all the db_refs entries that currently exist
#     for source_db_ns, source_db_id in deepcopy(db_refs).items():
#         source_db_id = _preprocess_for_mapping(source_db_ns, source_db_id)
#         # If there is a replacement for this entry, we apply it
#         replacement = ontology.get_replacement(source_db_ns, source_db_id)
#         if replacement:
#             source_db_ns, source_db_id = replacement
#             db_refs[source_db_ns] = source_db_id
#         # For the entry we get all its xref mappings as a list
#         # of tuples and turn it into a dict keyed by namespace
#         mappings = _get_mappings_dict(
#             ontology.get_mappings(source_db_ns, source_db_id))
#         # We iterate over these mappings and check if they should
#         # be applied
#         for mapped_db_ns, mapped_db_ids in mappings.items():
#             # If the db_refs doesn't yet contain a mapping for this
#             # name space then we always add this mapping. If there
#             # is already an entry for this name space then
#             # we overwrite it if the source name space is higher
#             # priority than the name space being mapped to.
#             if mapped_db_ns not in db_refs or \
#                     prioritize(mapped_db_ns, source_db_ns,
#                                ns_order=ns_order):
#                 db_refs[mapped_db_ns] = sorted(mapped_db_ids)[0]
#     return db_refs


import re
import logging
from indra.statements import BioContext, RefContext
from indra.ontology.bio import bio_ontology
from indra.ontology.standardize import \
    standardize_db_refs
            from indra.sources import reach
            from indra.sources import bel
            from gilda import ground
        for stmt in rp.statements:
            # There is expected to be exactly one evidence in all cases
            # but this is still a good way to work with it
            for ev in stmt.evidence:
                ev.source_api = 'hypothes.is'
                ev.text = text
                ev.text_refs = text_refs
                if 'PMID' in text_refs:
                    ev.pmid = text_refs['PMID']
                ev.annotations['hypothes.is'] = annotation
                ev.context = bio_context
        return rp.statements


def parse_context_entry(entry, grounder, sentence=None):
    """Return a dict of context type and object processed from an entry."""
    match = re.match(r'(.*): (.*)', entry)
    if not match:
        return None
    context_type, context_txt = match.groups()
    if context_type not in allowed_contexts:
        logger.warning('Unknown context type %s' % context_type)
        return None

    terms = grounder(context_txt, context=sentence)
    if not terms:
        logger.warning('Could not ground %s context: %s'
                       % (context_type, context_txt))
    db_refs = {}
    if terms:

# Path: indra/ontology/standardize.py
# def standardize_db_refs(db_refs, ontology=None, ns_order=None):
#     """Return a standardized db refs dict for a given db refs dict.
# 
#     Parameters
#     ----------
#     db_refs : dict
#         A dict of db refs that may not be standardized, i.e., may be
#         missing an available UP ID corresponding to an existing HGNC ID.
#     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
#     -------
#     dict
#         The db_refs dict with standardized entries.
#     """
#     if ontology is None:
#         from indra.ontology.bio import bio_ontology
#         ontology = bio_ontology
# 
#     # We iterate over all the db_refs entries that currently exist
#     for source_db_ns, source_db_id in deepcopy(db_refs).items():
#         source_db_id = _preprocess_for_mapping(source_db_ns, source_db_id)
#         # If there is a replacement for this entry, we apply it
#         replacement = ontology.get_replacement(source_db_ns, source_db_id)
#         if replacement:
#             source_db_ns, source_db_id = replacement
#             db_refs[source_db_ns] = source_db_id
#         # For the entry we get all its xref mappings as a list
#         # of tuples and turn it into a dict keyed by namespace
#         mappings = _get_mappings_dict(
#             ontology.get_mappings(source_db_ns, source_db_id))
#         # We iterate over these mappings and check if they should
#         # be applied
#         for mapped_db_ns, mapped_db_ids in mappings.items():
#             # If the db_refs doesn't yet contain a mapping for this
#             # name space then we always add this mapping. If there
#             # is already an entry for this name space then
#             # we overwrite it if the source name space is higher
#             # priority than the name space being mapped to.
#             if mapped_db_ns not in db_refs or \
#                     prioritize(mapped_db_ns, source_db_ns,
#                                ns_order=ns_order):
#                 db_refs[mapped_db_ns] = sorted(mapped_db_ids)[0]
#     return db_refs


# Path: indra/sources/hypothesis/processor.py
import re
import logging
from indra.statements import BioContext, RefContext
from indra.ontology.bio import bio_ontology
from indra.ontology.standardize import \
    standardize_db_refs
            from indra.sources import reach
            from indra.sources import bel
            from gilda import ground

        for stmt in rp.statements:
            # There is expected to be exactly one evidence in all cases
            # but this is still a good way to work with it
            for ev in stmt.evidence:
                ev.source_api = 'hypothes.is'
                ev.text = text
                ev.text_refs = text_refs
                if 'PMID' in text_refs:
                    ev.pmid = text_refs['PMID']
                ev.annotations['hypothes.is'] = annotation
                ev.context = bio_context
        return rp.statements


def parse_context_entry(entry, grounder, sentence=None):
    """Return a dict of context type and object processed from an entry."""
    match = re.match(r'(.*): (.*)', entry)
    if not match:
        return None
    context_type, context_txt = match.groups()
    if context_type not in allowed_contexts:
        logger.warning('Unknown context type %s' % context_type)
        return None

    terms = grounder(context_txt, context=sentence)
    if not terms:
        logger.warning('Could not ground %s context: %s'
                       % (context_type, context_txt))
    db_refs = {}
    if terms:

        db_refs = standardize_db_refs({terms[0].term.db: