Metindeki istenmeyen karakterleri silerek:
lower_vowel = {"â","ê","î","ô","û","a","e","ı","i","o","ö","u","ü","A","E","I","İ","O","Ö","U","Ü"}
SPELL_SLICER = (('001000', 5), ('000100', 5), ('01000', 4), ('00100', 4), ('00010', 4), ('1000', 3), ('0100', 3),
('0011', 3), ('0010', 3), ('011', 2),('010', 2), ('100', 2), ('10', 1), ('11', 1))
def wordtoten(word: str):
wtt = ''
for ch in word:
if ch in lower_vowel:
wtt += '1'
else:
wtt += '0'
return wtt
def spellword_util(word: str):
syllable_list = []
tenword = wordtoten(word)
len_spell = tenword.count('1')
for i in range(len_spell):
for x, y in SPELL_SLICER:
if tenword.startswith(x):
syllable_list.append(word[:y])
word = word[y:]
tenword = tenword[y:]
break
if tenword == '0':
syllable_list[-1] = syllable_list[-1] + word
elif word:
syllable_list.append(word)
if len(syllable_list) != len_spell:
return False
return syllable_list
def spellword(word: str):
ignore = "'"
s = "".join(filter(lambda c: c not in ignore, word))
return spellword_util(s)