def _handle_phonetics(cls, word, phonetic_attributes, form_str, lexeme_attributes=None): lexeme_attributes = lexeme_attributes or [] phonetic_attributes = phonetic_attributes or [] first_letter_of_form = TurkishAlphabet.get_letter_for_char(form_str[0]) # first apply voicing if possible if LexemeAttribute.NoVoicing not in lexeme_attributes and PhoneticAttributes.LastLetterVoicelessStop in phonetic_attributes and first_letter_of_form.vowel: voiced_letter = TurkishAlphabet.voice( TurkishAlphabet.get_letter_for_char(word[-1])) if voiced_letter: word = word[:-1] + voiced_letter.char_value # then try devoicing if PhoneticAttributes.LastLetterVoiceless in phonetic_attributes and TurkishAlphabet.devoice( first_letter_of_form): form_str = TurkishAlphabet.devoice( first_letter_of_form).char_value + form_str[1:] applied = u'' for i in range(len(form_str)): c = form_str[i] next_c = form_str[i + 1] if i + 1 < len(form_str) else None if c == '!': continue letter = TurkishAlphabet.get_letter_for_char(c) if letter.vowel and letter.upper_case_char_value == c: if c == u'A': if PhoneticAttributes.LastVowelBack in phonetic_attributes: applied += u'a' else: applied += u'e' elif c == u'I': if PhoneticAttributes.LastVowelBack in phonetic_attributes: if PhoneticAttributes.LastVowelUnrounded in phonetic_attributes or next_c == '!': applied += u'ı' else: applied += u'u' else: if PhoneticAttributes.LastVowelUnrounded in phonetic_attributes or next_c == '!': applied += u'i' else: applied += u'ü' elif c == u'O': if PhoneticAttributes.LastVowelBack in phonetic_attributes: applied += u'o' else: applied += u'ö' else: applied = applied + c return word, applied
def _handle_phonetics(cls, word, phonetic_attributes, form_str, lexeme_attributes=None): lexeme_attributes = lexeme_attributes or [] phonetic_attributes = phonetic_attributes or [] first_letter_of_form = TurkishAlphabet.get_letter_for_char(form_str[0]) # first apply voicing if possible if LexemeAttribute.NoVoicing not in lexeme_attributes and PhoneticAttributes.LastLetterVoicelessStop in phonetic_attributes and first_letter_of_form.vowel: voiced_letter = TurkishAlphabet.voice(TurkishAlphabet.get_letter_for_char(word[-1])) if voiced_letter: word = word[:-1] + voiced_letter.char_value # then try devoicing if PhoneticAttributes.LastLetterVoiceless in phonetic_attributes and TurkishAlphabet.devoice(first_letter_of_form): form_str = TurkishAlphabet.devoice(first_letter_of_form).char_value + form_str[1:] applied = u'' for i in range(len(form_str)): c = form_str[i] next_c = form_str[i + 1] if i + 1 < len(form_str) else None if c == '!': continue letter = TurkishAlphabet.get_letter_for_char(c) if letter.vowel and letter.upper_case_char_value == c: if c == u'A': if PhoneticAttributes.LastVowelBack in phonetic_attributes: applied += u'a' else: applied += u'e' elif c == u'I': if PhoneticAttributes.LastVowelBack in phonetic_attributes: if PhoneticAttributes.LastVowelUnrounded in phonetic_attributes or next_c == '!': applied += u'ı' else: applied += u'u' else: if PhoneticAttributes.LastVowelUnrounded in phonetic_attributes or next_c == '!': applied += u'i' else: applied += u'ü' elif c == u'O': if PhoneticAttributes.LastVowelBack in phonetic_attributes: applied += u'o' else: applied += u'ö' else: applied = applied + c return word, applied