Module:User:Wyang/ko-pron-summary

local export = {} local char = mw.ustring.char local sub = mw.ustring.sub

local m_pron = require("Module:ko-pron").romanise local decompose_jamo = require("Module:ko").decompose_jamo

local jamo = { initial = { { -1, "Ø" }, { 0, "ᄀ" }, { 1, "ᄁ" }, { 2, "ᄂ" }, { 3, "ᄃ" }, { 4, "ᄄ" }, { 5, "ᄅ" }, { 6, "ᄆ" }, { 7, "ᄇ" }, { 8, "ᄈ" }, { 9, "ᄉ" }, { 10, "ᄊ" }, { 11, "ᄋ" }, { 12, "ᄌ" }, { 13, "ᄍ" }, { 14, "ᄎ" }, { 15, "ᄏ" }, { 16, "ᄐ" }, { 17, "ᄑ" }, { 18, "ᄒ" }, },	vowel = { { 0, "ᅡ" }, { 1, "ᅢ" }, { 2, "ᅣ" }, { 3, "ᅤ" }, { 4, "ᅥ" }, { 5, "ᅦ" }, { 6, "ᅧ" }, { 7, "ᅨ" }, { 8, "ᅩ" }, { 9, "ᅪ" }, { 10, "ᅫ" }, { 11, "ᅬ" }, { 12, "ᅭ" }, { 13, "ᅮ" }, { 14, "ᅯ" }, { 15, "ᅰ" }, { 16, "ᅱ" }, { 17, "ᅲ" }, { 18, "ᅳ" }, { 19, "ᅴ" }, { 20, "ᅵ" }, },	final = { { 0, "Ø" }, { 1, "ᆨ" }, { 2, "ᆩ" }, { 3, "ᆪ" }, { 4, "ᆫ" }, { 5, "ᆬ" }, { 6, "ᆭ" }, { 7, "ᆮ" }, { 8, "ᆯ" }, { 9, "ᆰ" }, { 10, "ᆱ" }, { 11, "ᆲ" }, { 12, "ᆳ" }, { 13, "ᆴ" }, { 14, "ᆵ" }, { 15, "ᆶ" }, { 16, "ᆷ" }, { 17, "ᆸ" }, { 18, "ᆹ" }, { 19, "ᆺ" }, { 20, "ᆻ" }, { 21, "ᆼ" }, { 22, "ᆽ" }, { 23, "ᆾ" }, { 24, "ᆿ" }, { 25, "ᇀ" }, { 26, "ᇁ" }, { 27, "ᇂ" }, }, }

function get_jamo_char(i, v, f)	if i == -1 then return "" end return char(0xAC00 + i * 588 + v * 28 + f) end

function format_Korean(text) return ' ' .. text .. ' ' end

function export.make(frame) local summary_set = {} local conversion_type = frame.args[1] local summary = { '{| class="wikitable"' } table.sort(jamo.initial, function(first, second) return first[1] < second[1] end) table.sort(jamo.final, function(first, second) return first[1] < second[1] end) for _, final_data in pairs(jamo.final) do		final_id, final_char = final_data[1], final_data[2] for _, initial_data in pairs(jamo.initial) do			initial_id, initial_char = initial_data[1], initial_data[2] local char_seq = get_jamo_char(11, 0, final_id) .. get_jamo_char(initial_id, 0, 0) local conversion = m_pron(char_seq, conversion_type, "") if conversion_type == "ipa" then conversion = ' ' .. conversion .. ' '				conversion = mw.ustring.gsub(conversion, "a̠", "") end if conversion_type ~= "ph" and conversion_type ~= "ipa" then conversion = mw.ustring.gsub(conversion, "a", "") end summary_set[final_char .. "-" .. initial_char] = conversion end end table.insert(summary, '\n|-\n! ') for _, initial_data in pairs(jamo.initial) do table.insert(summary, "!!" .. format_Korean(initial_data[2]) .. "") end for _, final_data in pairs(jamo.final) do table.insert(summary, "\n|-\n|" .. format_Korean(final_data[2]) .. "") for _, initial_data in pairs(jamo.initial) do table.insert(summary, '||' .. summary_set[final_data[2] .. "-" .. initial_data[2]]) end end table.insert(summary, "\n|}") return table.concat(summary) end

function phonetic_tidying_up(text) text = mw.ustring.gsub(text, '%<[^%>]+%>', '') text = decompose_jamo(sub(text, 1, 1)).final .. (sub(text, 2, 2) and decompose_jamo(sub(text, 2, 2)).initial or "") return format_Korean(text) end

function export.make_two(frame) local summary_set, summary = {}, { '{|class="wikitable"\n!Final-Initial!!Phonetic Hangul!!RR!!RRR!!MR!!YR!!IPA' } table.sort(jamo.initial, function(first, second) return first[1] < second[1] end) table.sort(jamo.final, function(first, second) return first[1] < second[1] end) for _, final_data in pairs(jamo.final) do		final_id, final_char = final_data[1], final_data[2] for _, initial_data in pairs(jamo.initial) do			initial_id, initial_char = initial_data[1], initial_data[2] local i_f_combination = final_char .. "-" .. initial_char summary_set[i_f_combination] = {} local char_seq = get_jamo_char(11, 0, final_id) .. get_jamo_char(initial_id, 0, 0) for _, conversion_type in ipairs({ "ph", "rr", "rrr", "mr", "yr", "ipa" }) do				local conversion = m_pron(char_seq, conversion_type, "") if conversion_type == "ipa" then conversion = ' ' .. conversion .. ' '					conversion = mw.ustring.gsub(conversion, "a̠", "") end if conversion_type ~= "ph" and conversion_type ~= "ipa" then conversion = mw.ustring.gsub(conversion, "a", "") elseif conversion_type == "ph" then conversion = phonetic_tidying_up(conversion) end table.insert(summary_set[i_f_combination], conversion) end end end for _, final_data in pairs(jamo.final) do		for _, initial_data in pairs(jamo.initial) do local i_f_combination = final_data[2] .. "-" .. initial_data[2] table.insert(summary, "\n|-\n!" .. format_Korean(i_f_combination) .. "\n|" .. 				table.concat(summary_set[i_f_combination], '||')) end end return table.concat(summary, "\n") .. "\n|}" end

function export.make_three(frame) local summary_set, summary = {}, { '{|class="wikitable"\n!Vowel!!Phonetic Hangul!!RR!!RRR!!MR!!YR!!IPA' } table.sort(jamo.vowel, function(first, second) return first[1] < second[1] end) for _, vowel_data in ipairs(jamo.vowel) do table.insert(summary, "\n|-\n|" .. format_Korean(vowel_data[2]) .. "") local vowel_char = get_jamo_char(11, vowel_data[1], 0) for _, conversion_type in ipairs({ "ph", "rr", "rrr", "mr", "yr", "ipa" }) do			local conversion = m_pron(vowel_char, conversion_type, "") if conversion_type == "ipa" then conversion = ' ' .. conversion .. ' '				conversion = mw.ustring.gsub(conversion, "[%[%]]", "") conversion = mw.ustring.gsub(conversion, "~ ɥi", "~ y") elseif conversion_type == "ph" then conversion = format_Korean(conversion) end table.insert(summary, "||" .. conversion) end end table.insert(summary, "\n|}") return table.concat(summary) end

return export