A modult a Modul:mnp-pron/doc lapon tudod dokumentálni
local export = {}
local gsub = mw.ustring.gsub
local gsplit = mw.text.gsplit
local match = mw.ustring.match
local initial_ipa = {
= "p", = "pʰ", = "m",
= "t", = "tʰ", = "n", = "l",
= "t͡s", = "t͡sʰ", = "s",
= "k", = "kʰ", = "ŋ", = "x",
= "",
}
local final_ipa = {
= "i", = "u", = "y",
= "a", = "ia", = "ua",
= "ɛ", = "iɛ", = "uɛ", = "yɛ",
= "ɔ", = "iɔ",
= "e", = "œ", = "o",
= "ai", = "uai",
= "au", = "iau",
= "iu",
= "iŋ", = "uiŋ", = "yiŋ",
= "aŋ", = "iaŋ", = "uaŋ",
= "ɔŋ", = "ɔŋ", = "iɔŋ", = "iɔŋ", = "uɔŋ",
= "eiŋ", --missing /ieiŋ/
= "œyŋ",
= "aiŋ", = "uaiŋ",
}
local tone_marks = ""
local tone_from_mark = {
= 1, --陰平 (acute)
= 3, --陽平 (circumflex)
= 2, --上 (caron)
= 3, --陰去 (double overline)
= 4, --陽去 (macron)
= 5, --陰入 (breve)
= 6, --陽入 (grave)
}
local tone_value = {
= "⁵⁴", --陰平
= "²¹", --上
= "³³", --陰去
= "⁵⁵", --陽去
= "²⁴", --陰入
= "⁴²", --陽入
}
--[=[
Given a syllable, return tone value of the syllable's tone and the syllable without the tone mark
]=]
local function get_tone_value(syllable)
if match(syllable, "̄̄") then -- check for double macron
local corrected = gsub(syllable, "̄̄", "̿")
error("Please change " .. syllable .. " to " .. corrected .. ".")
end
local tone = match(syllable, tone_marks)
if tone then
return tone_value], gsub(syllable, tone, "")
else
error("No tone detected.")
end
end
function export.rom(text)
text = gsub(text, "/", " / ")
text = gsub(text, ">(+)", "<sup>→%1</sup>")
return text
end
function export.ipa(text)
text = mw.ustring.toNFD(mw.ustring.lower(text))
local words_ipa = {}
for word in gsplit(text, "/") do
word = gsub(word, " ", "-")
syllables_ipa = {}
for syllable in gsplit(word, "-") do
syllable = match(syllable, ">(.*)$") or syllable
local initial, final, tone_value
tone_value, syllable = get_tone_value(syllable)
initial, final = match(syllable, "^(??)(+)$")
initial, final = mw.ustring.toNFC(initial), mw.ustring.toNFC(final)
initial, final = initial_ipa, final_ipa
table.insert(syllables_ipa, initial..final..tone_value)
end
table.insert(words_ipa, table.concat(syllables_ipa, " "))
end
return "/" .. table.concat(words_ipa, "/, /") .. "/"
end
return export