Skip to content

Commit 734eab7

Browse files
committed
use descriptive variable name key_string in normalize_key()
1 parent f5fc128 commit 734eab7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

scripts/1-fetch/internetarchive_fetch.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,24 @@ def normalize_license(licenseurl, license_mapping=None):
183183
return label
184184

185185

186-
def normalize_key(s):
187-
"""Normalize string for dictionary keys:
188-
NFKD, remove diacritics, punctuation, collapse spaces, lowercase."""
189-
if not s:
186+
def normalize_key(key_string):
187+
"""
188+
Normalize string for dictionary keys:
189+
NFKD, remove diacritics, punctuation, collapse spaces, lowercase
190+
"""
191+
if not key_string:
190192
return ""
191-
s = str(s)
192-
s = unicodedata.normalize("NFKD", s)
193-
s = "".join(ch for ch in s if not unicodedata.combining(ch))
194-
s = re.sub(
195-
r"[^\w\s\+\-/]", " ", s, flags=re.UNICODE
193+
key_string = str(key_string)
194+
key_string = unicodedata.normalize("NFKD", key_string)
195+
key_string = "".join(
196+
ch for ch in key_string if not unicodedata.combining(ch)
197+
)
198+
key_string = re.sub(
199+
r"[^\w\s\+\-/]", " ", key_string, flags=re.UNICODE
196200
) # keep + / - for splits
197-
if re.fullmatch(r"[a-zA-Z]{2,3}[-_][a-zA-Z]{2,3}", s.strip()):
198-
s = s.replace("_", "-")
199-
return s.strip().lower()
201+
if re.fullmatch(r"[a-zA-Z]{2,3}[-_][a-zA-Z]{2,3}", key_string.strip()):
202+
key_string = key_string.replace("_", "-")
203+
return key_string.strip().lower()
200204

201205

202206
def strip_noise(language):

0 commit comments

Comments
 (0)