MarcoP > 14-10-2023, 07:53 AM
bi3mw > 14-10-2023, 04:07 PM
#!/usr/bin/env python
import re
import sys
import pyphen
def calculate_syllable_statistics(text, dic):
total_letters = len(re.sub(r'[^\w\s]', '', text)) # Count letters and spaces
syllables = dic.inserted(text).split('-')
total_syllables = len([s for s in syllables if s]) # Filter out empty syllables
lines = text.split('\n')
last_word_syllables = 0
total_lines = len(lines)
for line in lines:
words = line.split()
if words:
last_word = words[-1]
last_word_syllables += len([s for s in dic.inserted(last_word).split('-') if s])
total_words = sum(len(line.split()) for line in lines)
average_syllables_per_word = total_syllables / total_words if total_words > 0 else 0
average_syllables_per_line = last_word_syllables / total_lines if total_lines > 0 else 0
# Calculate the percentage using the rule of three
syllable_percentage = (total_syllables * 100) / total_letters
return total_syllables, total_letters, syllable_percentage, average_syllables_per_word, last_word_syllables, average_syllables_per_line
def detect_syllables_in_file(filename):
print("Processing, please wait...") # Meldung hinzufügen
try:
with open(filename, 'r', encoding='utf-8') as file:
text = file.read()
dic = pyphen.Pyphen(lang='it_IT')
total_syllables, total_letters, syllable_percentage, average_syllables_per_word, last_word_syllables, average_syllables_per_line = calculate_syllable_statistics(text, dic)
# Ausgabe in der Konsole
print(f"Total letters and spaces: {total_letters}")
print(f"Total syllables: {total_syllables}")
print(f"Syllable percentage: {syllable_percentage:.9f}%")
print(f"Average syllables per word: {average_syllables_per_word:.9f}")
print(f"Total syllables in last words of lines: {last_word_syllables}")
print(f"Average syllables per line (last words): {average_syllables_per_line:.9f}")
# Erstellung der Ausgabedatei für die Silben der letzten Wörter
output_filename = "last_word_syllables.txt"
with open(output_filename, 'w', encoding='utf-8') as output_file:
lines = text.split('\n')
for line in lines:
words = line.split()
if words:
last_word = words[-1]
last_word_syllables = [s for s in dic.inserted(last_word).split('-') if s]
# Schreibe die Silben der letzten Wörter getrennt durch Kommas
last_word_syllables_str = ','.join(last_word_syllables)
output_file.write(last_word_syllables_str + '\n')
except FileNotFoundError:
print(f"Error: File '{filename}' not found.")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python syllable_detection.py <text_file>")
else:
filename = sys.argv[1]
detect_syllables_in_file(filename)
bi3mw > 15-10-2023, 12:45 PM
(14-10-2023, 02:02 AM)ReneZ Wrote: You are not allowed to view links. Register or Login to view.For this, one should not use Eva. I would recommend something along the lines of the FSG alphabet, or this:
You are not allowed to view links. Register or Login to view.
These two options tend to generate quite similar statistics.
ReneZ > 15-10-2023, 01:27 PM
bitrans -f Eva-Cuva.bit Voynich_full_clean01.txt >Voynich_Cuva.txt
bi3mw > 15-10-2023, 01:46 PM
(15-10-2023, 01:27 PM)ReneZ Wrote: You are not allowed to view links. Register or Login to view.Let me know if you run into a problem.
ReneZ > 15-10-2023, 11:40 PM
c E
h E
bi3mw > 16-10-2023, 08:07 PM
bi3mw > 17-10-2023, 09:47 PM
bi3mw > 19-10-2023, 06:10 PM
bi3mw > 21-10-2023, 02:53 PM