Module:User:Fenakhay/mt-IPA
- This module lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of Fenakhay, for his own experimentation. Items in this module may be added and removed at Fenakhay's discretion; do not rely on this module's stability.
local export = {}
local rfind = mw.ustring.find
local rsubn = mw.ustring.gsub
local m_q = require("Module:qualifier")
local m_IPA = require("Module:IPA")
local sc = require("Module:scripts").getByCode("Latn")
local lang = require("Module:languages").getByCode("mt")
function export.show(frame)
local args = frame:getParent().args
local pagetitle = mw.title.getCurrentTitle().text
local p, results_archaic_rural = {}, {}
if args[1] then
for index, item in ipairs(args) do
table.insert(p, (item ~= "") and item or nil)
end
else
p = {pagetitle}
end
for _, word in ipairs(p) do
table.insert(results_archaic_rural, {pron = "/" .. export.mt_archaic_rural_IPA(word) .. "/"})
end
return m_IPA.format_IPA_full { lang = lang, items = results }
end
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
-- apply rsub() repeatedly until no change
local function rsub_repeatedly(term, foo, bar)
while true do
local new_term = rsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
local vowels = "aeiyouâêîôû"
local vowel = "[" .. vowels .. "]"
local consonant = "[^" .. vowels .. "]"
local voiceless_consonant = "ptkqzċfsxħ"
local voiced_consonant = "bdgẓġvzžḡʕ"
local vowel_correspondences = {
["i"] = "ɪ",
["ì"] = "ɪ",
["î"] = "iː",
["y"] = "ɪː",
["o"] = "ɔ",
["ò"] = "ɔ",
["ô"] = "ɔː",
["e"] = "ɛ",
["è"] = "ɛ",
["ê"] = "ɛː",
["u"] = "u",
["ù"] = "u",
["û"] = "uː",
["a"] = "a",
["à"] = "a",
["â"] = "aː",
["é"] = "ɛˤː",
["á"] = "aˤː",
["ó"] = "ɔˤː",
["æ"] = "əˤ"
}
local devoicing = {
["b"] = "p",
["g"] = "k",
["v"] = "f",
["ġ"] = "ċ",
["ž"] = "x",
["d"] = "t",
["ʕ"] = "ħ",
["ḡ"] = "ħ",
["ẓ"] = "Z"
}
local voicing = {
["p"] = "b",
["k"] = "g",
["f"] = "v",
["ċ"] = "ġ",
["x"] = "ž",
["t"] = "d",
["Z"] = "ẓ",
}
local consonant_correspondences = {
["ġ"] = "d͡ʒ",
["g"] = "ɡ",
["x"] = "ʃ",
["ċ"] = "t͡ʃ",
["q"] = "ʔ",
["Z"] = "t͡s",
["ż"] = "z",
["ẓ"] = "d͡z",
["ʕ"] = "ʕ",
["ḡ"] = "ɣ",
["ž"] = "ʒ",
}
function export.mt_IPA(text, variant, do_debug)
text = rsubn(text, "-", "")
text = rsubn(text, " | ", "# | #")
text = "##" .. rsubn(text, " ", "# #") .. "##"
text = mw.ustring.lower(text)
-- Replace ie with y
text = rsubn(text, "ie", "y")
-- Replace għ with ʕ
text = rsubn(text, "għ", "ʕ")
-- Replace ḡ with ʕ if archaic
if variant == "archaic" then text = rsubn(text, "ḡ", "ʕ") end
-- Replace final h with ħ
text = rsubn(text, "h#", "ħ#")
-- Replace z with Z (temp)
text = rsubn(text, "z", "Z")
local function epenthetic_vowel_add(cons1, cons2)
if rfind(cons1, "[nmrl]") or cons1 == cons2 then
return "##(ɪ)" .. cons1 .. cons2
end
end
text = rsubn(text, "##(" .. consonant .. ")(" .. consonant .. ")", epenthetic_vowel_add)
text = rsubn(text, "ZZ([aàâoòôuùû])", "ẓẓ%1")
-- Simplify affricate geminates
text = rsubn(text, "([ġẓ])%1", "d%1")
text = rsubn(text, "([Zċ])%1", "t%1")
-- Replace ʕh, ħh, hh with ħħ
text = rsubn(text, "[ʕħh]h", "ħħ")
-- Replace âho, aho with ô
text = rsubn(text, "[aàâ]ho", "ô")
-- Replace êhi, ehi with èj
text = rsubn(text, "[eèê]hi", "èj")
-- Replace ûho, ùho with ûwo
text = rsubn(text, "[uùû]ho", "ûwo")
-- Replace îħ with yħ
text = rsubn(text, "[yî]([ħhq])", "y%1")
-- Replace yha with yja
text = rsubn(text, "yha", "yja")
-- Replace eh, he with ê
text = rsubn(text, "h[eèê]", "ê")
text = rsubn(text, "[eèê]h", "ê")
-- Replace ah, ha with â
text = rsubn(text, "h[àâ]", "â")
text = rsubn(text, "h[àâ]", "â")
text = rsubn(text, "[âà]ha", "â")
-- Replace ih, hi with î
text = rsubn(text, "h[iìî]", "î")
-- Replace vowel + għ + vowel with vowel + ˤː
text = rsubn(text, "[eèê]ʕ[eèê]", "é")
text = rsubn(text, "[aàâ]ʕ[aàâ]", "á")
text = rsubn(text, "[oòô]ʕ[oòô]", "ó")
-- Replace consonant + e + għ + consonant with consonant + ɛˤː + consonant
text = rsubn(text, "(" .. consonant .. ")[eèê]ʕ(" .. consonant .. ")", "%1é%2")
-- Replace consonant + a + għ + consonant with consonant + aˤː + consonant
text = rsubn(text, "(" .. consonant .. ")[aàâ]ʕ(" .. consonant .. ")", "%1á%2")
-- Replace consonant + ɔ + għ + consonant with consonant + ɔˤː + consonant
text = rsubn(text, "(" .. consonant .. ")[oòô]ʕ(" .. consonant .. ")", "%1ó%2")
-- Replace initial għ + î with əˤjː
text = rsubn(text, "ʕî", "æj")
-- Replace initial għ + e with əˤ
text = rsubn(text, "ʕe", "æ")
-- Replace initial għ + u,û with əˤwː
text = rsubn(text, "ʕ[uû]", "æw")
-- Replace initial għ + vowel with vowel + ˤː
text = rsubn(text, "ʕ[èê]", "é")
text = rsubn(text, "ʕ[aàâ]", "á")
text = rsubn(text, "ʕ[oòô]", "ó")
text = rsubn(text, "a'#", "aˤ#")
-- text = rsubn(text, "êî", "ejî")
local function voice(sound, following)
return voicing[sound] .. following
end
local function devoice(sound, following)
return devoicing[sound] .. following
end
local function final_devoicing(sound)
return devoicing[sound]
end
-- Final devoicing
text = rsub_repeatedly(text, "([" .. voiced_consonant .. "])#", final_devoicing)
text = rsub_repeatedly(text, "([" .. voiceless_consonant .. "])([" .. voiced_consonant .. "])", voice)
text = rsub_repeatedly(text, "([" .. voiced_consonant .. "])([" .. voiceless_consonant .. "])", devoice)
local function simplify_final_geminates(cons1, cons2)
if cons1 == cons2 and not rfind(cons1, "[nmrl]") then
return cons2 .. "#"
end
end
text = rsubn(text, "(" .. consonant .. ")(" .. consonant .. ")#", simplify_final_geminates)
-- Replace îħ with yħ
text = rsubn(text, "[yî]([ħhq])", "y%1")
-- Replace îħ with yħ
text = rsubn(text, "ts", "Z")
text = rsubn(text, "dz", "ẓ")
-- Replace consonants
text = rsubn(text, ".", consonant_correspondences)
-- Replace vowels
text = rsubn(text, ".", vowel_correspondences)
text = rsubn(text, "h", "")
text = rsubn(text, "#", "")
return text
end
return export