ข้ามไปเนื้อหา

มอดูล:sl-headword

จาก วิกิพจนานุกรม พจนานุกรมเสรี

local m_common = require("Module:sl-common")

local export = {}

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

local pos_functions = {}

-- 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
	PAGENAME = mw.title.getCurrentTitle().text
	
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	-- หมวดหมู่เป็นภาษาไทย
	local poscat_th = require("Module:th-utilities").th_pos(poscat)

	local data = {lang = lang, pos_category = poscat_th, categories = {}, heads = {args[1] or ""}, genders = {}, inflections = {}}
	
	-- Gather headwords
	local i = 2
	local head = args["head" .. i]
	
	while head do
		if head ~= "" then
			table.insert(data.heads, head)
		end
		
		i = i + 1
		head = args["head" .. i]
	end
	
	-- Process headwords for accents
	local check_accents = true
	
	-- If the first headword given is "-", then skip the check.
	if data.heads[1] == "-" then
		data.heads[1] = ""
		check_accents = false
	else
		for i, head in ipairs(data.heads) do
			if head == "" or not m_common.has_accents(head) then
				table.insert(data.categories, "Slovene terms needing accents")
			end
		end
	end
	
	-- Call POS-specific function
	if pos_functions[poscat_th] then
		pos_functions[poscat_th](args, data, check_accents)
	end
	
	return require("Module:headword").full_headword(data)
end

-- Display additional inflection information for an adjective
pos_functions["คำคุณศัพท์"] = function(args, data, check_accents)
	-- Get all the parameters
	local comparatives = {}
	
	local i = 2
	
	while true do
		local comp = args[i]; if comp == "" then comp = nil end
		
		if not comp then
			break
		end
		
		table.insert(comparatives, comp)
		i = i + 1
	end
	
	-- Decide what to do next...
	local mode = comparatives[1]
	
	if mode == "-" then
		table.insert(data.inflections, {label = "not [[Appendix:Glossary#comparable|comparable]]"})
	else
		do_comparatives(data, comparatives, check_accents)
	end
end

-- Display additional inflection information for an adverb
pos_functions["คำกริยาวิเศษณ์"] = function(args, data, check_accents)
	-- Get all the parameters
	local comparatives = {}
	
	local i = 2
	
	while true do
		local comp = args[i]; if comp == "" then comp = nil end
		
		if not comp then
			break
		end
		
		table.insert(comparatives, comp)
		i = i + 1
	end
	
	-- Decide what to do next...
	local mode = comparatives[1]
	
	if mode and mode ~= "-" then
		do_comparatives(data, comparatives, check_accents)
	end
end

function do_comparatives(data, comparatives, check_accents)
	local encoded_head = ""
	
	if data.heads[1] ~= "" then
		-- This is decoded again by [[WT:ACCEL]].
		encoded_head = " origin-" .. data.heads[1]:gsub("%%", "."):gsub(" ", "_")
	end
	
	local comp_parts = {label = "ขั้นกว่า", accel = "comparative-form-of" .. encoded_head, request = true}
	local sup_parts = {label = "ขั้นสุด", accel = "superlative-form-of" .. encoded_head}
	
	for i, comp in ipairs(comparatives) do
		if comp == "bolj" then
			table.insert(comp_parts, "[[bòlj]] " .. (data.heads[1] ~= "" and data.heads[1] or PAGENAME))
			table.insert(sup_parts, "[[nàjbolj]] " .. (data.heads[1] ~= "" and data.heads[1] or PAGENAME))
		else
			table.insert(comp_parts, comp)
			table.insert(sup_parts, "nàj" .. comp)
			
			if check_accents and not m_common.has_accents(comp) then
				table.insert(data.categories, "Slovene terms needing accents")
			end
		end
	end
	
	table.insert(data.inflections, comp_parts)
	table.insert(data.inflections, sup_parts)
end

