srs_metadata_cleaning.py
def sifting_metadata_for_title_differences(list_of_row_lists):
    """
    Sifts fm and marc title values in metadata records to 
    look for potential indicators of discrepancies.

    The following Stack Overflow page was helpful in producing this function:
    "Merge Two Lists to Make List of Lists,"
    https://stackoverflow.com/questions/23327242/merge-two-lists-to-make-list-of-lists (accessed October 28, 2020)

    Parameters
    ----------
    list_of_row_lists: list
        A list of the metadata records returned
        from the original CSV.

    Returns
    ----------
    check_fm_and_marc_titles_for_differences: list
        A list with values indicating whether the fm and marc title values
        need to be checked for discrepancies manually.
    """


    fm_full_title_list = []
    marc_full_title_list = []
    check_fm_and_marc_titles_for_differences = []

    for row in list_of_row_lists:
        fm_full_title = str(row[1]).lower()
        clean_fm_full_title = fm_full_title.replace("/n", "")
        cleaner_fm_full_title = clean_fm_full_title.replace(" ", "")
        cleanest_fm_full_title = cleaner_fm_full_title.replace(":", "")
        ready_fm_full_title = cleanest_fm_full_title.replace(",", "")
        fm_full_title_list.append(ready_fm_full_title)

        marc_main_title = row[2]
        marc_subtitle = row[3]

        clean_marc_main_title = str(marc_main_title).lower()
        cleaner_marc_main_title = clean_marc_main_title.replace("\n", "")
        cleanest_marc_main_title = cleaner_marc_main_title.replace(" ", "")
        almost_ready_marc_main_title = cleanest_marc_main_title.replace(",", "")
        ready_marc_main_title = almost_ready_marc_main_title.replace(":", "")

        if marc_subtitle.endswith("/") == True:
            marc_subtitle = marc_subtitle[:-1]
            clean_marc_subtitle = str(marc_subtitle).lower()
            cleaner_marc_subtitle = clean_marc_subtitle.replace("\n", "")
            cleanest_marc_subtitle = cleaner_marc_subtitle.replace(" ", "")
            almost_ready_marc_subtitle = cleanest_marc_subtitle.replace(",", "")
            ready_marc_subtitle = almost_ready_marc_subtitle.replace(":", "")

        elif marc_subtitle.endswith("/") == False:
            clean_marc_subtitle = str(marc_subtitle).lower()
            cleaner_marc_subtitle = clean_marc_subtitle.replace("/n", "")
            cleanest_marc_subtitle = cleaner_marc_subtitle.replace(" ", "")
            almost_ready_marc_subtitle = cleanest_marc_subtitle.replace(",", "")
            ready_marc_subtitle = almost_ready_marc_subtitle.replace(":", "")

        marc_full_title = ready_marc_main_title + ready_marc_subtitle

        marc_full_title_list.append(marc_full_title)

        a = fm_full_title_list
        b = marc_full_title_list

        combined_title_values = [list(x) for x in zip(a, b)]

    for title_string_pairs in combined_title_values:       # Implementing conditions below to anticipate the "nan" that Python is adding to certain strings.

        if len(title_string_pairs[0]) == len(title_string_pairs[1]):

            if title_string_pairs[0] == title_string_pairs[1]:
                check_fm_and_marc_titles = "N"
                check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                continue
            elif title_string_pairs[0] != title_string_pairs[1]:
                check_fm_and_marc_titles = "YES"
                check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                continue

        elif len(title_string_pairs[0]) != len(title_string_pairs[1]):

            if title_string_pairs[1].endswith("nan"):

                if title_string_pairs[0] == title_string_pairs[1][:-3]:
                    check_fm_and_marc_titles = "N"
                    check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                    continue
                elif title_string_pairs[0] != title_string_pairs[1][:-3]:
                    check_fm_and_marc_titles = "YES"
                    check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                    continue

            else:
                check_fm_and_marc_titles = "YES"
                check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                continue

    return check_fm_and_marc_titles_for_differences

    Sifts fm and marc title values in metadata records to 
    look for potential indicators of discrepancies.

    The following Stack Overflow page was helpful in producing this function:
    "Merge Two Lists to Make List of Lists,"
    https://stackoverflow.com/questions/23327242/merge-two-lists-to-make-list-of-lists (accessed October 28, 2020)

    Parameters
    ----------
    list_of_row_lists: list
        A list of the metadata records returned
        from the original CSV.

    Returns
    ----------
    check_fm_and_marc_titles_for_differences: list
        A list with values indicating whether the fm and marc title values
        need to be checked for discrepancies manually.
    
