モジュール:xkz-IPA
表示
このモジュールについての説明文ページを モジュール:xkz-IPA/doc に作成できます
local find = mw.ustring.find
local rsub = mw.ustring.gsub
local m_a = require("モジュール:accent qualifier")
local u = require("モジュール:string/char")
local export = {}
local m_IPA = require("モジュール:IPA")
local lang = require("モジュール:languages").getByCode("xkz")
local function format_accent(qual)
return m_a.format_qualifiers(lang, {qual})
end
local function phonetic(text, col)
text = rsub(text, "thr", "trh")
text = rsub(text, "â", "aː")
text = rsub(text, "ê", "eː")
text = rsub(text, "î", "iː")
text = rsub(text, "ô", "oː")
text = rsub(text, "û", "uː")
text = rsub(text, "^", "H")
text = rsub(text, " ", " H")
text = rsub(text, "H'([bpdtgkmnrlczswyh]+)([aeiouöü])", "%1'%2")
text = rsub(text, "H(t?[ptcksh]r?[sh]?[rylw]?)([aeiouöü])", "%1'%2")
text = rsub(text, "H([bdjgz][zhr]?[rylw]?)([aeiouöü])", "%1!%2")
text = rsub(text, "Hlh([aeiou])", "lh'%1")
text = rsub(text, "H([mnrlyw][ygr]?)([áéíóúöü])", "%1'%2")
text = rsub(text, "H([mnrlyw][ygr]?)([aeiouöü])", "%1!%2")
text = rsub(text, "H([aeiouöü])", "!%1")
text = rsub(text, "([ai])u", "%1u̯")
text = rsub(text, "([auo])i", "%1i̯")
text = rsub(text, "%!([aeiouöü])", "%1G")
text = rsub(text, "%'([aeiouöü])", "%1A")
text = rsub(text, "a", "ɐ")
text = rsub(text, "ng", "ŋ")
text = rsub(text, "lh", "l̥")
text = rsub(text, "ny", "ɲ")
text = rsub(text, "tr", "ʈ")
text = rsub(text, "dr", "ɖ")
text = rsub(text, "j", "ɟ")
text = rsub(text, "y", "j")
text = rsub(text, "([ptʈck]s?)h", "%1ʰ")
text = rsub(text, "[sz]h", "ç")
text = rsub(text, "c", "c͡ɕ")
text = rsub(text, "ɟ", "ɟ͡ʑ")
text = rsub(text, "ts", "t͡s")
text = rsub(text, "ʈ", "ʈ(r)")
text = rsub(text, "ɖ", "ɖ(r)")
text = rsub(text, "pj", "(p)c")
text = rsub(text, "mj([ɐeiouöü])", "(m)ɲ%1")
text = rsub(text, "b%.", "p.")
text = rsub(text, "b ", "p ")
text = rsub(text, "b$", "p$")
text = rsub(text, "d%.", "t.")
text = rsub(text, "d ", "t ")
text = rsub(text, "d$", "t$")
text = rsub(text, "g%.", "k.")
text = rsub(text, "g ", "k ")
text = rsub(text, "g$", "k$")
text = rsub(text, "g", "ɡ")
text = rsub(text, "t", "t̪")
text = rsub(text, "d", "d̪")
text = rsub(text, "%(r%)ʰ", "ʰ(r)")
text = rsub(text, "H", "")
if col == 1 then
text = rsub(text, "ü", "u")
text = rsub(text, "ö", "o")
elseif col == 2 then
text = rsub(text, "ü([AG]?)", "u%1i̯")
text = rsub(text, "ö([AG]?)", "o%1i̯")
end
text = rsub(text, "ü([AG]?)", "y%1ː")
text = rsub(text, "ö([AG]?)", "ø%1ː")
text = rsub(text, " $", "")
text = rsub(text, "^ ", "")
text = rsub(text, "G", "̀")
text = rsub(text, "A", "́")
text = rsub(text, "^([ɐeiouøy])", "ʔ%1")
text = rsub(text, " ([ɐeiouøy])", "ʔ%1")
return text
end
function export.IPA(frame)
local words = {}
for _, word in ipairs(frame:getParent().args) do
word = rsub(word, "་", ".")
word = require("モジュール:Tibt-translit").tr(word, "xkz", 'Tibt')
table.insert(words, word)
local test = word
word = rsub(word, "k ", "ː ")
word = rsub(word, "k$", "ː")
word = rsub(word, "s ", "ː ")
word = rsub(word, "s$", "ː")
word = rsub(word, "nː", "ng")
if word ~= test then
table.insert(words, word)
end
end
if #words == 0 then
word = rsub(mw.loadData("モジュール:headword/data").pagename, "་", ".")
word = require("モジュール:Tibt-translit").tr(word, "xkz", 'Tibt')
table.insert(words, word)
local test = word
word = rsub(word, "k ", "ː ")
word = rsub(word, "k$", "ː")
word = rsub(word, "s ", "ː ")
word = rsub(word, "s$", "ː")
word = rsub(word, "nː", "ng")
if word ~= test then
table.insert(words, word)
end
end
local IPA_results = {}
local IPA_col = {}
local IPA_edu = {}
for _, word in ipairs(words) do
if mw.ustring.match(word, "ü") or mw.ustring.match(word, "ö") then
table.insert(IPA_col, { pron = "[" .. phonetic(word, 1) .. "]" })
table.insert(IPA_edu, { pron = "[" .. phonetic(word, 2) .. "]" })
table.insert(IPA_edu, { pron = "[" .. phonetic(word, 3) .. "]" })
else
table.insert(IPA_results, { pron = "[" .. phonetic(word, 3) .. "]" })
end
end
if #IPA_col == 0 and #IPA_edu == 0 then
return m_IPA.format_IPA_full { lang = lang, items = IPA_results }
else
return "*" .. format_accent("口語") .. " " .. m_IPA.format_IPA_full { lang = lang, items = IPA_col } .. "\n*" ..
format_accent("educated") .. " " .. m_IPA.format_IPA_full { lang = lang, items = IPA_edu }
end
end
return export