"""Select SCOWL's English vocabulary without importing its personal-name lists.""" import tarfile import unicodedata def terms(source): words = set() with tarfile.open(source) as archive: for member in archive.getmembers(): category, _, size = member.name.rsplit("/", 1)[-1].rpartition(".") if not member.isfile() or "/final/" not in member.name or not size.isdigit(): continue # SCOWL's upper lists at level 50 and above include personal names # such as Aaron and Xavier. Level 35 retains weekdays/languages. selected = (int(size) <= 80 and category.endswith(("-words", "-contractions"))) or (int(size) <= 35 and category.endswith("-upper")) if selected: for term in archive.extractfile(member).read().decode("latin-1").splitlines(): term = unicodedata.normalize("NFC", term.lower().replace("’", "'")) if not term or not all(c.isalpha() or c in "'-" for c in term): raise ValueError(f"Invalid SCOWL term shape: {term!r}") words.add(term) return sorted(words)