Sifts fm and marc title values in metadata records to
look for potential indicators of discrepancies.


Sifts fm and marc title values in metadata records to look for potential indicators of discrepancies .
def sifting_metadata_for_title_differences(list_of_row_lists):
    fm_full_title_list = []
    marc_full_title_list = []
    check_fm_and_marc_titles_for_differences = []
    for row in list_of_row_lists:
        fm_full_title = str(row[1]).lower()
        clean_fm_full_title = fm_full_title.replace("/n", "")
        cleaner_fm_full_title = clean_fm_full_title.replace(" ", "")
        cleanest_fm_full_title = cleaner_fm_full_title.replace(":", "")
        ready_fm_full_title = cleanest_fm_full_title.replace(",", "")
        fm_full_title_list.append(ready_fm_full_title)
        marc_main_title = row[2]
        marc_subtitle = row[3]
        clean_marc_main_title = str(marc_main_title).lower()
        cleaner_marc_main_title = clean_marc_main_title.replace("\n", "")
        cleanest_marc_main_title = cleaner_marc_main_title.replace(" ", "")
        almost_ready_marc_main_title = cleanest_marc_main_title.replace(",", "")
        ready_marc_main_title = almost_ready_marc_main_title.replace(":", "")
        if marc_subtitle.endswith("/") == True:
            marc_subtitle = marc_subtitle[:-1]
            clean_marc_subtitle = str(marc_subtitle).lower()
            cleaner_marc_subtitle = clean_marc_subtitle.replace("\n", "")
            cleanest_marc_subtitle = cleaner_marc_subtitle.replace(" ", "")
            almost_ready_marc_subtitle = cleanest_marc_subtitle.replace(",", "")
            ready_marc_subtitle = almost_ready_marc_subtitle.replace(":", "")
        elif marc_subtitle.endswith("/") == False:
            clean_marc_subtitle = str(marc_subtitle).lower()
            cleaner_marc_subtitle = clean_marc_subtitle.replace("/n", "")
            cleanest_marc_subtitle = cleaner_marc_subtitle.replace(" ", "")
            almost_ready_marc_subtitle = cleanest_marc_subtitle.replace(",", "")
            ready_marc_subtitle = almost_ready_marc_subtitle.replace(":", "")
        marc_full_title = ready_marc_main_title + ready_marc_subtitle
        marc_full_title_list.append(marc_full_title)
        a = fm_full_title_list
        b = marc_full_title_list
        combined_title_values = [list(x) for x in zip(a, b)]
    for title_string_pairs in combined_title_values:       
        if len(title_string_pairs[0]) == len(title_string_pairs[1]):
            if title_string_pairs[0] == title_string_pairs[1]:
                check_fm_and_marc_titles = "N"
                check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                continue
            elif title_string_pairs[0] != title_string_pairs[1]:
                check_fm_and_marc_titles = "YES"
                check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                continue
        elif len(title_string_pairs[0]) != len(title_string_pairs[1]):
            if title_string_pairs[1].endswith("nan"):
                if title_string_pairs[0] == title_string_pairs[1][:-3]:
                    check_fm_and_marc_titles = "N"
                    check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                    continue
                elif title_string_pairs[0] != title_string_pairs[1][:-3]:
                    check_fm_and_marc_titles = "YES"
                    check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                    continue
            else:
                check_fm_and_marc_titles = "YES"
                check_fm_and_marc_titles_for_differences.append(check_fm_and_marc_titles)
                continue
    return check_fm_and_marc_titles_for_differences
def sifting_metadata_for_title_differences ( list_of_row_lists ) : fm_full_title_list = [ ] marc_full_title_list = [ ] check_fm_and_marc_titles_for_differences = [ ] for row in list_of_row_lists : fm_full_title = str ( row [ 1 ] ) . lower ( ) clean_fm_full_title = fm_full_title . replace ( "/n" , "" ) cleaner_fm_full_title = clean_fm_full_title . replace ( " " , "" ) cleanest_fm_full_title = cleaner_fm_full_title . replace ( ":" , "" ) ready_fm_full_title = cleanest_fm_full_title . replace ( "," , "" ) fm_full_title_list . append ( ready_fm_full_title ) marc_main_title = row [ 2 ] marc_subtitle = row [ 3 ] clean_marc_main_title = str ( marc_main_title ) . lower ( ) cleaner_marc_main_title = clean_marc_main_title . replace ( "\n" , "" ) cleanest_marc_main_title = cleaner_marc_main_title . replace ( " " , "" ) almost_ready_marc_main_title = cleanest_marc_main_title . replace ( "," , "" ) ready_marc_main_title = almost_ready_marc_main_title . replace ( ":" , "" ) if marc_subtitle . endswith ( "/" ) == True : marc_subtitle = marc_subtitle [ : - 1 ] clean_marc_subtitle = str ( marc_subtitle ) . lower ( ) cleaner_marc_subtitle = clean_marc_subtitle . replace ( "\n" , "" ) cleanest_marc_subtitle = cleaner_marc_subtitle . replace ( " " , "" ) almost_ready_marc_subtitle = cleanest_marc_subtitle . replace ( "," , "" ) ready_marc_subtitle = almost_ready_marc_subtitle . replace ( ":" , "" ) elif marc_subtitle . endswith ( "/" ) == False : clean_marc_subtitle = str ( marc_subtitle ) . lower ( ) cleaner_marc_subtitle = clean_marc_subtitle . replace ( "/n" , "" ) cleanest_marc_subtitle = cleaner_marc_subtitle . replace ( " " , "" ) almost_ready_marc_subtitle = cleanest_marc_subtitle . replace ( "," , "" ) ready_marc_subtitle = almost_ready_marc_subtitle . replace ( ":" , "" ) marc_full_title = ready_marc_main_title + ready_marc_subtitle marc_full_title_list . append ( marc_full_title ) a = fm_full_title_list b = marc_full_title_list combined_title_values = [ list ( x ) for x in zip ( a , b ) ] for title_string_pairs in combined_title_values : if len ( title_string_pairs [ 0 ] ) == len ( title_string_pairs [ 1 ] ) : if title_string_pairs [ 0 ] == title_string_pairs [ 1 ] : check_fm_and_marc_titles = "N" check_fm_and_marc_titles_for_differences . append ( check_fm_and_marc_titles ) continue elif title_string_pairs [ 0 ] != title_string_pairs [ 1 ] : check_fm_and_marc_titles = "YES" check_fm_and_marc_titles_for_differences . append ( check_fm_and_marc_titles ) continue elif len ( title_string_pairs [ 0 ] ) != len ( title_string_pairs [ 1 ] ) : if title_string_pairs [ 1 ] . endswith ( "nan" ) : if title_string_pairs [ 0 ] == title_string_pairs [ 1 ] [ : - 3 ] : check_fm_and_marc_titles = "N" check_fm_and_marc_titles_for_differences . append ( check_fm_and_marc_titles ) continue elif title_string_pairs [ 0 ] != title_string_pairs [ 1 ] [ : - 3 ] : check_fm_and_marc_titles = "YES" check_fm_and_marc_titles_for_differences . append ( check_fm_and_marc_titles ) continue else : check_fm_and_marc_titles = "YES" check_fm_and_marc_titles_for_differences . append ( check_fm_and_marc_titles ) continue return check_fm_and_marc_titles_for_differences
Sifts fm and marc title values in metadata records to
look for potential indicators of discrepancies.
Sifts fm and marc title values in metadata records to look for potential indicators of discrepancies .
"""
    Sifts fm and marc title values in metadata records to 
    look for potential indicators of discrepancies.

    The following Stack Overflow page was helpful in producing this function:
    "Merge Two Lists to Make List of Lists,"
    https://stackoverflow.com/questions/23327242/merge-two-lists-to-make-list-of-lists (accessed October 28, 2020)

    Parameters
    ----------
    list_of_row_lists: list
        A list of the metadata records returned
        from the original CSV.

    Returns
    ----------
    check_fm_and_marc_titles_for_differences: list
        A list with values indicating whether the fm and marc title values
        need to be checked for discrepancies manually.
    """ # Implementing conditions below to anticipate the "nan" that Python is adding to certain strings.

list_of_row_lists
A list of the metadata records returned
from the original CSV.
A list of the metadata records returned from the original CSV .
Returns

None
----------

None
check_fm_and_marc_titles_for_differences
A list with values indicating whether the fm and marc title values
need to be checked for discrepancies manually.
A list with values indicating whether the fm and marc title values need to be checked for discrepancies manually .