Last active
November 15, 2020 11:51
-
-
Save KozhevnikovM/01a389e31a63ece762fe9ff87d3c04d1 to your computer and use it in GitHub Desktop.
dividere_lettere
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
def clear_string(string): | |
dictionary = str.maketrans('àáâãäåèéêëìíîïòóôõöøùúûüýÿ', 'aaaaaaeeeeiiiioooooouuuuyy') | |
return ''.join(e for e in string if e.isalpha()).translate(dictionary) | |
def is_vowel(letter, vowels='aeiouyj'): | |
return letter in vowels | |
def get_dividere_lettere(string): | |
cleared_string = clear_string(string) | |
syllables = [] | |
pointer = 0 | |
current_syllable = '' | |
for letter in cleared_string: | |
pointer += 1 | |
current_syllable += letter | |
stayed_string = cleared_string[pointer:] | |
if not stayed_string: | |
syllables.append(current_syllable) | |
break | |
if is_vowel(letter) and not is_vowel(stayed_string[0]): | |
syllables.append(current_syllable) | |
current_syllable = '' | |
return syllables | |
def count_se(dividere_lettere): | |
return len(dividere_lettere) | |
def get_sound_elements(dividere_lettere): | |
return len(dividere_lettere) | |
def get_final_element(dividere_lettere): | |
return dividere_lettere[-1] | |
def get_prosodic_structure(list_of_final): | |
unique_syllables = list(set(list_of_final)) | |
return [unique_syllables.index(el) for el in list_of_final] | |
with open ('example.txt', 'r') as file: | |
poem = file.read().splitlines() | |
poem_syllables = [get_dividere_lettere(string) for string in poem] | |
poem_list_of_se = [count_se(syllables) for syllables in poem_syllables] | |
print(poem_list_of_se) | |
list_of_final = [get_final_element(syllables) for syllables in poem_syllables] | |
print(list_of_final) | |
prosodic_structure = get_prosodic_structure(list_of_final) | |
print(prosodic_structure) | |
integer_representing = max(prosodic_structure) | |
print(integer_representing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment