Module:User:AG202/jje-pron
Jump to navigation
Jump to search
- This module sandbox lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of AG202, for his own experimentation. Items in this module may be added and removed at AG202's discretion; do not rely on this module's stability.
local export = {}
local m_jje_utilities = require("Module:jje")
local m_data = mw.loadData("Module:jje-pron/data")
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local sub = mw.ustring.sub
local char = mw.ustring.char
local codepoint = mw.ustring.codepoint
local function tidy_phonetic(original, romanised)
local ori_index, rom_index, result = 1, 1, {}
for i = 1, mw.ustring.len(romanised) do
local romanised_syllable = mw.ustring.sub(romanised, rom_index, rom_index)
local original_syllable = mw.ustring.sub(original, ori_index, ori_index)
if romanised_syllable ~= original_syllable then
-- Handle cases of non-precomposed choseong character changing
if match(romanised_syllable, "[ᄀ-ᄒ]") then
-- Insert choseong
table.insert(result, '<b>'..romanised_syllable..'</b>')
-- Insert jungseong
romanised_syllable = mw.ustring.sub(romanised, rom_index + 1, rom_index + 1)
table.insert(result, '<b>'..romanised_syllable..'</b>')
-- Check if next character is jongseong; if so, insert, if not end iteration
-- and continue accoringly
romanised_syllable = mw.ustring.sub(romanised, rom_index + 2, rom_index + 2)
if match(romanised_syllable, "ᆨ-ᇝ") then
table.insert(w, '<b>'..romanised_syllable..'</b>')
ori_index, rom_index = ori_index + 2, rom_index + 2
if match(original_syllable, "[^ ]") then rom_index = rom_index + 1 end
if match(romanised_syllable, "[^ ]") then ori_index = ori_index + 1 end
else
ori_index, rom_index = ori_index + 1, rom_index + 1
if match(original_syllable, "[^ ]") then rom_index = rom_index + 1 end
if match(romanised_syllable, "[^ ]") then ori_index = ori_index + 1 end
end
-- Handle cases of non-precomposed jongseong character changing
elseif match(romanised_syllable, "[ᆨ-ᇝ]") then
-- Remove previous non-bold choseong & jungseong
table.remove(result, #result - 1)
table.remove(result, #result)
-- Insert choseong character
romanised_syllable_cho = mw.ustring.sub(romanised, rom_index - 2, rom_index - 2)
table.insert(result, '<b>'..romanised_syllable_cho..'</b>')
-- Insert jungseong character
romanised_syllable_jung = mw.ustring.sub(romanised, rom_index - 1, rom_index - 1)
table.insert(result, '<b>'..romanised_syllable_jung..'</b>')
-- Insert jongseong character
table.insert(result, '<b>'..romanised_syllable..'</b>')
if match(original_syllable, "[^ ]") then rom_index = rom_index + 1 end
if match(romanised_syllable, "[^ ]") then ori_index = ori_index + 1 end
-- Handle precomposed characters per typical method
else
table.insert(result, '<b>'..romanised_syllable..'</b>')
if match(original_syllable, "[^ ]") then rom_index = rom_index + 1 end
if match(romanised_syllable, "[^ ]") then ori_index = ori_index + 1 end
end
else
table.insert(result, '<span>'..romanised_syllable..'</span>')
ori_index, rom_index = ori_index + 1, rom_index + 1
end
end
return table.concat(result)
end
function export.make(frame, scheme)
return tidy_phonetic("ᄀᆞᇀ다 닷ᄀᆞ", "ᄀᆞᆮ따 닫ᄁᆞ")
end
return export