Module:User:Thadh/nl-IPA
Appearance
- This module sandbox lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox
local export={}
local m_IPA = require("Module:IPA")
local m_a = require("Module:accent qualifier")
local lang = require("Module:languages").getByCode("nl")
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower
local V = "[aeiouə]"
local V_IPA = "[aeiouyɑɛɪɔʊʏœ]"
local C = "[bcdfghjklmnpqrstvwxzɡʃʒ]"
local C_IPA = "[bdfɣɦjklmnprstvʋxzɡʃʒŋ]"
local T = "[fkpstʃx]"
local t = mw.ustring.char(0x0308)
local p = mw.ustring.char(0x002E)
local diac = {
["ä"]="a" .. t, ["ë"]="e" .. t, ["ï"]="i" .. t, ["ö"]="o" .. t, ["ü"]="u" .. t
}
local phon = {
["b"]="b", ["d"]="d", ["f"]="f", ["g"]="ɣ", ["h"]="ɦ",
["j"]="j", ["k"]="k", ["l"]="l", ["m"]="m", ["n"]="n",
["p"]="p", ["r"]="r", ["s"]="s", ["t"]="t", ["v"]="v",
["w"]="ʋ", ["z"]="z",
["a"]="ɑ", ["e"]="ə", ["i"]="ɪ", ["o"]="ɔ", ["u"]="ʏ",
["ê"]="ɛː", ["ô"]="ɔː",
["á"]="a", ["é"]="e", ["í"]="i", ["ó"]="o", ["ú"]="u"
}
local digr = {
["ch"]="x", ["sh"]="ʃ", ["zh"]="ʒ",
["ie"]="ii", ["eu"]="øː", ["oe"]="ú",
["ij"]="ɛí", ["ei"]="ɛí", ["ou"]="ɑú",
["au"]="ɑú", ["ui"]="œy",
}
local function phonemic(text)
text = rlower(text)
-- stress
if mw.ustring.find(text, "ˈ") == nil then
text = "ˈ" .. text
end
if mw.ustring.find(text, "ˌ") == nil then
text = mw.ustring.gsub(text, "-", "ˌ")
end
-- special cases
if text == "ˈeen" then text = "ən" end
if text == "ˈéén" then text = "ˈeen" end
if text == "ˈde" then text = "də" end
if text == "ˈge" then text = "gə" end
if text == "ˈje" then text = "jə" end
if text == "ˈme" then text = "mə" end
if text == "ˈwe" then text = "wə" end
if text == "ˈze" then text = "zə" end
text = rsub(text, "moniken$", "monikken")
text = rsub(text, "oeuvre$", "œːvre")
if text == "([ˈˌ]" .. C .. "?" .. C .. "?)lijk" then text = "%1lɛík" end
text = rsub(text, "lijk", "lək")
if text == "([ˈˌ]" .. C .. "?" .. C .. "?)ig" then text = "%1ɪg" end
text = rsub(text, "[iï]g", "əg")
text = rsub(text, "é", "éː")
text = rsub(text, "ü", "yː")
text = rsub(text, "auw", "áːúw")
text = rsub(text, "eeuw", "éːúw")
text = rsub(text, "ieuw", "íːúw")
text = rsub(text, "ouw", "áːúw")
-- digraphs
text = rsub(text, "ng", "ŋ")
text = rsub(text, "êŋ", "ɛ̃ː")
text = rsub(text, "ôŋ", "ɔ̃ː")
text = rsub(text, "âŋ", "ɑ̃ː")
local index = 0
while index <= 5 do
text = rsub(text, "..", digr)
text = rsub("@" .. text, "..", digr)
text = rsub(text, "@", "")
index = index + 1
end
text = rsub(text, "úw$", "ú")
text = rsub(text, "úw%s", "ú ")
-- long vowels
text = rsub(text, ".", diac)
text = rsub(text, "(" .. V .. ")" .. t, p .. "%1")
text = rsub(text, "(" .. V .. ")([ˈˌ]" .. C .. "?" .. V .. ")", "%1%1%2")
text = rsub(text, "(" .. V .. ")(" .. C .. V .. ")", "%1%1%2")
text = rsub(text, "([ˈˌ]" .. C .. "*)e(" .. C .. V .. ")", "%1ee" .. p .. "%2")
text = rsub(text, "(" .. C .. ")(" .. V .. ")$", "%1%2%2")
text = rsub(text, "(" .. C .. ")(" .. V .. ")%s", "%1%2%2 ")
text = rsub(text, "([ˈˌ])(" .. V .. ")$", "%1%2%2")
text = rsub(text, "([ˈˌ])(" .. V .. ")%s", "%1%2%2 ")
text = rsub(text, "aa", "áː")
text = rsub(text, "ee", "eː")
text = rsub(text, "ii", "í")
text = rsub(text, "oo", "óː")
text = rsub(text, "uu", "y")
text = rsub(text, "əə", "ə")
-- schwa
text = rsub(text, "([ˈˌ]" .. C .. "?" .. C .. "?" .. C .. "?)eː", "%1éː") -- any unstressed <e> becomes a schwa
text = rsub(text, "([ˈˌ]" .. C .. "?" .. C .. "?" .. C .. "?)e", "%1ɛ") -- any unstressed <e> becomes a schwa
text = rsub(text, "eː", "e")
-- general phonology
text = rsub(text, ".", phon)
text = rsub(text, "^(" .. C_IPA .. ")([ˈˌ]?)(" .. C_IPA .. ")", "%2%1%3")
text = rsub(text, " (" .. C_IPA .. ")([ˈˌ]?)(" .. C_IPA .. ")", " %2%1%3")
text = rsub(text, "ɦ$", "")
text = rsub(text, "ɦ%s", " ")
text = rsub(text, "(" .. C_IPA .. ")%1", "%1")
text = rsub(text, "(" .. C_IPA .. ")([ˈˌ]?)(" .. V_IPA .. ")", "%2%1%3")
return text
end
local function NL(text)
text = phonemic(text)
-- final devoicing
text = rsub(text, "b$", "p")
text = rsub(text, "b%s", "p ")
text = rsub(text, "d$", "t")
text = rsub(text, "d%s", "t ")
text = rsub(text, "v$", "f")
text = rsub(text, "v%s", "f ")
text = rsub(text, "z$", "s")
text = rsub(text, "z%s", "s ")
text = rsub(text, "ʒ$", "ʃ")
text = rsub(text, "ʒ%s", "ʃ ")
-- tj/dj/sj
text = rsub(text, "t([ˈˌ]?)j", "t͡%1ʃj")
text = rsub(text, "d([ˈˌ]?)j", "t͡%1ʃj")
text = rsub(text, "s([ˈˌ]?)j", "ʃ%1j")
text = rsub(text, "t ([ˈˌ]?)j", "t͡ʃ‿%1j")
text = rsub(text, "s ([ˈˌ]?)j", "ʃ‿%1j")
text = rsub(text, "st͡ʃ‿([ˈˌ]?)j", "ʃ‿%1j")
-- final liquids
text = rsub(text, "r$", "ɹ")
text = rsub(text, "r%s", "ɹ ")
text = rsub(text, "r([ˈˌ]?)(" .. C_IPA .. ")", "ɹ%1%2")
text = rsub(text, "l$", "ɰ")
text = rsub(text, "l%s", "ɰ ")
text = rsub(text, "l([ˈˌ]?)(" .. C_IPA .. ")", "ɰ%1%2")
-- long vowels
text = rsub(text, "øː", "øʏ")
text = rsub(text, "eː", "eɪ")
text = rsub(text, "oː", "oʊ")
text = rsub(text, "øʏ([ɹɰr])", "øː%1")
text = rsub(text, "eɪ([ɹɰur])", "eː%1")
text = rsub(text, "oʊ([ɹɰr])", "oː%1")
text = rsub(text, "œy([ɹɰ])", "ɛː%1")
text = rsub(text, "ɛi([ɹɰ])", "ɛː%1")
-- phonetic values
text = rsub(text, "x", "χ")
text = rsub(text, "r", "ʀ")
text = rsub(text, "ɣ", "χ")
text = rsub(text, "ɑu", "aʊ")
text = rsub(text, "ɛi", "ɛɪ")
text = rsub(text, "([ˈˌ]" .. C_IPA .. "?)([yiuɛɔ])ː", "%1%2ːː")
text = rsub(text, "([yiuɛɔ])ː", "%1")
text = rsub(text, "ən%s(" .. C .. ")", "ə(n) %1")
text = rsub(text, "ən$", "ə(n)")
text = rsub(text, "ən([ˈˌ]?)t", "ə(n)%1t")
text = rsub(text, "^ə(n)", "ən")
text = rsub(text, "%sən", " ən")
text = rsub(text, "(" .. V_IPA .. "ː?" .. V_IPA .. ")", "%1" .. mw.ustring.char(0x032F))
text = rsub(text, "u̯ʋ", "w")
text = rsub(text, "n%s([ˈˌ]?[pbmfv])", "m %1")
text = rsub(text, "n([pbmfv])", "m%1")
text = rsub(text, "n%s([ˈˌ]?[kɡχ])", "ŋ %1")
text = rsub(text, "n([kɡχ])", "ŋ%1")
-- /v/
text = rsub(text, "([ptkfsχ])v", "%1f")
-- /t/
text = rsub(text, "t", "tˢ")
text = rsub(text, "tˢ͡", "t͡")
return text
end
function export.IPA(frame)
local words = {}
for _, word in ipairs(frame:getParent().args) do
table.insert(words, word)
end
if #words == 0 then
error("Please add a first parameter for the pronunciation module!!")
end
local results_phon = {}
local results_nl = {}
for _, word in ipairs(words) do
table.insert(results_phon, { pron = "/" .. phonemic(word) .. "/" })
if frame:getParent().args["N"] ~= "-" then
table.insert(results_nl, { pron = "[" .. NL(word) .. "]" })
end
end
local show = ""
if #results_nl ~= 0 then
show = show .. '\n<div class="vsSwitcher" data-toggle-category="pronunciations"><span class="vsToggleElement"></span>'
end
show = show .. "\n*" .. m_IPA.format_IPA_full { lang = lang, items = results_phon }
if #results_nl ~= 0 then
show = show .. '<div class="vsHide">\n**' .. m_a.format_qualifiers(lang, {"Netherlands"}) ..
" " .. m_IPA.format_IPA_full { lang = lang, items = results_nl } .. '</div></div>'
end
return show
end
return export