Last active
February 22, 2024 09:58
-
-
Save HoffmannP/6ab67c7133edab5b3b01760a3f226a25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import re | |
IGNORE_BEGINNING = True | |
allUppercase = re.compile(r'[A-ZÄÜÖ][A-ZÄÜÖ]+') | |
matchLetters = re.compile(r'[a-zäüößA-ZÄÜÖ]') | |
matchUCLetters = re.compile(r'[A-ZÄÜÖ]') | |
# Source https://www.biblesupersearch.com/bible-downloads/ | |
for name in ['kjv.txt', 'luther.txt']: | |
letters = 0 | |
ucletters = 0 | |
with open(name) as f: | |
for line in f: | |
words = line.split(' ') | |
if len(words) < 4: | |
continue | |
first_word = 2 | |
if ':' in words[first_word]: | |
first_word += 1 | |
if words[first_word] == '¶': | |
first_word += 1 | |
if IGNORE_BEGINNING: | |
first_word += 1 | |
sentence = ' '.join( | |
filter( | |
lambda word: allUppercase.match(word) is None, | |
words[first_word:])) | |
letters += len(matchLetters.findall(sentence)) | |
ucletters += len(matchUCLetters.findall(sentence)) | |
book_name = name.split(".")[0] | |
percentage = 100 * ucletters / letters | |
print(f'{book_name}:\t{percentage:.1f}%\t({letters}/{ucletters})') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated cleaning of the lines again and downloaded another version (machine readable instead of plain text which has hard line breaks):