Add some conditions to not confuse #stress and #stressed tags. Add restrictions to which phoneme can be onset/nucleus/coda.
This commit is contained in:
parent
b375702a09
commit
dd0a756a6b
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue