Module:User:Kalexchu/1

local export = {} local m_ltc_pron = require('Module:ltc-pron') local m_ltc_predict = require('Module:ltc-pron/predict') local m_cmn_pron = require('Module:cmn-pron') local data = mw.loadData('Module:ltc-pron/data')

local function replace_sup(text) local a = text a = mw.ustring.gsub(a, '1', '¹') a = mw.ustring.gsub(a, '2', '²') a = mw.ustring.gsub(a, '3', '³') a = mw.ustring.gsub(a, '4', '⁴') a = mw.ustring.gsub(a, '5', '⁵') a = mw.ustring.gsub(a, '6', '⁶') a = mw.ustring.gsub(a, 'H', 'ᴴ') a = mw.ustring.gsub(a, 'X', 'ˣ') return a end

function export.fanqie(text) local t = mw.text.split(text, '', true) if t[3] then return error('More than two characters detected') end local out = t[1] .. t[2] .. '切' local data_1 = mw.loadData('Module:zh/data/ltc-pron/' .. t[1]) local data_2 = mw.loadData('Module:zh/data/ltc-pron/' .. t[2]) local initial_type, final_type, tone_number, tone_symbol, rime_1, rime_2 = {}, {}, {}, {}, {}, {} for i,v in ipairs(data_1) do		initial_type[i] = m_ltc_pron.infer_categories(v) table.insert(rime_1, v)	end for i,v in ipairs(data_2) do		final_type[i] = select(2, m_ltc_pron.infer_categories(v)) tone_number[i] = data.tone_number[mw.ustring.sub(v, 6, 6)] tone_symbol[i] = data.tone_symbol[mw.ustring.sub(v, 6, 6)] table.insert(rime_2, v)	end out = out .. '\n' .. t[1] .. ': ' .. table.concat(rime_1, ', ') out = out .. '\n' .. t[2] .. ': ' .. table.concat(rime_2, ', ') local mc_reading, predicted_cmn, predicted_yue = {}, {}, {} for i,v in ipairs(initial_type) do		for j,w in ipairs(final_type) do table.insert(mc_reading, replace_sup(data.initialConv['Zhengzhang'][initial_type[i]] .. data.finalConv['Zhengzhang'][final_type[j]] .. tone_symbol[j])) table.insert(predicted_cmn, m_cmn_pron.py_number_to_mark(m_ltc_predict.predict_cmn(initial_type[i], final_type[j], tone_number[j]))) table.insert(predicted_yue, replace_sup(m_ltc_predict.predict_yue(initial_type[i], final_type[j], tone_number[j]))) end end out = out .. '\nMiddle Chinese: ' .. table.concat(mc_reading, ', ') out = out .. '\nPredicted Mandarin: ' .. table.concat(predicted_cmn, ', ') out = out .. '\nPredicted Cantonese: ' .. table.concat(predicted_yue, ', ') return out end

return export