| 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) |
|
|
|
|
|
|