local M = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local lang = require("Modül:diller").getirKodaGore("ko")
-- makes hanjatab automatically
function M.hanjatab()
local hanja = mw.ustring.gsub(mw.title.getCurrentTitle().text, '', '')
local table_head = '<table class="floatright wikitable" style="text-align:center; font-size:small;"><tr><th colspan="' ..
mw.ustring.len(hanja) ..
'" style="font-weight:normal;">] in this term</th></tr><tr lang="ko" class="Kore" style="font-size:2em; background:white; line-height:1em;">'
return table_head ..
mw.ustring.gsub(hanja, '(.)', '<td style="padding:0.5em;">]</td>') ..
'</tr></table>'
end
-- return only non-hangeul contained in text
function M.remove_hangeul(f)
local nonhangeul = mw.ustring.gsub(f.args, '', '')
return nonhangeul
end
function M.boldify(f)
local pagename = mw.title.getCurrentTitle().text
hangul = f.args
if match(hangul, pagename) and not match(hangul, "'") then
hangul = gsub(hangul, pagename, "'''" .. pagename .. "'''")
end
return hangul
end
function M.usex_hangul(f)
local pagename = mw.title.getCurrentTitle().text
hangul = f.args
if match(hangul, pagename) and not match(hangul, "'") then
hangul = gsub(hangul, pagename, "'''" .. pagename .. "'''")
end
i = 1
local front, back = '<span style="background-color:#FEF8EA"><b>', '</b></span>'
for bold in mw.ustring.gmatch(hangul, "'''") do
hangul = gsub(hangul, "'''", (i % 2 == 1 and front or back), 1)
i = i + 1
end
hangul = gsub(hangul, '', '')
return hangul
end
function M.link(frame)
local arg = frame:getParent().args
local args, distances = {}, {}
local m_pron = require("Modül:ko-alfabeçeviri")
local curr_distance, closest_match = 1000, 0
local word, translit, definition, hanja, note = false, false, false, false, false
for i = 1, 4, 1 do
if arg and arg ~= "" then
table.insert(args, arg)
end
end
local curr_hangul_level, closest_hangul = 0, 0
for i, parameter in ipairs(args) do
local _, tentative_hangul_level = gsub(parameter, "", "")
if tentative_hangul_level > curr_hangul_level then
curr_hangul_level = tentative_hangul_level
closest_hangul = i
end
end
if curr_hangul_level > 0 then
word = args
table.remove(args, closest_hangul)
end
local function compute_distance(str1, str2)
local len1, len2 = #str1, #str2
local char1, char2, distance = {}, {}, {}
str1:gsub('.', function (c)
table.insert(char1, c) end)
str2:gsub('.', function (c)
table.insert(char2, c) end)
for i = 0, len1 do
distance = {}
end
for i = 0, len1 do
distance = i
end
for i = 0, len2 do
distance = i
end
for i = 1, len1 do
for j = 1, len2 do
distance = math.min(
distance + 1,
distance + 1,
distance + (char1 == char2 and 0 or 1)
)
end
end
return distance
end
local m_baglantilar = require("Modül:bağlantılar")
local test_translit = m_pron.tr_revised(m_baglantilar.kaldir_baglantilari(word or arg)) or ""
if arg and arg ~= "" then
note = arg
end
for i, parameter in ipairs(args) do
if not match(parameter, '') then
local tentative_distance = compute_distance(test_translit, parameter)
if tentative_distance < curr_distance then
curr_distance = tentative_distance
closest_match = i
end
end
end
if curr_distance < 3 and #args > 1 then
translit = args
table.remove(args, closest_match)
end
for i, parameter in ipairs(args) do
if match(parameter, "") then
hanja = parameter
table.remove(args, i)
end
end
if not hanja and not word then
word = args
table.remove(args, 1)
end
if #args > 1 then
translit = args
definition = args
elseif #args > 0 then
definition = args
end
if hanja and not match(hanja, "]") then
for hanja_word in mw.ustring.gmatch(hanja, "+") do
hanja = gsub(hanja, hanja_word, "]")
end
for hangul_word in mw.ustring.gmatch(hanja, "+") do
hanja = gsub(hanja, hangul_word, "]")
end
hanja = gsub(hanja, "%[%[%[%[", "[[")
hanja = gsub(hanja, "%]%]%]%]", "]]")
end
if arg or translit or test_translit then
translit = '<span lang="ko-Latn" class="mention-tr tr Latn">' ..
(arg or translit or test_translit) .. "</span>"
end
if definition then
if not match(definition, "^''.+''$") then definition = "“" .. definition .. "”" end
end
if hanja then
hanja = '<span lang="ko" class="Hani">' .. m_baglantilar.dil_bag({dil = lang, sozcuk = hanja}, true) .. '</span>'
end
word = gsub(word, "%^", "")
if not match(word, "]") then
if match(word, "^—.+—$") then
word = gsub(word, "—(.+)—", "—]—")
elseif match(word, "^—.+$") then
word = gsub(word, "—(.+)", "—]")
elseif match(word, "^.+—$") then
word = gsub(word, "(.+)—", "]")
elseif match(word, "^.+–$") then
word = gsub(word, "(.+)–", "]—")
elseif match(word, "^\*") then
word = gsub(word, "\*", "")
else
word = "]"
end
end
local info = {}
table.insert(info, word and (hanja or nil) or nil)
table.insert(info, translit or nil)
table.insert(info, definition or nil)
local result = word
and
("<span lang=\"ko\" class=\"Hang\">" .. word .. "</span>")
or
('<span lang="ko" class="Hani">' .. m_baglantilar.dil_bag({dil = lang, sozcuk = hanja}, true) .. '</span>')
if #info > 0 then
result = result .. " (" .. table.concat(info, ", ") .. ")"
end
if note then
result = result .. " (<i>" .. note .. "</i>)"
end
return result
end
function M.new(frame)
local args = frame:getParent().args
local function other(class, title, args)
local code = ""
if args then
code = code .. "\n\n===" .. title .. "===\n* {{ko-l|" .. args .. "}}"
if args then
code = code .. "\n* {{ko-l|" .. args .. "}}"
if args then
code = code .. "\n* {{ko-l|" .. args .. "}}"
if args then
code = code .. "\n* {{ko-l|" .. args .. "}}"
end
end
end
end
return code
end
local result = "==Korean=="
if args then
result = result .. "\n{{wikipedia|lang=ko}}"
end
result = result .. other("alt", "Alternative forms", args)
if args or args or args or args then
result = result .. "\n\n===Etymology===\n"
result = result .. (args or
("From {{etyl|" .. (args or "en") .. "|ko}} {{m|" ..
(args or "en") .. "|" .. args .. "}}."))
end
end
function M.decompose_jamo(syllable)
if not match(syllable, "") then
if match(syllable, "") then return { initial = syllable, vowel = "Ø", final = "Ø" }
elseif match(syllable, "") then return { initial = "Ø", vowel = syllable, final = "Ø" }
elseif match(syllable, "") then return { initial = "Ø", vowel = "Ø", final = syllable }
elseif match(syllable, "") then return { initial = "Ø", vowel = "Ø", final = syllable }
else return { initial = "Ø", vowel = " ", final = "X" } end
end
local char = mw.ustring.char
local cp = mw.ustring.codepoint(syllable)
if not cp then return { "", "", "" } end
local relative_cp = cp - 0xAC00
local jongseong = relative_cp % 28
local jungseong = math.floor((relative_cp % 588) / 28)
local choseong = math.floor(relative_cp / 588)
choseong, jungseong, jongseong =
char(0x1100 + choseong),
char(0x1161 + jungseong),
jongseong ~= 0 and char(0x11A7 + jongseong) or ""
return { initial = choseong, vowel = jungseong, final = jongseong }
end
return M