From 5b52ee1afa7c1127c25f255b03fbaa79f8cdaa1c Mon Sep 17 00:00:00 2001 From: Feufochmar Date: Sat, 23 Jun 2018 00:24:55 +0200 Subject: [PATCH] Ignore stress in rulemaker if all vowels of a phonology is tagged unstressed --- py-phonagen/phonagen.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/py-phonagen/phonagen.py b/py-phonagen/phonagen.py index 4a44f18..f45dfe6 100644 --- a/py-phonagen/phonagen.py +++ b/py-phonagen/phonagen.py @@ -229,6 +229,15 @@ class Phonology: phonemeList.append(id) return phonemeList + def hasStressedVowels(self): + """Check if all vowels are tagged #unstressed""" + hasStressed = False + for id in self.entries: + if self.isNucleus(id) and self.isInStressedSyllables(id): + hasStressed = True + break + return hasStressed + class Distribution: """Discrete distribution""" def __init__(self): @@ -552,7 +561,7 @@ class RuleGenerator(Generator): # Step 1: Generate the word rules based on the min and max number of syllables, and the presence of stress stressId = phonology.getStress() syllableBreakId = phonology.getSyllableBreak() - isStressed = stressPosition != 0 + isStressed = (stressPosition != 0) and phonology.hasStressedVowels() # Add the 'word' rule, initialized with an empty distribution self.rules.update({'word': Distribution()}) # Add the syllable rules and word patterns @@ -578,7 +587,7 @@ class RuleGenerator(Generator): nbSyllables = nbMiddleSyllables + 2 wordPattern = [] for position in range(1, nbSyllables + 1): - isStressPosition = RuleGenerator.isStressPosition(position, nbSyllables, stressPosition) + isStressPosition = isStressed and RuleGenerator.isStressPosition(position, nbSyllables, stressPosition) # add syllable separator if isStressPosition: wordPattern.append(stressId)