Skip to content

Instantly share code, notes, and snippets.

@HoffmannP
Last active February 22, 2024 09:58
Show Gist options
  • Select an option

  • Save HoffmannP/6ab67c7133edab5b3b01760a3f226a25 to your computer and use it in GitHub Desktop.

Select an option

Save HoffmannP/6ab67c7133edab5b3b01760a3f226a25 to your computer and use it in GitHub Desktop.
#!/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})')
@HoffmannP

HoffmannP commented Feb 22, 2024

Copy link
Copy Markdown
Author

Updated cleaning of the lines again and downloaded another version (machine readable instead of plain text which has hard line breaks):

kjv:	1.9%	(3090749/57577)
luther:	5.2%	(2993877/156041)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment