wikit-ai / olaf

6 stars 1 forks source link

fix: candidate_terms_tools.find_synonym_candidates #22

Closed ba-talibe closed 5 months ago

ba-talibe commented 5 months ago

There is an index issue. We sometime end up with IndexError: list index out of range coming from (See full error at the end):

check_common_synonyms = cts_have_common_synonyms(
            reference_ct, candidate_terms[i]
        )

Some thoughts:

Full error:


olaf\pipeline\pipeline_component\concept_relation_extraction\synonym_concept_extraction.py:70: in run
    concept_candidates = group_cts_on_synonyms(pipeline.candidate_terms)
olaf\commons\candidate_term_tools.py:34: in group_cts_on_synonyms
    find_synonym_candidates(reference_term, candidate_terms, common_candidates)

def find_synonym_candidates(
        reference_ct: CandidateTerm,
        candidate_terms: List[CandidateTerm],
        common_candidates: Set[CandidateTerm],
    ) -> None:
        """Find candidate terms with common synonyms based on
        the reference term and group them in the a set.
        If the candidate terms are candidate relations,
        they should have the same source and destination concepts.

        Parameters
        ----------
        reference_ct : CandidateTerm
            Candidate term used as reference to start the synonym search with.
        candidate_terms : List[CandidateTerm]
            List of candidate terms to compare with the reference term.
        common_candidates : Set[CandidateTerm]
            Set of candidate terms with common synonyms.
        """
        i = 0
        while i < len(candidate_terms):
            check_source_destination = True
            if isinstance(reference_ct, CandidateRelation):
                check_source_destination = (
                    reference_ct.source_concept == candidate_terms[i].source_concept
                    and reference_ct.destination_concept
                    == candidate_terms[i].destination_concept
                )
            check_common_synonyms = cts_have_common_synonyms(
>               reference_ct, candidate_terms[i]
            )
E           IndexError: list index out of range

olaf\commons\candidate_term_tools.py:69: IndexError