Module:User:Quantum10000/mu-render

-- Define the module local M = {}

local C = "ptCksSxhmnwylzf" -- consonants local voicelessObstruents = "ptCksSxhz" -- voiceless obstruents local vowels = "aeiouAEIO" -- vowels local v = {"a", "i", "e", "o", "u"} -- short vowels local V = {"A", "I", "E", "O"} -- long vowels

-- Helper function to apply the rules local function ifDiff(inStr, output, rule) -- You can do something here if you want to handle differences end

-- Helper function to apply R22 (Vowel Elision) local function vowelElision(input) local syllables = {} for s in input:gmatch("[aeiouAEIO]+") do       table.insert(syllables, s)    end

local strongSyllables = {} for i = 1, #syllables do       local strong = false for _, V in ipairs(V) do           if syllables[i]:find(V) then strong = true break end end table.insert(strongSyllables, strong) end

for i = 1, #syllables - 1 do       if not strongSyllables[i] and syllables[i]:sub(-1) == "a" then local nextSyllable = syllables[i + 1]:sub(1, 1) if nextSyllable == "h" or nextSyllable == "x" then syllables[i] = syllables[i]:sub(1, -2) end end end

return table.concat(syllables) end

-- Apply rule R22 (Vowel Elision) local function R22(inStr) return vowelElision(inStr) end

-- Define the main function crunch function M.crunch(input, pos) local output = input

-- Applying the rules output = R1(output, pos) output = R2(output, pos) output = R3(output, pos) output = R8(output, pos) output = R9(output, pos) output = R10(output, pos) output = R11(output, pos) output = R13(output, pos) output = R14(output, pos) output = R15(output, pos) output = R16(output, pos) output = R17(output, pos) output = R19(output, pos) output = R20(output, pos) output = R21(output, pos) output = R23(output, pos) output = R24(output, pos)

output = R4(output, pos) output = R5(output, pos) output = R6(output, pos) output = R7(output, pos) output = R12(output, pos) output = R18(output, pos) output = R22(output, pos) output = R25(output, pos) output = R26(output, pos) output = R27(output, pos) output = R28(output, pos) output = R29(output, pos) output = R30(output, pos) output = R31(output, pos) output = bodgedR31(output, pos)

output = R32(output, pos) output = R33(output, pos) output = R34(output, pos) output = R35(output, pos) output = R36(output, pos) output = R37(output, pos) output = R38(output, pos) output = R39(output, pos) output = R40(output, pos) output = R41(output, pos) output = R42(output, pos) output = R43(output, pos) output = R44(output, pos)

-- Miscellaneous output = output:gsub("SS", "S'S") output = output:gsub("sh", "s'h") output = output:gsub("nS", "nZ")

return output end

-- Rule R1 function R1(inStr, pos) local output = inStr if pos == "VAI" or pos == "VTA" then output = output:gsub("l-kE", "h-kE") -- realized before -kee, intransitive suffix if output:sub(-3) == "l-k" then output = output:gsub("l-k$", "h-k") -- in AI stems before -k suffix end end ifDiff(inStr, output, 1) return output end

-- R2 function R2(inStr, pos) local output = inStr output = output:gsub("t-k", "h-k") output = output:gsub("t-p", "h-p") output = output:gsub("p-t", "h-t") output = output:gsub("p-l", "h-l")

output = output:gsub("l-kE", "h-kE") -- realized before -kee, intransitive suffix if output:sub(-3) == "l-k" then output = output:gsub("l-k$", "h-k") -- in AI stems before -k suffix end ifDiff(inStr, output, 2) return output end

-- Rule R3 function R3(inStr, pos) local output = inStr output = output:gsub("n-l", "h-l") ifDiff(inStr, output, 3) return output end

-- Rule R8 function R8(inStr, pos) -- there are many exceptions to this derivation local output = inStr output = output:gsub("t-I", "C-I") ifDiff(inStr, output, 8) return output end

-- Rule R9 function R9(inStr, pos) local output = inStr if pos:sub(1, 1) == "N" then if output:sub(-3) == "-uS" then local split = {} for s in output:gmatch("[^-]+") do               table.insert(split, s)            end if #split >= 2 then split[#split - 1] = split[#split - 1]:gsub("t", "C"):gsub("s", "S") output = table.concat(split, "-") end end end ifDiff(inStr, output, 9) return output end

-- Rule R10 function R10(inStr, pos) -- T-insertion -- Ku-V* => KtV (K = n, k, w)   local output = inStr

