From 4d5696c4cbd85468d868743c7f457f8405499e2d Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Sun, 5 Dec 2021 16:21:44 +0200 Subject: [PATCH] csv_metadata_quality/check.py: update title in citation check Initialize the titles and citations before the for loop so we can access them later. This makes it easier to check if the item actua- lly has a citation. --- csv_metadata_quality/check.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/csv_metadata_quality/check.py b/csv_metadata_quality/check.py index 3f219c2..69f9126 100755 --- a/csv_metadata_quality/check.py +++ b/csv_metadata_quality/check.py @@ -419,6 +419,11 @@ def title_in_citation(row): Function prints a warning if the title does not appear in the citation. """ + # Initialize some variables at global scope so that we can set them in the + # loop scope below and still be able to access them afterwards. + title = "" + citation = "" + # Iterate over the labels of the current row's values to get the names of # the title and citation columns. Then we check if the title is present in # the citation. @@ -430,17 +435,15 @@ def title_in_citation(row): # Find the name of the title column match = re.match(r"^(dc|dcterms)\.title.*$", label) if match is not None: - title_column_name = label + title = row[label] # Find the name of the citation column match = re.match(r"^.*?[cC]itation.*$", label) if match is not None: - citation_column_name = label + citation = row[label] - if row[citation_column_name] != "": - if row[title_column_name] not in row[citation_column_name]: - print( - f"{Fore.YELLOW}Title is not present in citation: {Fore.RESET}{row[title_column_name]}" - ) + if citation != "": + if title not in citation: + print(f"{Fore.YELLOW}Title is not present in citation: {Fore.RESET}{title}") return