Module:User:Sokkjo/gmw-stress

-- Function to determine the stress of a Proto-Germanic word function determine_stress(word) -- Mapping plain vowels to vowels with acute accents local accented_vowels = { a = "á", e = "é", i = "í", o = "ó", u = "ú", A = "Á", E = "É", I = "Í", O = "Ó", U = "Ú" }   -- Helper function to identify vowels local function is_vowel(char) return string.match(char, "[aeiouAEIOU]") end

-- Split the word into syllables local syllables = {} local syllable = "" local vowel_found = false

for i = 1, #word do       local char = word:sub(i, i)        syllable = syllable .. char if is_vowel(char) then vowel_found = true elseif vowel_found and (i == #word or is_vowel(word:sub(i + 1, i + 1))) then table.insert(syllables, syllable) syllable = "" vowel_found = false end end

if #syllable > 0 then table.insert(syllables, syllable) end

-- Primary stress falls on the first vowel of the first syllable local stressed_word = "" local stress_applied = false for i, syllable in ipairs(syllables) do       if i == 1 and not stress_applied then -- Apply stress on the first vowel in the first syllable for j = 1, #syllable do               local char = syllable:sub(j, j)                if is_vowel(char) then stressed_word = stressed_word .. accented_vowels[char] stress_applied = true else stressed_word = stressed_word .. char end end else stressed_word = stressed_word .. syllable end end

return stressed_word end

-- Test the function with a sample word local proto_germanic_word = "harjabardi" local stressed_word = determine_stress(proto_germanic_word) print("Original word: " .. proto_germanic_word) print("Stressed word: " .. stressed_word)