Hello, AnkiDroid Support/Forum,
I prefer to use your software for flashcard learning, but I use Pleco to create my own custom categories for words I want to learn.
I am aware that we are able to export our cards from Pleco and import them into a custom deck in Anki, however, what I am really looking for is an add-on or feature to convert the PinYin tone numbers (which is how it is exported from Pleco) into PinYin tone marks.
Is there an add-on, or feature that would achieve this?
Thanks.
tone_map_a = {1: 'ā',
2: 'á',
3: 'â',
4: 'à',
5: 'ǎ',
6: 'a'}
tone_map_i = {1: 'ī',
2: 'í',
3: 'î',
4: 'ì',
5: 'ǐ',
6: 'i'}
tone_map_o = {1: 'ō',
2: 'ó',
3: 'ô',
4: 'ò',
5: 'ǒ',
6: 'o'}
tone_map_u = {1: 'ū',
2: 'ú',
3: 'û',
4: 'ù',
5: 'ǔ',
6: 'u'}
def yale_tone_character(char, tone):
if char == 'e':
return tone_map_e[tone]
if char == 'a':
return tone_map_a[tone]
if char == 'i':
return tone_map_i[tone]
if char == 'o':
return tone_map_o[tone]
if char == 'u':
return tone_map_u[tone]
raise Exception("unknown char %c"%char)
def yale_tone_marks_syllable(syllable):
# extract tone
m = re.search("([a-z]+)([0-9])", syllable)
if m == None:
raise Exception("couldn't parse syllable [%s]" % syllable)
sound = m.group(1)
tone = int(m.group(2))
# find the first vowel in the sound
index=0
for char in sound:
if char in ('a','e','i','o','u'):
break
index += 1
if index >= len(sound):
return sound
# the index of the first vowel is in "index"
sound_characters = list(sound)
sound_characters[index] = yale_tone_character(sound_characters[index], tone)
updated_sound = "".join(sound_characters)
return updated_sound
def yale_tone_marks(input):
try:
syllables = input.split(" ")
syllables_modified = [yale_tone_marks_syllable(s) for s in syllables]
return " ".join(syllables_modified)
except Exception as e:
print("Couldn't convert yale [%s]: %s"%(input, e))
return ""