Skip to content
Snippets Groups Projects
Commit a3c5d9a3 authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

2 level pronunciation with accent

parent 5622cf94
No related branches found
No related tags found
No related merge requests found
...@@ -4,5 +4,6 @@ string_values = { ...@@ -4,5 +4,6 @@ string_values = {
"en":"English", "en":"English",
"fr":"French", "fr":"French",
"t_ipa":"IPA", #template for transcription "t_ipa":"IPA", #template for transcription
"t_snd":"audio" #template for audio "t_snd":"audio", #template for audio
"t_acc":"a" #template for accents
} }
...@@ -3,12 +3,17 @@ from wikstraktor import Wikstraktor ...@@ -3,12 +3,17 @@ from wikstraktor import Wikstraktor
from parsers.en_constants import string_values from parsers.en_constants import string_values
from pronunciation import Pronunciation from pronunciation import Pronunciation
def debugC(c): def debugC(c, e):
res = "Context: " res = "Context: "
if len(c) == 0 : if len(c) == 0 :
res += "0" res += "0"
else: else:
res += f"{len(c)}, {c[-1].level*'#'} {c[-1].title}" res += f"{len(c)}, {c[-1].level*'#'} {c[-1].title}"
res += " / "
if len(e) == 0:
res += "0"
else:
res += f"{len(e)}, {(len(e) - 1)*'='} {e[-1]}"
return res return res
class En_en_straktor(Wikstraktor): class En_en_straktor(Wikstraktor):
...@@ -30,17 +35,22 @@ class En_en_straktor(Wikstraktor): ...@@ -30,17 +35,22 @@ class En_en_straktor(Wikstraktor):
for li in l.sublists(i)[0].items: for li in l.sublists(i)[0].items:
for t in self.wtp.parse(li).templates: for t in self.wtp.parse(li).templates:
templates.append(t) templates.append(t)
a = None
for t in templates: for t in templates:
print(t.normal_name()) print(t.normal_name())
if t.normal_name() == self.constants['t_ipa']: if t.normal_name() == self.constants['t_acc']:
a = t.arguments[0].value
elif t.normal_name() == self.constants['t_ipa']:
p.set_transcription(t.arguments[1].value) p.set_transcription(t.arguments[1].value)
p.set_accent(a)
print(t, t.arguments, t.arguments[0].value) print(t, t.arguments, t.arguments[0].value)
elif t.normal_name() == self.constants['t_snd']: elif t.normal_name() == self.constants['t_snd']:
p.add_sound(self.get_file_url(t.arguments[1].value)) p.add_sound(self.get_file_url(t.arguments[1].value), a)
print(t, t.arguments, t.arguments[1].value) print(t, t.arguments, t.arguments[1].value)
pronunciations.append(p) pronunciations.append(p)
i += 1 i += 1
print(pronunciations[0], pronunciations[1]) print(pronunciations[0], pronunciations[1])
return pronunciations
def parse(self, entry, sections): def parse(self, entry, sections):
...@@ -48,6 +58,7 @@ class En_en_straktor(Wikstraktor): ...@@ -48,6 +58,7 @@ class En_en_straktor(Wikstraktor):
entry_context = [] #todo récupérer les infos section par section et créer des entrées avec les infos des niveaux supérieurs. entry_context = [] #todo récupérer les infos section par section et créer des entrées avec les infos des niveaux supérieurs.
for s in sections: for s in sections:
if s.title != None : if s.title != None :
#handle wiki context
if len(wiki_context) == 0 or s.level > wiki_context[-1].level: if len(wiki_context) == 0 or s.level > wiki_context[-1].level:
wiki_context.append(s) wiki_context.append(s)
else: else:
...@@ -55,8 +66,8 @@ class En_en_straktor(Wikstraktor): ...@@ -55,8 +66,8 @@ class En_en_straktor(Wikstraktor):
wiki_context.pop() wiki_context.pop()
wiki_context[-1] = s wiki_context[-1] = s
if s.title == self.constants['ipa']: if s.title == self.constants['ipa']:
self.process_pronunciation(self.wtp.parse(s.contents)) entry_context.append(self.process_pronunciation(self.wtp.parse(s.contents)))
print(s.level, debugC(wiki_context)) print(s.level, debugC(wiki_context, entry_context))
print("ok") print("ok")
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -30,7 +30,11 @@ class Pronunciation: ...@@ -30,7 +30,11 @@ class Pronunciation:
snds = [] snds = []
for s in self.sounds: for s in self.sounds:
snds.append(s.serializable()) snds.append(s.serializable())
return {"transcript":self.ipa, "sounds":snds} if self.accent == None:
res = {"transcript":self.ipa, "sounds":snds}
else:
res = {"accent":self.accent, "transcript":self.ipa, "sounds":snds}
return res
def __str__(self): def __str__(self):
return f"{self.serializable()}" return f"{self.serializable()}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment