playground/compound_disease/transfer_learning_experiment/data/label_functions/compound_disease_lf.py
def LF_CD_CHECK_DISEASE_TAG(c):
    """
    This label function is used for labeling each passed candidate as either pos or neg.
    Keyword Args:
    c- the candidate object to be passed in.
    """
    sen = c[1].get_parent()
    disease_name = re.sub("\) ?", "", c[1].get_span())
    disease_name = re.sub(r"(\w)-(\w)", r"\g<1> \g<2>", disease_name)
    disease_name = " ".join([word for word in word_tokenize(disease_name) if word not in set(stop_word_list)])

    # If abbreviation skip since no means of easy resolution
    if len(disease_name) <=5 and disease_name.isupper():
        return 0

    disease_id = sen.entity_cids[c[1].get_word_start()]
    result = disease_normalization_df[
        disease_normalization_df["subsumed_name"].str.contains(disease_name.lower(), regex=False)
    ]
    # If no match then return -1
    if result.empty:

        # check the reverse direction e.g. carcinoma lung -> lung carcinoma
        disease_name_tokens = word_tokenize(disease_name)
        if len(disease_name_tokens) == 2:
            result = disease_normalization_df[
                disease_normalization_df["subsumed_name"].str.contains(" ".join(disease_name_tokens[-1::0-1]).lower(), regex=False)
            ]
            
            # if reversing doesn't work then output -t
            if not result.empty:
                slim_id = result['slim_id'].values[0]
                if slim_id == disease_id:
                    return 0
        return -1
    else:
        # If it can be normalized return 0 else -1
        slim_id = result['slim_id'].values[0]
        if slim_id == disease_id:
            return 0
        else:
            return -1

    This label function is used for labeling each passed candidate as either pos or neg.
    Keyword Args:
    c- the candidate object to be passed in.
    
This label function is used for labeling each passed candidate as either pos or neg.
Keyword Args:
c- the candidate object to be passed in.
This label function is used for labeling each passed candidate as either pos or neg . Keyword Args : c - the candidate object to be passed in .
def LF_CD_CHECK_DISEASE_TAG(c):
    sen = c[1].get_parent()
    disease_name = re.sub("\) ?", "", c[1].get_span())
    disease_name = re.sub(r"(\w)-(\w)", r"\g<1> \g<2>", disease_name)
    disease_name = " ".join([word for word in word_tokenize(disease_name) if word not in set(stop_word_list)])
    if len(disease_name) <=5 and disease_name.isupper():
        return 0
    disease_id = sen.entity_cids[c[1].get_word_start()]
    result = disease_normalization_df[
        disease_normalization_df["subsumed_name"].str.contains(disease_name.lower(), regex=False)
    ]
    if result.empty:
        disease_name_tokens = word_tokenize(disease_name)
        if len(disease_name_tokens) == 2:
            result = disease_normalization_df[
                disease_normalization_df["subsumed_name"].str.contains(" ".join(disease_name_tokens[-1::0-1]).lower(), regex=False)
            ]
            if not result.empty:
                slim_id = result['slim_id'].values[0]
                if slim_id == disease_id:
                    return 0
        return -1
    else:
        slim_id = result['slim_id'].values[0]
        if slim_id == disease_id:
            return 0
        else:
            return -1
def LF_CD_CHECK_DISEASE_TAG ( c ) : sen = c [ 1 ] . get_parent ( ) disease_name = re . sub ( "\) ?" , "" , c [ 1 ] . get_span ( ) ) disease_name = re . sub ( r"(\w)-(\w)" , r"\g<1> \g<2>" , disease_name ) disease_name = " " . join ( [ word for word in word_tokenize ( disease_name ) if word not in set ( stop_word_list ) ] ) if len ( disease_name ) <= 5 and disease_name . isupper ( ) : return 0 disease_id = sen . entity_cids [ c [ 1 ] . get_word_start ( ) ] result = disease_normalization_df [ disease_normalization_df [ "subsumed_name" ] . str . contains ( disease_name . lower ( ) , regex = False ) ] if result . empty : disease_name_tokens = word_tokenize ( disease_name ) if len ( disease_name_tokens ) == 2 : result = disease_normalization_df [ disease_normalization_df [ "subsumed_name" ] . str . contains ( " " . join ( disease_name_tokens [ - 1 : : 0 - 1 ] ) . lower ( ) , regex = False ) ] if not result . empty : slim_id = result [ 'slim_id' ] . values [ 0 ] if slim_id == disease_id : return 0 return - 1 else : slim_id = result [ 'slim_id' ] . values [ 0 ] if slim_id == disease_id : return 0 else : return - 1
This label function is used for labeling each passed candidate as either pos or neg.
This label function is used for labeling each passed candidate as either pos or neg .
"""
    This label function is used for labeling each passed candidate as either pos or neg.
    Keyword Args:
    c- the candidate object to be passed in.
    """ # If abbreviation skip since no means of easy resolution # If no match then return -1 # check the reverse direction e.g. carcinoma lung -> lung carcinoma # if reversing doesn't work then output -t # If it can be normalized return 0 else -1
c