From dd0a756a6bcfe438d2f6c8363c070766d7a8f485 Mon Sep 17 00:00:00 2001 From: Feufochmar Date: Fri, 15 Jun 2018 19:31:20 +0200 Subject: [PATCH] Add some conditions to not confuse #stress and #stressed tags. Add restrictions to which phoneme can be onset/nucleus/coda. --- py-phonagen/phonagen.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/py-phonagen/phonagen.py b/py-phonagen/phonagen.py index 7a8ae2b..4a44f18 100644 --- a/py-phonagen/phonagen.py +++ b/py-phonagen/phonagen.py @@ -89,10 +89,16 @@ class Phonology: result[y].append(phoneme[y]) return result + def isStress(self, id): + entry = self.entries[id] + description = entry['description'] + phoneme = entry['phoneme'] + return (('#stress' in description) and ('#stressed' not in description)) or ("'" in phoneme) or ("ˈ" in phoneme) + def getStress(self): """Return the phoneme id of the stress phoneme""" # search for #stress tag in description - found = [x['id'] for x in self.entries.values() if '#stress' in x['description']] + found = [x['id'] for x in self.entries.values() if ('#stress' in x['description']) and ('#stressed' not in x['description'])] if len(found) == 0: # if not tagged, search for "'" (apostrophe, u+0027) or "ˈ" (primary stress, u+02C8) in phoneme transcription found = [x['id'] for x in self.entries.values() if ("'" in x['phoneme']) or ("ˈ" in x['phoneme'])] @@ -100,6 +106,12 @@ class Phonology: raise Exception('No stress phoneme in phonology', self.id) return found[0] + def isSyllableBreak(self, id): + entry = self.entries[id] + description = entry['description'] + phoneme = entry['phoneme'] + return ('#syllable-break' in description) or ("." in phoneme) + def getSyllableBreak(self): """Return the phoneme id of the syllable break phoneme""" # search for #syllable-break tag in description @@ -123,7 +135,7 @@ class Phonology: """Check if an id corresponds to a phoneme that can be in an onset, either from description, or if not available, guessed from the phonemic transcription""" entry = self.entries[id] description = entry['description'] - result = ('#onset' in description) or ('#consonant' in description) + result = (not self.isSyllableBreak(id)) and (not self.isStress(id)) and (('#onset' in description) or ('#consonant' in description)) if (not result) and ('#vowel' not in description) and ('#nucleus' not in description) and ('#coda' not in description): result = Phonology.isConsonant(entry['phoneme']) return result @@ -132,7 +144,7 @@ class Phonology: """Check if an id corresponds to a phoneme that can be in a nucleus, either from description, or if not available, guessed from the phonemic transcription""" entry = self.entries[id] description = entry['description'] - result = ('#nucleus' in description) or ('#vowel' in description) + result = (not self.isSyllableBreak(id)) and (not self.isStress(id)) and (('#nucleus' in description) or ('#vowel' in description)) if (not result) and ('#consonant' not in description) and ('#onset' not in description) and ('#coda' not in description): result = Phonology.isVowel(entry['phoneme']) return result @@ -141,7 +153,7 @@ class Phonology: """Check if an id corresponds to a phoneme that can be in a coda, either from description, or if not available, guessed from the phonemic transcription""" entry = self.entries[id] description = entry['description'] - result = ('#coda' in description) or ('#consonant' in description) + result = (not self.isSyllableBreak(id)) and (not self.isStress(id)) and (('#coda' in description) or ('#consonant' in description)) if (not result) and ('#vowel' not in description) and ('#nucleus' not in description) and ('#onset' not in description): result = Phonology.isConsonant(entry['phoneme']) return result