if pos:sub(1, 1) == "N" or pos == "VTA" then if output:sub(-2) == "u-" then output = output:gsub("u-", "t") elseif output:sub(-2) == "a-" then output = output:gsub("a-", "t") elseif output:sub(-2) == "i-" then output = output:gsub("i-", "t") elseif output:sub(-2) == "e-" then output = output:gsub("e-", "t") end end

ifDiff(inStr, output, 10) return output end

-- Rule R11 function R11(inStr, pos) -- Ku-a-CV* => Ko-CV (K = n, k, w; C = h, s, z)   local output = inStr

if pos:sub(1, 1) == "N" or pos == "VTA" then if output:sub(-5) == "u-a-" then output = output:gsub("u-a-", "o-") elseif output:sub(-5) == "a-a-" then output = output:gsub("a-a-", "o-") elseif output:sub(-5) == "i-a-" then output = output:gsub("i-a-", "e-") elseif output:sub(-5) == "e-a-" then output = output:gsub("e-a-", "o-") end end

ifDiff(inStr, output, 11) return output end

-- Rule R13 function R13(inStr, pos) -- V* => Vw (except V = e, o; V = a, i before -C) local output = inStr

if pos == "VTA" then if output:sub(-2) == "u" then output = output .. "w" elseif output:sub(-2) == "a" then output = output .. "w" elseif output:sub(-2) == "i" then output = output .. "w" end end

ifDiff(inStr, output, 13) return output end

-- Rule R14 function R14(inStr, pos) -- V* => Vh (except V = a, i)   local output = inStr

if pos:sub(1, 1) == "N" then if output:sub(-2) == "u" then output = output .. "h" elseif output:sub(-2) == "e" then output = output .. "h" elseif output:sub(-2) == "o" then output = output .. "h" end end

ifDiff(inStr, output, 14) return output end

-- Rule R15 function R15(inStr, pos) -- VC => VoC (V = short vowels; C = voiceless obstruents) local output = inStr

if pos == "VAI" then if output:sub(-2):find("[" .. voicelessObstruents .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(v) do               if lastVowel == vowel then output = output .. "o" .. lastChar break end end end end

ifDiff(inStr, output, 15) return output end

-- Rule R16 function R16(inStr, pos) -- V => VoV (V = long vowels) local output = inStr

if pos == "VAI" then local lastChar = output:sub(-1)

for _, vowel in ipairs(V) do           if lastChar == vowel then output = output .. "o" .. lastChar break end end end

ifDiff(inStr, output, 16) return output end

-- Rule R17 function R17(inStr, pos) -- VC => VeC (V = long vowels; C = voiceless obstruents) local output = inStr

if pos == "VAI" then if output:sub(-2):find("[" .. voicelessObstruents .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(V) do               if lastVowel == vowel then output = output .. "e" .. lastChar break end end end end

ifDiff(inStr, output, 17) return output end

-- Rule R19 function R19(inStr, pos) -- V => VyV (V = long vowels) local output = inStr

if pos == "VTA" then local lastChar = output:sub(-1)

for _, vowel in ipairs(V) do           if lastChar == vowel then output = output .. "y" .. lastChar break end end end

ifDiff(inStr, output, 19) return output end

-- Rule R20 function R20(inStr, pos) -- V => VyV (V = short vowels) local output = inStr

if pos == "VTA" then local lastChar = output:sub(-1)

for _, vowel in ipairs(v) do           if lastChar == vowel then output = output .. "y" .. lastChar break end end end

ifDiff(inStr, output, 20) return output end

-- Rule R21 function R21(inStr, pos) -- V => VwV (V = long vowels) local output = inStr

if pos == "VTA" then local lastChar = output:sub(-1)

for _, vowel in ipairs(V) do           if lastChar == vowel then output = output .. "w" .. lastChar break end end end

ifDiff(inStr, output, 21) return output end

-- Rule R23 function R23(inStr, pos) -- V => VwV (V = short vowels) local output = inStr

if pos == "VTA" then local lastChar = output:sub(-1)

for _, vowel in ipairs(v) do           if lastChar == vowel then output = output .. "w" .. lastChar break end end end

ifDiff(inStr, output, 23) return output end

-- Rule R24 function R24(inStr, pos) -- V => VhV (V = short vowels) local output = inStr

if pos:sub(1, 1) == "N" then local lastChar = output:sub(-1)

for _, vowel in ipairs(v) do           if lastChar == vowel then output = output .. "h" .. lastChar break end end end

ifDiff(inStr, output, 24) return output end

-- Rule R4 function R4(inStr, pos) -- VC => VyC (V = long vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-2):find("[" .. C .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(V) do               if lastVowel == vowel then output = output .. "y" .. lastChar break end end end end

ifDiff(inStr, output, 4) return output end

-- Rule R5 function R5(inStr, pos) -- V => VyC (V = long vowels) local output = inStr

if pos == "VAI" then local lastChar = output:sub(-1)

for _, vowel in ipairs(V) do           if lastChar == vowel then output = output .. "y" .. lastChar break end end end

ifDiff(inStr, output, 5) return output end

-- Rule R6 function R6(inStr, pos) -- VC => VwC (V = long vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-2):find("[" .. C .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(V) do               if lastVowel == vowel then output = output .. "w" .. lastChar break end end end end

ifDiff(inStr, output, 6) return output end

-- Rule R7 function R7(inStr, pos) -- VC => VhC (V = long vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-2):find("[" .. C .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(V) do               if lastVowel == vowel then output = output .. "h" .. lastChar break end end end end

ifDiff(inStr, output, 7) return output end

-- Rule R12 function R12(inStr, pos) -- Remove final -V local output = inStr

if pos == "VTA" then if output:sub(-1):find("[" .. vowels .. "]") then output = output:sub(1, -2) end end

ifDiff(inStr, output, 12) return output end

-- Rule R18 function R18(inStr, pos) -- V => Vw (V = long vowels) local output = inStr

if pos == "VAI" then local lastChar = output:sub(-1)

for _, vowel in ipairs(V) do           if lastChar == vowel then output = output .. "w" break end end end

ifDiff(inStr, output, 18) return output end

-- Rule R25 function R25(inStr, pos) -- V => Vh (V = long vowels) local output = inStr

if pos == "VAI" then local lastChar = output:sub(-1)

for _, vowel in ipairs(V) do           if lastChar == vowel then output = output .. "h" break end end end

ifDiff(inStr, output, 25) return output end

-- Rule R26 function R26(inStr, pos) -- V* => Vw (except V = e, o)   local output = inStr

if pos == "VTA" then if output:sub(-2) == "u" then output = output .. "w" elseif output:sub(-2) == "a" then output = output .. "w" elseif output:sub(-2) == "i" then output = output .. "w" end end

ifDiff(inStr, output, 26) return output end

-- Rule R27 function R27(inStr, pos) -- V* => Vh (except V = a, i)   local output = inStr

if pos:sub(1, 1) == "N" then if output:sub(-2) == "u" then output = output .. "h" elseif output:sub(-2) == "e" then output = output .. "h" elseif output:sub(-2) == "o" then output = output .. "h" end end

ifDiff(inStr, output, 27) return output end

-- Rule R28 function R28(inStr, pos) -- V* => Vw (except V = a, i)   local output = inStr

if pos == "VTA" then if output:sub(-2) == "u" then output = output .. "w" elseif output:sub(-2) == "e" then output = output .. "w" elseif output:sub(-2) == "o" then output = output .. "w" end end

ifDiff(inStr, output, 28) return output end

-- Rule R29 function R29(inStr, pos) -- V* => Vh (except V = a, i)   local output = inStr

if pos:sub(1, 1) == "N" then if output:sub(-2) == "u" then output = output .. "h" elseif output:sub(-2) == "e" then output = output .. "h" elseif output:sub(-2) == "o" then output = output .. "h" end end

ifDiff(inStr, output, 29) return output end

-- Rule R30 function R30(inStr, pos) -- V => VC (V = short vowels; C = voiceless obstruents) local output = inStr

if pos == "VTA" then if output:sub(-1):find("[" .. voicelessObstruents .. "]") then local lastChar = output:sub(-1)

for _, vowel in ipairs(v) do               if lastChar == vowel then output = output .. lastChar break end end end end

ifDiff(inStr, output, 30) return output end

-- Rule R31 function R31(inStr, pos) -- VC => VCaC (V = long vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-2):find("[" .. C .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(V) do               if lastVowel == vowel then output = output .. "a" .. lastChar break end end end end

ifDiff(inStr, output, 31) return output end

-- Rule R32 function R32(inStr, pos) -- V => VwC (V = long vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-1):find("[" .. C .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(V) do               if lastVowel == vowel then output = output .. "w" .. lastChar break end end end end

ifDiff(inStr, output, 32) return output end

-- Rule R33 function R33(inStr, pos) -- V => VhC (V = long vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-1):find("[" .. C .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(V) do               if lastVowel == vowel then output = output .. "h" .. lastChar break end end end end

ifDiff(inStr, output, 33) return output end

-- Rule R34 function R34(inStr, pos) -- VC => VyC (V = long vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-2):find("[" .. C .. "]") then local lastChar = output:sub(-1) local lastVowel = output:sub(-2, -2)

for _, vowel in ipairs(V) do               if lastVowel == vowel then output = output .. "y" .. lastChar break end end end end

ifDiff(inStr, output, 34) return output end

-- Rule R35 function R35(inStr, pos) -- V => VyC (V = short vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-1):find("[" .. C .. "]") then local lastChar = output:sub(-1)

for _, vowel in ipairs(v) do               if lastChar == vowel then output = output .. "y" .. lastChar break end end end end

ifDiff(inStr, output, 35) return output end

-- Rule R36 function R36(inStr, pos) -- V => VyC (V = short vowels; C = consonants) local output = inStr

if pos == "VTA" then if output:sub(-1):find("[" .. C .. "]") then local lastChar = output:sub(-1)

for _, vowel in ipairs(v) do               if lastChar == vowel then output = output .. "y" .. lastChar break end end end end

ifDiff(inStr, output, 36) return output end

-- Rule R37 function R37(inStr, pos) -- V* => VwC (except V = e, o)   local output = inStr

if pos == "VTA" then if output:sub(-2) == "u" then output = output .. "w" elseif output:sub(-2) == "a" then output = output .. "w" elseif output:sub(-2) == "i" then output = output .. "w" end end

ifDiff(inStr, output, 37) return output end

-- Rule R38 function R38(inStr, pos) -- V* => VhC (except V = a, i)   local output = inStr

if pos:sub(1, 1) == "N" then if output:sub(-2) == "u" then output = output .. "h" elseif output:sub(-2) == "e" then output = output .. "h" elseif output:sub(-2) == "o" then output = output .. "h" end end

ifDiff(inStr, output, 38) return output end

-- Rule R39 function R39(inStr, pos) -- V* => VwC (except V = a, i)   local output = inStr

if pos == "VTA" then if output:sub(-2) == "u" then output = output .. "w" elseif output:sub(-2) == "e" then output = output .. "w" elseif output:sub(-2) == "o" then output = output .. "w" end end

ifDiff(inStr, output, 39) return output end

-- Rule R40 function R40(inStr, pos) -- V* => VhC (except V = a, i)   local output = inStr

if pos:sub(1, 1) == "N" then if output:sub(-2) == "u" then output = output .. "h" elseif output:sub(-2) == "e" then output = output .. "h" elseif output:sub(-2) == "o" then output = output .. "h" end end

ifDiff(inStr, output, 40) return output end

-- Rule R41 function R41(inStr, pos) -- V* => Vw (except V = e, o)   local output = inStr

if pos == "VTA" then if output:sub(-2) == "u" then output = output .. "w" elseif output:sub(-2) == "a" then output = output .. "w" elseif output:sub(-2) == "i" then output = output .. "w" end end

ifDiff(inStr, output, 41) return output end

-- Rule R42 function R42(inStr, pos) -- V* => Vh (except V = a, i)   local output = inStr

if pos:sub(1, 1) == "N" then if output:sub(-2) == "u" then output = output .. "h" elseif output:sub(-2) == "e" then output = output .. "h" elseif output:sub(-2) == "o" then output = output .. "h" end end

ifDiff(inStr, output, 42) return output end

-- Rule R43 function R43(inStr, pos) -- V* => Vw (except V = a, i)   local output = inStr

if pos == "VTA" then if output:sub(-2) == "u" then output = output .. "w" elseif output:sub(-2) == "e" then output = output .. "w" elseif output:sub(-2) == "o" then output = output .. "w" end end

ifDiff(inStr, output, 43) return output end

-- Rule R44 function R44(inStr, pos) -- V* => Vh (except V = a, i)   local output = inStr

if pos:sub(1, 1) == "N" then if output:sub(-2) == "u" then output = output .. "h" elseif output:sub(-2) == "e" then output = output .. "h" elseif output:sub(-2) == "o" then output = output .. "h" end end

ifDiff(inStr, output, 44) return output end

-- Rule bodgedR31 function bodgedR31(inStr, pos) -- GIA => Gja (G = m, n)   local output = inStr

if pos == "VTA" then if output:sub(-3) == "GIu" then output = output:gsub("GIu", "Gju") elseif output:sub(-3) == "GIn" then output = output:gsub("GIn", "Gjn") end end

ifDiff(inStr, output, "bodgedR31") return output end

-- Export the module return M