မာတိကာသို့ ခုန်သွားရန်

မဝ်ဂျူ:sl-headword

နူ ဝိက်ရှေန်နရဳ

Documentation for this module may be created at မဝ်ဂျူ:sl-headword/doc

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

local export = {}


local function do_headwords(data)
	-- If the first headword given is "-", then skip the check.
	if data.heads[1] == "-" then
		data.heads[1] = ""
		return false
	end
	
	for i, head in ipairs(data.heads) do
		if head == "" or not require("Module:sl-common").has_accents(head) then
			
		end
	end
	
	return true
end


local function do_genders(data)
	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,
	}
	
	for i, g in ipairs(data.genders) do
		if g == "m" then
			g = "m-?"
		elseif not valid_genders[g] then
			g = "?"
		end
		
		data.genders[i] = g
		
		-- Categorize by gender
		if g == "m-an" then
			
			
		elseif g == "m-in" then
			
			
		elseif g:sub(1,1) == "m" then
			
		elseif g:sub(1,1) == "f" then
			
		elseif g:sub(1,1) == "n" then
			
		end
		
		-- Categorize by number
		if g:sub(3,3) == "d" then
			
		elseif g:sub(3,3) == "p" then
			
		end
	end
	
	if #data.genders > 1 then
		
	end
end


local function do_comparatives(data, comparatives, check_accents)
	local encoded_head = data.heads[1]
	
	if encoded_head == "" then
		encoded_head = nil
	end
	
	local comp_parts = {label = "[[:en:Appendix:Glossary#comparative|ပတုပ်ရံင်]]", request = true} --accel = {form = "comparative", lemma = encoded_head}
	local sup_parts = {label = "[[:en:Appendix:Glossary#superlative|သဒ္ဒာ]]"} --accel = {form = "superlative", lemma = 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 mw.title.getCurrentTitle().text))
			table.insert(sup_parts, "[[nȁjbolj]] " .. (data.heads[1] ~= "" and data.heads[1] or mw.title.getCurrentTitle().text))
		else
			table.insert(comp_parts, comp)
			table.insert(sup_parts, "nȁj" .. comp)
			
			if check_accents and not require("Module:sl-common").has_accents(comp) then
				
			end
		end
	end
	
	table.insert(data.inflections, comp_parts)
	table.insert(data.inflections, sup_parts)
end


function export.default(frame)
	local params = {
		[1] = {list = "head"},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = frame.args[1], categories = {}, heads = args[1], inflections = {}}
	
	local check_accents = do_headwords(data)
	
	return require("Module:headword").full_headword(data)
end


function export.adjectives(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "နာမဝိသေသန", categories = {}, heads = args[1], inflections = {}}
	
	local check_accents = do_headwords(data)

	-- Decide what to do next...
	if args[2][1] == "-" then
		table.insert(data.inflections, {label = "[[:en:Appendix:Glossary#comparable|ပတုပ်ရံင်]]ဟွံမာန်"})
	else
		do_comparatives(data, args[2], check_accents)
	end
	
	return require("Module:headword").full_headword(data)
end


function export.adverbs(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "ကြိယာဝိသေသန", categories = {}, heads = args[1], inflections = {}}
	
	local check_accents = do_headwords(data)

	-- Decide what to do next...
	if args[2][1] and args[2][1] ~= "-" then
		do_comparatives(data, args[2], check_accents)
	end
	
	return require("Module:headword").full_headword(data)
end


function export.nouns(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {list = "g", default = "?"},
		
		["f"] = {list = true},
		["m"] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "နာမ်", categories = {}, heads = args[1], genders = args[2], inflections = {}}
	
	local check_accents = do_headwords(data)
	do_genders(data)
	
	-- Female equivalent
	if #args["f"] > 0 then
		args["f"].label = "female equivalent"
		
		if check_accents then
			for i, form in ipairs(args["f"]) do
				if not require("Module:sl-common").has_accents(form) then
					
				end
			end
		end
		
		-- Tone check
		for i, form in ipairs(args["f"]) do
			local found_tonal = false
			local found_stress = false
			local found_ambiguous = false
			form = mw.ustring.lower(form)
			
			if mw.ustring.find(form, "[ȃȇȋȏȗȓāēīōūȁȅȉȍȕẹọ" .. mw.ustring.char(0x0304) .. "]") then
				found_tonal = true
			end
			
			if mw.ustring.find(form, "[êô]") then
				found_stress = true
			end
			
			if mw.ustring.find(form, "[áéíóúŕàèìòù]") then
				found_ambiguous = true
			end
			
			if found_stress then
				require("Module:debug").track("sl-headword/stress")
			elseif found_ambiguous then
				require("Module:debug").track("sl-headword/ambiguous")
			elseif found_tonal then
				require("Module:debug").track("sl-headword/tonal")
			end
		end
		
		table.insert(data.inflections, args["f"])
	end
	
	-- Male equivalent
	if #args["m"] > 0 then
		args["m"].label = "male equivalent"
		
		if check_accents then
			for i, form in ipairs(args["m"]) do
				if not require("Module:sl-common").has_accents(form) then
					
				end
			end
		end
		
		-- Tone check
		for i, form in ipairs(args["m"]) do
			local found_tonal = false
			local found_stress = false
			local found_ambiguous = false
			form = mw.ustring.lower(form)
			
			if mw.ustring.find(form, "[ȃȇȋȏȗȓāēīōūȁȅȉȍȕẹọ" .. mw.ustring.char(0x0304) .. "]") then
				found_tonal = true
			end
			
			if mw.ustring.find(form, "[êô]") then
				found_stress = true
			end
			
			if mw.ustring.find(form, "[áéíóúŕàèìòù]") then
				found_ambiguous = true
			end
			
			if found_stress then
				require("Module:debug").track("sl-headword/stress")
			elseif found_ambiguous then
				require("Module:debug").track("sl-headword/ambiguous")
			elseif found_tonal then
				require("Module:debug").track("sl-headword/tonal")
			end
		end
		
		table.insert(data.inflections, args["m"])
	end
	
	return require("Module:headword").full_headword(data)
end


function export.proper_nouns(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {list = "g", default = "?"},
		
		["f"] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "proper nouns", categories = {}, heads = args[1], genders = args[2], inflections = {}}
	
	local check_accents = do_headwords(data)
	do_genders(data)
	
	-- Female equivalent
	if #args["f"] > 0 then
		args["f"].label = "female equivalent"
		
		if check_accents then
			for i, form in ipairs(args["f"]) do
				if not require("Module:sl-common").has_accents(form) then
					table.insert(data.categories, "Requests for accents in Slovene noun entries")
				end
			end
		end
		
		table.insert(data.inflections, args["f"])
	end
	
	return require("Module:headword").full_headword(data)
end


function export.verbs(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {default = "?"},
		
		["impf"] = {list = true},
		["pf"] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "ကြိယာ", categories = {}, heads = args[1], genders = {args[2]}, inflections = {}}
	
	local check_accents = do_headwords(data)
	
	-- Check aspect
	if data.genders[1] == "impf" then
		
		
		if #args["impf"] > 0 then
			error("Imperfective verbs cannot have an imperfective equivalent")
		end
		
		-- Perfective equivalents
		if #args["pf"] > 0 then
			if check_accents then
				for _, form in ipairs(args["pf"]) do
					if require("Module:sl-common").has_accents(form) then
						
					end
				end
			end
			
			args["pf"].label = "perfective"
			table.insert(data.inflections, args["pf"])
		end
	elseif data.genders[1] == "pf" then
		table.insert(data.categories, "Slovene perfective verbs")
		
		if #args["pf"] > 0 then
			error("Perfective verbs cannot have a perfective equivalent")
		end
		
		-- Imperfective equivalents
		if #args["impf"] > 0 then
			if check_accents then
				for _, form in ipairs(args["impf"]) do
					if require("Module:sl-common").has_accents(form) then
						
					end
				end
			end
			
			args["impf"].label = "imperfective"
			table.insert(data.inflections, args["impf"])
		end
	elseif data.genders[1] == "both" then
		data.genders = {"impf", "pf"}
		table.insert(data.categories, "Slovene biaspectual verbs")
		
		if #args["impf"] > 0 or #args["pf"] > 0 then
			error("Bispectual verbs cannot have an imperfective or perfective equivalent")
		end
	else
		data.genders = {"?"}
		
	end
	
	return require("Module:headword").full_headword(data)
end

return export