모듈:ko-headword

관련 모듈

편집

모듈:ko-pron 모듈:ko-translit


local PAGENAME = mw.title.getCurrentTitle().text

local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("ko")

pos_functions["동사"] = function(args, data)
	-- 부정사형
	local m_conj = require("Module:ko-conj").verb
	local hae = args["hae"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hae" })
	if hae == "" then hae = nil end
	local hae2 = args["hae2"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hae2" })
	if hae2 == "" then hae2 = nil end
	
	local infinitives = {label = "부정사형"}
	if hae then table.insert(infinitives, hae) end
	if hae2 then table.insert(infinitives, hae2) end
	if #infinitives > 0 then table.insert(data.inflections, infinitives) end
	
	-- 연결형
	local hani = args["hani"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hani" })
	if hani == "" then hani = nil end
	if hani then table.insert(data.inflections, {label = "연결어미형", hani}) end
	
	-- 명사형
	local nomi = args["nm"] 
	if nomi == "" then nomi = nil end
	if nomi then table.insert(data.inflections, {label = "명사형", nomi}) end
	
	-- 사동사(causative verb)
	local cauv = args["cv"]
	if cauv == "" then cauv = nil end
	if cauv then table.insert(data.inflections, {label = "사동사", cauv}) end
end

pos_functions["형용사"] = function(args, data)
	local m_conj = require("Module:ko-conj").adjective
	local hae = args["hae"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hae" })
	if hae == "" then hae = nil end
	local hae2 = args["hae2"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hae2" })
	if hae2 == "" then hae2 = nil end
	
	local infinitives = {label = "부정사형"}
	if hae then table.insert(infinitives, hae) end
	if hae2 then table.insert(infinitives, hae2) end
	if #infinitives > 0 then table.insert(data.inflections, infinitives) end
	
	-- sequential
	local hani = args["hani"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hani" })
	
	if hani then table.insert(data.inflections, {label = "연결어미형", hani}) end
end

pos_functions["suffixes"] = function(args, data)
	local hae = args["hae"]; if hae == "" then hae = nil end
	local hae2 = args["hae2"]; if hae2 == "" then hae2 = nil end
	
	local infinitives = {label = "부정사형"}
	if hae then table.insert(infinitives, hae) end
	if hae2 then table.insert(infinitives, hae2) end
	if #infinitives > 0 then table.insert(data.inflections, infinitives) end
	
	-- sequential
	local hani = args["hani"]; if hani == "" then hani = nil end
	
	if hani then table.insert(data.inflections, {label = "연결어미형", hani}) end
end

pos_functions["adjective forms"] = function(args, data)
	local root = args["root"]; if root == "" then root = nil end
	local form = args["form"]; if form == "" then form = nil end
	
	if form and root then
		table.insert(data.inflections, {label = form .. " of", root})
	end
end

pos_functions["verb forms"] = pos_functions["adjective forms"]

pos_functions["determiners"] = function(args, data)
	local root = args["root"]; if root == "" then root = nil end

	if root then table.insert(data.inflections, {label = "determinative form of", root}) end
end

pos_functions["명사"] = function(args, data)
	local vbfm = args["vf"]
	if vbfm == "" then vbfm = nil end
	if vbfm then table.insert(data.inflections, {label = "동사형", vbfm}) end
	
	local count = args["count"]; if count == "" then count = nil end
	
	if count == '-' then 
		table.insert(data.inflections, "불가산")
	elseif count then
		table.insert(data.inflections, {label = "종별사", count})
	end
end

-- other parts of speech: nothing special is done for adverbs, interjections, suffixes

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local args = frame:getParent().args
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	local hangeul_pattern = '[ᄀ-ᄒ".."ᅡ-ᅵ".."ᆨ-ᇂ" .. "ㄱ-ㆎ가-힣 ()!?-]' -- includes other punctuation that could appear in |head=
	local hanja_pattern = '[一-鿿㐀-䶿﨎﨏﨑﨓﨔﨟﨡﨣﨤﨧-﨩]'
	
	local params = {
		["head"] = {},

		[1] = {list = true},
		["hangeul"] = {},
		["hanja"] = {},
		["한자"] = { alias_of = "hanja" },
		["occasional hanja"] = {},

		["rv"] = {},
		["rr"] = {alias_of = "rv"}, -- 
		["mr"] = {}, -- 변형어근, modified root. ex) 듣다의 어간 '들-''
		["변형어근"] = { alias_of = "mr" },
		["nm"] = {}, -- 명사화된 형태, nominalization. ex) 안다와 '앎'
		["명사형"] = { alias_of = "nm" },
		["cv"] = {},
		["사동사"] = { alias_of = "cv" }, -- 사동사 형태 ex) 듣다와 '들리다'
		["vf"] = {},
		["동사형"] = { alias_of = "vf" }, -- 어떤 명사의 원형인 동사 형태 ex) 이름과 '이르다'
		["y"] = {},

		["count"] = {},
		["종별사"] = { alias_of = "count" },
		["form"] = {},
		["hae"] = {},
		["hae2"] = {},
		["hani"] = {},
		["irreg"] = {},
		["root"] = {},
	}
	args = require("Module:parameters").process(args, params)
	
	local data = {lang = lang, pos_category = poscat, categories = {}, heads = {args["head"]}, translits = {}, inflections = {}, sort_key = args["hangeul"], sc = require("Module:scripts").getByCode("Kore")}
	
	-- categorize by part of speech
	if poscat == "auxiliary verbs" then
		data.pos_category = "verbs"
		table.insert(data.categories, "Korean auxiliary verbs")
	end
	
	if args["irreg"] then table.insert(data.inflections, { label = "irregular" }) end
	
	-- grammatical forms etc. for each respective part of speech
	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end	
	
	-- >>> transliterations <<<
	-- if this entry is hangeul and no transliteration is provided, add auto transliteration
	-- if this entry is NOT hangeul and no translit is provided, add auto translit if there is hangeul
	local head_or_PAGENAME_no_links = require("Module:links").remove_links(args["head"] or PAGENAME)
	if args["rv"] then
		-- no need to do anything
	elseif mw.ustring.gsub(head_or_PAGENAME_no_links, hangeul_pattern, '') == "" then
		args["rv"] = lang:transliterate(head_or_PAGENAME_no_links)
	elseif args["hangeul"] then
		args["rv"] = lang:transliterate(args["hangeul"])
	else
		error('Could not produce transliteration. There may be non-hangeul characters in the entry title.')
	end
	if poscat == 'proper nouns' then
		args["rv"] = mw.ustring.upper(mw.ustring.sub(args["rv"],1,1)) .. mw.ustring.sub(args["rv"],2,-1)
	end
	
	-- 2021 August 2: transition from unhyphenated *fix page titles to hyphenated *fix page titles
	if not string.match(PAGENAME, '%-') then
		if poscat == "suffixes" then
			args["rv"] = "-" .. args["rv"]
			data.heads[1] = "—" .. (args["head"] or PAGENAME)
		elseif poscat == "prefixes" then
			args["rv"] = args["rv"] .. "-"
			data.heads[1] = (args["head"] or PAGENAME) .. "—"
		end
	end
	
	if args["rv"] then table.insert(data.translits, args["rv"]) end
	if args["mr"] then table.insert(data.translits, "McCune-Reischauer: " .. args["mr"]) end
	if args["y"] then table.insert(data.translits, "Yale: " .. args["y"]) end
	
	if args["hangeul"] then
		table.insert(data.inflections, {label = "hangeul", { term = args["hangeul"], sc = require("Module:scripts").getByCode("Kore") }})
	end
	
	if args["hanja"] then
		table.insert(data.inflections, {label = "한자", { term = args["hanja"], sc = require("Module:scripts").getByCode("Kore") }})
	end
	
	if args["occasional hanja"] then
		table.insert(data.inflections, {label = "usually no hanja; sometimes", { term = args["occasional hanja"], sc = require("Module:scripts").getByCode("Kore") }})
	end
	
	-- and categorize hanja terms
	if mw.ustring.match(PAGENAME, hanja_pattern) then
		if poscat == "nouns" then 
			table.insert(data.categories, "Korean nouns in Han script") 
		elseif poscat == "proper nouns" then 
			table.insert(data.categories, "Korean proper nouns in Han script") 
		end
	elseif mw.ustring.match(PAGENAME, hangeul_pattern) then
		local content = mw.title.new(PAGENAME):getContent()
		if content then
			local code = mw.ustring.match(content, '{{ko%-IPA[^}]*}}')
			if not code then code = mw.ustring.match(content, '{{ko%-ipa[^}]*}}') end
			if not code then code = mw.ustring.match(content, '{{ko%-pron[|}]') end
			if not code then table.insert(data.categories, "Korean terms without ko-IPA template") end
		end
	end
	
	-- maintenance category for hanja terms without hangeul
	if mw.ustring.match(PAGENAME, hanja_pattern) and args["hangeul"] == nil then 
		table.insert(data.categories, "Korean hanja terms lacking hangeul")
	end
	
	return require("Module:headword").full_headword(data)
end

return export