File size: 1,113 Bytes
1db7196 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import re
import separasilabas
def count_words(text):
text = ''.join(filter(lambda x: not x.isdigit(), text))
clean = re.compile(r'\W+')
text = clean.sub(' ', text).strip()
return len(text.split()) if len(text.split()) > 0 else 1
def count_sentences(text):
text = text.replace("\n", "")
sentence_end = re.compile(r'[.:;!?\)\()]')
sentences = sentence_end.split(text)
sentences = list(filter(None, sentences))
return len(sentences) if len(sentences) > 0 else 1
def count_all_syllables(text):
clean = re.compile(r'\W+')
words = clean.sub(' ', text).strip().split()
silabizer = separasilabas.silabizer()
total = 0
for word in words:
total += len(silabizer(word))
return total if total > 0 else 1
def Pval(text):
syllables = count_all_syllables(text)
words = count_words(text)
return round(syllables / words, 2)
def Fval(text):
sentences = count_sentences(text)
words = count_words(text)
return round(words / sentences, 2)
def fernandez_huerta(text):
return round(206.84 - 60 * Pval(text) - 1.02 * Fval(text), 2)
|