Skip to content

verbatim_term_mapper

VerbatimTermMapper

Maps a source term to a provided subset of target concepts based on exact matches of normalized terms.

Source code in src/ariadne/verbatim_mapping/verbatim_term_mapper.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class VerbatimTermMapper:
    """
    Maps a source term to a provided subset of target concepts based on exact matches of normalized terms.
    """

    def __init__(self, config: Config = Config()):
        self.term_normalizer = TermNormalizer(config)

    def map_term(
        self,
        source_term: str,
        target_concept_ids: List[int],
        target_terms: List[str],
        target_synonyms: List[str],
    ) -> (Union[int, None], Union[str, None]):
        """
        Maps a source term to the best matching target concept ID based on normalized terms.

        Args:
            source_term: the source clinical term to map
            target_concept_ids: a list of target concept IDs
            target_terms: a list of target clinical terms
            target_synonyms: a list of target synonyms. Each string is semicolon separated synonyms for the
                corresponding target term.

        Returns:
            A tuple of (mapped_concept_id, mapped_term) if a match is found, otherwise (None, None)
        """
        normalized_source = self.term_normalizer.normalize_term(source_term)
        for concept_id, term, synonyms in zip(
            target_concept_ids, target_terms, target_synonyms
        ):
            normalized_term = self.term_normalizer.normalize_term(term)
            if normalized_source == normalized_term:
                return concept_id, term
            if not pd.isna(synonyms):
                for synonym in synonyms.split(";"):
                    normalized_synonym = self.term_normalizer.normalize_term(synonym)
                    if normalized_source == normalized_synonym:
                        return concept_id, term
        return None, None

map_term(source_term, target_concept_ids, target_terms, target_synonyms)

Maps a source term to the best matching target concept ID based on normalized terms.

Parameters:

Name Type Description Default
source_term str

the source clinical term to map

required
target_concept_ids List[int]

a list of target concept IDs

required
target_terms List[str]

a list of target clinical terms

required
target_synonyms List[str]

a list of target synonyms. Each string is semicolon separated synonyms for the corresponding target term.

required

Returns:

Type Description
(Union[int, None], Union[str, None])

A tuple of (mapped_concept_id, mapped_term) if a match is found, otherwise (None, None)

Source code in src/ariadne/verbatim_mapping/verbatim_term_mapper.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def map_term(
    self,
    source_term: str,
    target_concept_ids: List[int],
    target_terms: List[str],
    target_synonyms: List[str],
) -> (Union[int, None], Union[str, None]):
    """
    Maps a source term to the best matching target concept ID based on normalized terms.

    Args:
        source_term: the source clinical term to map
        target_concept_ids: a list of target concept IDs
        target_terms: a list of target clinical terms
        target_synonyms: a list of target synonyms. Each string is semicolon separated synonyms for the
            corresponding target term.

    Returns:
        A tuple of (mapped_concept_id, mapped_term) if a match is found, otherwise (None, None)
    """
    normalized_source = self.term_normalizer.normalize_term(source_term)
    for concept_id, term, synonyms in zip(
        target_concept_ids, target_terms, target_synonyms
    ):
        normalized_term = self.term_normalizer.normalize_term(term)
        if normalized_source == normalized_term:
            return concept_id, term
        if not pd.isna(synonyms):
            for synonym in synonyms.split(";"):
                normalized_synonym = self.term_normalizer.normalize_term(synonym)
                if normalized_source == normalized_synonym:
                    return concept_id, term
    return None, None