diff --git a/parsers/en_en.py b/parsers/en_en.py index e2a931639973aa7554e09fdbd343decd39873d69..80d0688ac4b286a8f0e7ac0eaa42ce13c195b5b4 100644 --- a/parsers/en_en.py +++ b/parsers/en_en.py @@ -21,17 +21,19 @@ class En_en_straktor(Wikstraktor): while i < len(l.fullitems): p = Pronunciation() templates = self.wtp.parse(l.fullitems[i]).templates - a = None + acc = None for j, t in enumerate(templates): if (t.normal_name() == self.constants['t_acc'] and templates[j+1].normal_name()!= self.constants['t_acc']): - a = t.arguments[0].value + acc = t.arguments elif t.normal_name() == self.constants['t_ipa']: p.set_transcription(t.arguments[1].value) - p.set_accent(a) + if acc != None: + for a in acc: + p.set_accent(a.value) elif t.normal_name() == self.constants['t_snd']: - p.add_sound(self.get_file_url(t.arguments[1].value), a) + p.add_sound(self.get_file_url(t.arguments[1].value), t.arguments[2].value) if j==len(templates)-1 or templates[j+1].normal_name()== self.constants['t_acc'] : - if p.ipa != None or p.accent != None: + if p.ipa != None or p.has_accents(): pronunciations.append(p) p = Pronunciation() i += 1 diff --git a/wikstraktor.py b/wikstraktor.py index 66e187abda8fc96e86dcaaaa62ca2dd5e7bad513..4db70fbe7ddb598b04d44a74794902d3103f07b0 100755 --- a/wikstraktor.py +++ b/wikstraktor.py @@ -64,13 +64,16 @@ class Pronunciation(SubInfo): super().__init__(prefix) self.ipa = None self.sounds = [] - self.accent = None + self.accents = set() def set_transcription(self, tscpt): self.ipa = tscpt def set_accent(self, accent): - self.accent = accent + self.accents.add(accent) + + def has_accents(self): + return len(self.accents) > 0 def add_sound(self, url, accent=None): self.sounds.append(Sound(url,accent)) @@ -81,8 +84,8 @@ class Pronunciation(SubInfo): snds.append(s.serializable()) res = super().serializable(prefix) res['transcript'] = self.ipa - if self.accent != None: - res['accent'] = self.accent + if self.has_accents(): + res['accents'] = list(self.accents) res['sounds'] = snds return res @@ -90,7 +93,7 @@ class Pronunciation(SubInfo): return json.dumps(self.serializable('')) def __eq__(self, other): - res = isinstance(other, self.__class__) and self.ipa == other.ipa and self.accent == other.accent and len(self.sounds)==len(other.sounds) + res = isinstance(other, self.__class__) and self.ipa == other.ipa and self.accents == other.accents and len(self.sounds)==len(other.sounds) i = 0 while res and i<len(self.sounds): res = self.sounds[i] == other.sounds[i]