-- Display additional inflection information for a noun
pos_functions["คำนาม"] = function(args, data, check_accents)
	pos_functions["คำวิสามานยนาม"](args, data, check_accents)
	
	-- If the noun is dual/plural only, then ignore the 4th parameter altogether
	local num = data.genders[1]:sub(3,3)
	
	if num == "d" then
		table.insert(data.inflections, {label = "ทวิพจน์เท่านั้น"})
	elseif num == "p" then
		table.insert(data.inflections, {label = "พหูพจน์เท่านั้น"})
	else
		-- Get the plural parameters
		-- First get the 4th parameter. The remainder is named pl2=, pl3= etc.
		local form = args[4]; if form == "" then form = nil end
		local plurals = {form}
		local i = 2
		
		while true do
			form = args["pl" .. i]; if form == "" then form = nil end
			
			if not form then
				break
			end
			
			table.insert(plurals, form)
			i = i + 1
		end
		
		-- Decide what to do next...
		local mode = plurals[1]
		
		if mode == "-" then
			table.insert(data.inflections, {label = "นับไม่ได้"})
			table.insert(data.categories, "คำนามนับไม่ได้ภาษาสโลวีเนีย")
		else
			plurals.label = "กรรตุการกพหูพจน์"
			plurals.request = true
			
			for i, form in ipairs(plurals) do
				if check_accents and not m_common.has_accents(form) then
					table.insert(data.categories, "คำนามภาษาสโลวีเนียที่ต้องการการผัน")
				end
			end
			
			table.insert(data.inflections, plurals)
		end
	end
	
	-- Get the feminine parameters
	-- First get the f= parameter. The remainder is named f2=, f3= etc.
	local form = args["f"]; if form == "" then form = nil end
	local feminines = {form}
	local i = 2
	
	while true do
		form = args["f" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(feminines, form)
		i = i + 1
	end
	
	if #feminines > 0 then
		local f_parts = {label = "เพศหญิง"}
		
		for i, form in ipairs(feminines) do
			table.insert(f_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(data.categories, "Slovene nouns needing accents")
			end
		end
		
		table.insert(data.inflections, f_parts)
	end

	-- Get the masculine parameters
	-- First get the m= parameter. The remainder is named m2=, m3= etc.
	local form = args["m"]; if form == "" then form = nil end
	local masculines = {form}
	local i = 2
	
	while true do
		form = args["m" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(masculines, form)
		i = i + 1
	end
	
	if #masculines > 0 then
		local m_parts = {label = "เพศชาย"}
		
		for i, form in ipairs(masculines) do
			table.insert(m_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(data.categories, "Slovene nouns needing accents")
			end
		end
		
		table.insert(data.inflections, m_parts)
	end
end

-- Display additional inflection information for a proper noun
-- This is also used for nouns
pos_functions["คำวิสามานยนาม"] = function(args, data, check_accents)
	local valid_genders = {
		["m-?"] = true,
		["m-an"] = true,
		["m-in"] = true,
		["f"] = true,
		["n"] = true,
		["m-d"] = true,
		["f-d"] = true,
		["n-d"] = true,
		["m-p"] = true,
		["f-p"] = true,
		["n-p"] = true }
	
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	local g = args[2]; if g == "" then g = nil end
	local i = 2
	
	while g do
		if g == "m" then g = "m-?" end
		
		if not valid_genders[g] then
			g = "?"
		end
		
		table.insert(data.genders, g)
		
		-- Categorize by gender
		if g == "m-an" then
			table.insert(data.categories, "คำนามเพศชายภาษาสโลวีเนีย")
			table.insert(data.categories, "คำนามมีชีวิตภาษาสโลวีเนีย")
		elseif g == "m-in" then
			table.insert(data.categories, "คำนามเพศชายภาษาสโลวีเนีย")
			table.insert(data.categories, "คำนามไม่มีชีวิตภาษาสโลวีเนีย")
		elseif g:sub(1,1) == "m" then
			table.insert(data.categories, "คำนามเพศชายภาษาสโลวีเนีย")
		elseif g:sub(1,1) == "f" then
			table.insert(data.categories, "คำนามเพศหญิงภาษาสโลวีเนีย")
		elseif g:sub(1,1) == "n" then
			table.insert(data.categories, "คำนามเพศกลางภาษาสโลวีเนีย")
		end
		
		-- Categorize by number
		if g:sub(3,3) == "d" then
			table.insert(data.categories, "คำนามทวิพจน์เท่านั้นภาษาสโลวีเนีย")
		elseif g:sub(3,3) == "p" then
			table.insert(data.categories, "คำนามพหูพจน์เท่านั้นภาษาสโลวีเนีย")
		end
		
		g = args["g" .. i]; if g == "" then g = nil end
		i = i + 1
	end
	
	if #data.genders == 0 then
		table.insert(data.genders, "?")
	elseif #data.genders > 1 then
		table.insert(data.categories, "Slovene nouns with multiple genders")
	end
	
	-- Get the genitive parameters
	-- First get the 3rd parameter. The remainder is named gen2=, gen3= etc.
	local form = args[3]; if form == "" then form = nil end
	local genitives = {form}
	local i = 2
	
	while true do
		form = args["gen" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(genitives, form)
		i = i + 1
	end
	
	-- Show the forms
	genitives.label = "สัมพันธการก"
	genitives.request = true
	
	for i, form in ipairs(genitives) do
		if check_accents and not m_common.has_accents(form) then
			table.insert(data.categories, "Slovene nouns needing accents")
		end
	end

	table.insert(data.inflections, genitives)
end

-- Display additional inflection information for a verb
pos_functions["คำกริยา"] = function(args, data, check_accents)
	-- Aspect
	local aspect = args[2]; if aspect == "" then aspect = nil end
	
	if aspect == "impf" then
		table.insert(data.genders, "impf")
		table.insert(data.categories, "Slovene imperfective verbs")
	elseif aspect == "pf" then
		table.insert(data.genders, "pf")
		table.insert(data.categories, "Slovene perfective verbs")
	elseif aspect == "both" then
		table.insert(data.genders, "impf")
		table.insert(data.genders, "pf")
		table.insert(data.categories, "Slovene imperfective verbs")
		table.insert(data.categories, "Slovene perfective verbs")
	else
		table.insert(data.genders, "?")
		table.insert(data.categories, "Slovene verbs needing aspect")
	end
	
	-- Get all the parameters
	-- First get the 3rd and 4th parameters. The remainder is named pres2=, past2= etc.
	local pres = args[3]; if pres == "" then pres = nil end
	local past = args[4]; if past == "" then past = nil end
	local presents = {pres}
	local pasts = {past}
	local i = 2
	
	while true do
		pres = args["pres" .. i]; if pres == "" then pres = nil end
		past = args["past" .. i]; if past == "" then past = nil end
		
		if not pres and not past then
			break
		end
		
		if pres then table.insert(presents, pres) end
		if past then table.insert(pasts, past) end
		i = i + 1
	end
	
	-- Present tense (1st person singular)
	presents.label = "first-person singular present"
	presents.request = true
	
	for i, form in ipairs(presents) do
		if check_accents and not m_common.has_accents(form) then
			table.insert(data.categories, "Slovene verbs needing accents")
		end
	end
	
	table.insert(data.inflections, presents)
	
	-- Past tense (past active participle / l-participle)
	pasts.label = "past active participle"
	
	for i, form in ipairs(pasts) do
		if check_accents and not m_common.has_accents(form) then
			table.insert(data.categories, "Slovene verbs needing accents")
		end
	end
		
	table.insert(data.inflections, pasts)
end

return export