A modult a Modul:nan-pron-Hainan/doc lapon tudod dokumentálni
-- Mostly based on 《海南方言研究》 by 陳波
local export = {}
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local len = mw.ustring.len
local match = mw.ustring.match
local split = mw.text.split
local gsplit = mw.text.gsplit
local initial_ipa = {
= "ɓ", = "pʰ", = "m", = "b",
= "t", = "ɗ", = "d", = "n", = "l",
= "k", = "ɡ", = "ŋ", = "x", = "ɦ",
= "t͡ɕ", = "ɕ", = "d͡ʑ",
= "ʔ"
}
local final_ipa = {
= "i", = "u",
= "a", = "ia", = "ua",
= "o", = "io",
= "e", = "ue",
= "ai", = "uai",
= "oi", = "ui",
= "au", = "iau",
= "ou", = "iu",
= "am", = "iam",
= "om", = "iom",
= "an", = "uan",
= "ien", = "uon",
= "aŋ", = "iaŋ", = "uaŋ",
= "eŋ",
= "oŋ", = "ioŋ",
= "ap", = "iap",
= "op", = "iop",
= "at", = "uat",
= "iet", = "uot",
= "ak", = "iak", = "uak",
= "ek",
= "ok", = "iok",
= "iʔ", = "uʔ",
= "aʔ", = "iaʔ", = "uaʔ",
= "oʔ", = "ioʔ",
= "eʔ", = "ueʔ",
= "oiʔ"
}
local tone_chao = {
= "³³", = "²²", = "³¹",
= "¹¹", = "⁴²", = "⁵³",
= "⁵", = "⁵³", = "³", = "⁴²",
= "⁵⁵", = "¹"
}
-- find the tone of the first syllable in a two-syllable word
-- returns nil if the tone of the first syllable does not change
local function tone_sandhi(tone1, tone2)
if (tone1 == "1") or (tone1 == "4" and match(tone2, "")) or (tone1 == "6" and match(tone2, "")) then
return "5"
elseif match(tone1, "") and tone2 ~= "4" then
return "4"
elseif tone1 == "3" and match(tone2, "") then
return "6"
elseif (tone1 == "3" and match(tone2, "")) or (tone1 == "7" and match(tone2, "")) then
return "1"
elseif tone1 == "4" and match(tone2, "") then
return "4S"
elseif tone1 == "4" and match(tone2, "") then
return "7B"
elseif tone1 == "8" then
return "8S"
end
end
-- convert Hainanese Pinyin to IPA
function export.ipa(text)
if type(text) == "table" then
text = text.args
end
local result = {}
for word in gsplit(text, "/") do
local syllables = split(word, " ")
local initial, final, tone, sandhi, ipa = {}, {}, {}, {}, {}
for i, syllable in ipairs(syllables) do
initial, final, tone = match(syllable, "^(??)(??g?)()$")
if match(tone, "") then
tone = tone .. (match(final, "h$") and "B" or "A")
end
end
if #syllables == 2 then
sandhi = tone_sandhi(tone, tone)
end
for i=1,#syllables,1 do
actual_tone = tone_chao] .. (sandhi and "⁻" .. tone_chao] or "")
ipa = initial_ipa] .. final_ipa] .. actual_tone
end
table.insert(result, table.concat(ipa, " "))
end
return "/" .. table.concat(result, "/, /") .. "/"
end
function export.rom(text)
text = gsub(text, "/", " / ")
text = gsub(text, '(+)', '<sup>%1</sup>')
return text
end
return export