Exemplo n.º 1
0
 def __init__(self):
     self.logger = set_up_logging(__name__)
Exemplo n.º 2
0
from app.common.logger import set_up_logging
logger = set_up_logging(__name__)


def get_all_replacements(doc):
    """Obtain the references from neuralcoref reference clusters
     and recursively check if a reference is contained in other reference cluster and replace it

        Parameters
        ----------
        doc : Spacy tokens doc
            An instance of spacy doc with an instance of spacy token for each word in the text

        Returns
        -------
        list
            list of dictionaries, each dictionary contains the information of a replacement
    """

    logger.info("************ Getting replacements")
    replacement_list = sorted(get_initial_replacement(doc),
                              key=lambda x: x['initial_index'][0])
    replacement_list_aux = ""
    count = 0
    while replacement_list_aux != str(replacement_list):
        count += 1
        replacement_list_aux = str(replacement_list)
        check_replacements(replacement_list)
        if count > 10:
            replacement_list = sorted(get_initial_replacement(doc),
                                      key=lambda x: x['initial_index'][0])