Module:fy-headword

De neikommende dokumintaasje stiet op Module:fy-headword/dokumintaasje. [bewurkje]

Wurdt noch oanpast.


local export = {}
local pos_functions = {}

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

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	PAGENAME = mw.title.getCurrentTitle().text
	
	-- The part of speech. This is also the name of the category that
	-- entries go in. However, the two are separate (the "cat" parameter)
	-- because you sometimes want something to behave as an adjective without
	-- putting it in the adjectives category.
	local poscode = frame.args[1] or error("Wurdsoarte is net opjûn. Jou a.j.w. parameter 1 by it oanroppen fan 'e module.")
	
	local params = {
		["head"] = {list = true, default = ""},
		-- Parameters fan Berjocht:-fy- - PiefPafPier
		["tref"] = {alias_of = "head"},
		["leb"] = {list = true},
		["-"] = {},
	}
	
	if pos_functions[poscode] then
		for key, val in pairs(pos_functions[poscode].params) do
			params[key] = val
		end
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lemmas = mw.loadData("Module:headword/data").lemmas
	local nonlemmas = mw.loadData("Module:headword/data").nonlemmas
	local poscat = lemmas[poscode] or nonlemmas[poscode] or error("De wurdsoartkoade \"" .. poscode .. "\" is net jildich.")
	
	local data = {lang = lang, pos_category = poscat, categories = {}, heads = args["head"], genders = {}, inflections = {}, tracking_categories = {}}
	
	if pos_functions[poscode] then
		pos_functions[poscode].func(args, data)
	end
	
	return require("Module:headword").full_headword(data) ..
		require("Module:utilities").format_categories(data.tracking_categories, lang, nil)
end

-- Display additional inflection information for an adjective
pos_functions["adjek"] = {
	params = {
		[1] = {},
		[2] = {list = "comp"},
		[3] = {list = "sup"},
		[4] = {},
		},
	func = function(args, data)
		local mode = args[2][1]
		
		if mode == "inv" then
			table.insert(data.inflections, {label = "[[Wikiwurdboek:Glossarium#net bûchber|net bûchber]]"})
			table.insert(data.categories, "Net-bûchbere eigenskipswurden yn it Frysk")
			args[2][1] = args[3][1]
			args[3][1] = args[4]
		elseif mode == "pred" then
			table.insert(data.inflections, {label = "allinne [[predikatyf]] brûkt"})
			table.insert(data.categories, "Allinne-predikative eigenskipswurden yn it Frysk")
			args[2][1] = args[3][1]
			args[3][1] = args[4]
		end
		
		local comp_mode = args[2][1]
		
		if comp_mode == "-" then
			table.insert(data.inflections, {label = "gjin [[Wikiwurdboek:Glossarium#graadbûging|graadbûging]]"})
		else
			-- Gather parameters
			local comparatives = args[2]
			comparatives.label = "[[Wikiwurdboek:Glossarium#meartrime|meartrime]]"
			
			local superlatives = args[3]
			superlatives.label = "[[Wikiwurdboek:Glossarium#measttrime|measttrime]]"
			
			-- Generate forms if none were given
			if #comparatives == 0 then
				if mode == "inv" or mode == "pred" then
					table.insert(comparatives, "peri")
				else
					table.insert(comparatives, require("Module:fy-adjectives").make_comparative(PAGENAME))
				end
			end
			
			if #superlatives == 0 then
				if mode == "inv" or mode == "pred" then
					table.insert(superlatives, "peri")
				else
					-- Add preferred periphrastic superlative, if necessary
					if
						-- PAGENAME:find("[iï]de$") or PAGENAME:find("[^eio]e$") or
						-- PAGENAME:find("s$") or PAGENAME:find("sch$") or PAGENAME:find("x$") or
						-- PAGENAME:find("sd$") or PAGENAME:find("st$") or PAGENAME:find("sk$") then
						-- ? - PiefPafPier
						PAGENAME:find("[iï]de$") or PAGENAME:find("[^eio]e$") or PAGENAME:find("s[dtk]?$") then
						table.insert(superlatives, "peri")
					end
					
					table.insert(superlatives, require("Module:fy-adjectives").make_superlative(PAGENAME))
				end
			end
			
			-- Replace "peri" with phrase
			for key, val in ipairs(comparatives) do
				if val == "peri" then comparatives[key] = "[[mear]] " .. PAGENAME end
			end
			
			for key, val in ipairs(superlatives) do
				if val == "peri" then superlatives[key] = "[[meast]] " .. PAGENAME end
			end
			
			table.insert(data.inflections, comparatives)
			table.insert(data.inflections, superlatives)
		end
	end
}
pos_functions["adjec"] = pos_functions["adjek"]

-- -- Display additional inflection information for an adverb
-- pos_functions["adverb"] = {
-- 	params = {
-- 		[1] = {},
-- 		[2] = {},
-- 		[3] = {},
-- 		},
-- 	func = function(args, data)
-- 		local comp = args[2]
-- 		local sup = args[3]
-- 		
-- 		if comp then
-- 			if not sup then
-- 				sup = PAGENAME .. "st"
-- 			end
-- 			
-- 			table.insert(data.inflections, {label = "[[Wikiwurdboek:Glossarium#meartrime|meartrime]]", comp})
-- 			table.insert(data.inflections, {label = "[[Wikiwurdboek:Glossarium#measttrime|measttrime]]", sup})
-- 		end
-- 	end
-- }
-- 
-- -- Display information for a noun's gender
-- -- This is separate so that it can also be used for proper nouns
-- function noun_gender(args, data)
-- 	for _, g in ipairs(args[2]) do
-- 		if g == "c" then
-- 			table.insert(data.categories, "Haadwurden mei mienskiplik geslacht yn it Frysk")
-- 		elseif g == "p" then
-- 			table.insert(data.categories, "Pluralia tantum yn it Frysk")
-- 		elseif g ~= "m" and g ~= "f" and g ~= "n" then
-- 			g = nil
-- 		end
-- 		
-- 		table.insert(data.genders, g)
-- 	end
-- 	
-- 	if #data.genders == 0 then
-- 		table.insert(data.genders, "?")
-- 	end
-- 	
-- 	-- Most nouns that are listed as f+m should really have only f
-- 	if data.genders[1] == "f" and data.genders[2] == "m" then
-- 		table.insert(data.categories, "Haadwurden mei f+m geslacht yn it Frysk")
-- 	end
-- end
-- 
-- pos_functions["namme"] = {
-- 	params = {
-- 		[1] = {},
-- 		[2] = {list = "g"},
-- 		},
-- 	func = function(args, data)
-- 		noun_gender(args, data)
-- 		
-- 		-- Rubryk derby - PiefPafPier
-- 		table.insert(data.categories, "Haadwurden yn it Frysk")
-- 	end
-- }
-- pos_functions["nomen"] = pos_functions["namme"]
-- 
-- -- Display additional inflection information for a noun
-- pos_functions["subst"] = {
-- 	params = {
-- 		[1] = {},
-- 		[2] = {list = "g"},
-- 		[3] = {list = "pl"},
-- 		[4] = {list = "dim"},
-- 		
-- 		["f"] = {list = true},
-- 		["m"] = {list = true},
-- 		},
-- 	func = function(args, data)
-- 		noun_gender(args, data)
-- 		
-- 		local plurals = args[3]
-- 		local diminutives = args[4]
-- 		local feminines = args["f"]
-- 		local masculines = args["m"]
-- 		
-- 		-- Plural
-- 		if data.genders[1] == "p" then
-- 			table.insert(data.inflections, {label = "[[Wikiwurdboek:Glossarium#allinne meartal|allinne meartal]]"})
-- 		elseif plurals[1] == "-" then
-- 			table.insert(data.inflections, {label = "[[Wikiwurdboek:Glossarium#net telber|net telber]]"})
-- 			table.insert(data.categories, "Net-telbere haadwurden yn it Frysk")
-- 		else
-- 			local generated = generate_plurals(PAGENAME)
-- 			
-- 			-- Process the plural forms
-- 			for i, p in ipairs(plurals) do
-- 				-- Is this a shortcut form?
-- 				if p:sub(1,1) == "-" then
-- 					if not generated[p] then
-- 						error("It bekoarte meartal " .. p .. " koe net oanmakke wurde.")
-- 					end
-- 					
-- 					if p:sub(-2) == "es" then
-- 						table.insert(data.categories, "Haadwurden mei meartal op -es yn it Frysk")
-- 					elseif p:sub(-1) == "s" then
-- 						table.insert(data.categories, "Haadwurden mei meartal op -s yn it Frysk")
-- 					elseif p:sub(-4) == "eren" then
-- 						table.insert(data.categories, "Haadwurden mei meartal op -eren yn it Frysk")
-- 					else
-- 						table.insert(data.categories, "Haadwurden mei meartal op -en yn it Frysk")
-- 					end
-- 					
-- 					if p:sub(2,2) == ":" then
-- 						table.insert(data.categories, "Haadwurden mei rutsen fokaal yn it meartal yn it Frysk")
-- 					end
-- 					
-- 					p = generated[p]
-- 				-- Not a shortcut form, but the plural form specified directly.
-- 				else
-- 					local matches = {}
-- 					
-- 					for pi, g in pairs(generated) do
-- 						if g == p then
-- 							table.insert(matches, pi)
-- 						end
-- 					end
-- 					
-- 					if #matches > 0 then
-- 						table.insert(data.tracking_categories, "meartal fy-headword gelyk oan generearre foarm")
-- 					elseif not PAGENAME:find("[ -]") then
-- 						if p == PAGENAME then
-- 							table.insert(data.categories, "Net-bûchbere haadwurden yn it Frysk")
-- 						elseif
-- 							p == PAGENAME .. "den" or p == PAGENAME:gsub("ee$", "eden") or
-- 							p == PAGENAME .. "des" or p == PAGENAME:gsub("ee$", "edes") then
-- 							table.insert(data.categories, "Haadwurden mei meartal op -den yn it Frysk")
-- 						elseif p == PAGENAME:gsub("([ao])$", "%1%1ien") or p == PAGENAME:gsub("oe$", "oeien") then
-- 							table.insert(data.categories, "Haadwurden mei twalûd yn it meartal yn it Frysk")
-- 						elseif p == PAGENAME:gsub("y$", "ies") then
-- 							table.insert(data.categories, "Haadwurden mei Ingelske meartallen yn it Frysk")
-- 						elseif
-- 							p == PAGENAME:gsub("a$", "ae") or
-- 							p == PAGENAME:gsub("[ei]x$", "ices") or
-- 							p == PAGENAME:gsub("is$", "es") or
-- 							p == PAGENAME:gsub("men$", "mina") or
-- 							p == PAGENAME:gsub("ns$", "ntia") or
-- 							p == PAGENAME:gsub("o$", "ones") or
-- 							p == PAGENAME:gsub("o$", "onen") or
-- 							p == PAGENAME:gsub("s$", "tes") or
-- 							p == PAGENAME:gsub("us$", "era") or
-- 							p == mw.ustring.gsub(PAGENAME, "[uü]s$", "i") or
-- 							p == mw.ustring.gsub(PAGENAME, "[uü]m$", "a") or
-- 							p == PAGENAME:gsub("x$", "ges") then
-- 							table.insert(data.categories, "Haadwurden mei Latynske meartallen yn it Frysk")
-- 						elseif
-- 							p == PAGENAME:gsub("os$", "oi") or
-- 							p == PAGENAME:gsub("on$", "a") or
-- 							p == PAGENAME:gsub("a$", "ata") then
-- 							table.insert(data.categories, "Haadwurden mei Grykske meartallen yn it Frysk")
-- 						else
-- 							table.insert(data.categories, "Unregelmjittige haadwurden yn it Frysk")
-- 						end
-- 						
-- 						if plural and not mw.title.new(plural).exists then
-- 							table.insert(data.categories, "Haadwurden mei ûntbrekkende meartallen yn it Frysk")
-- 						end
-- 					end
-- 				end
-- 				
-- 				plurals[i] = p
-- 			end
-- 			
-- 			-- Add the plural forms
-- 			plurals.label = "meartal"
-- 			-- N.f.t. (sjoch https://en.wiktionary.org/w/index.php?title=Wiktionary:ACCEL) - PiefPafPier
-- 			-- plurals.accel = {form = "p"}
-- 			plurals.request = true
-- 			table.insert(data.inflections, plurals)
-- 		end
-- 		
-- 		-- Add the diminutive forms
-- 		if diminutives[1] == "-" then
-- 			-- do nothing
-- 		else
-- 			-- Process the diminutive forms
-- 			for i, p in ipairs(diminutives) do
-- 				diminutives[i] = {term = p, genders = {"n"}}
-- 			end
-- 			
-- 			diminutives.label = "[[Wikiwurdboek:Glossarium#ferlytsingswurd|ferlytsingswurd]]"
-- 			-- Ek n.f.t. - PiefPafPier
-- 			-- diminutives.accel = {form = "diminutive"}
-- 			diminutives.request = true
-- 			table.insert(data.inflections, diminutives)
-- 		end
-- 		
-- 		-- Add the feminine forms
-- 		if #feminines > 0 then
-- 			feminines.label = "froulik"
-- 			table.insert(data.inflections, feminines)
-- 		end
-- 		
-- 		-- Add the masculine forms
-- 		if #masculines > 0 then
-- 			masculines.label = "manlik"
-- 			table.insert(data.inflections, masculines)
-- 		end
-- 	end
-- }
-- 
-- -- Display additional inflection information for a diminutive noun
-- pos_functions["substdim"] = {
-- 	params = {
-- 		[1] = {},
-- 		[2] = {},
-- 		[3] = {list = "pl"},
-- 		},
-- 	func = function(args, data)
-- 		if not (args[2] == "n" or args[2] == "p") then
-- 			args[2] = {"n"}
-- 		else
-- 			args[2] = {args[2]}
-- 		end
-- 		
-- 		if #args[3] == 0 then
-- 			args[3] = {"-s"}
-- 		end
-- 		
-- 		args[4] = {"-"}
-- 		args["f"] = {}
-- 		args["m"] = {}
-- 		
-- 		-- Rubryk derby - PiefPafPier
-- 		table.insert(data.categories, "Haadwurdfoarmen yn it Frysk")
-- 		
-- 		pos_functions["subst"].func(args, data)
-- 	end
-- }
-- 
-- function generate_plurals(PAGENAME)
-- 	local m_common = require("Module:fy-common")
-- 	local generated = {}
-- 	
-- 	generated["-s"] = PAGENAME .. "s"
-- 	generated["-'s"] = PAGENAME .. "'s"
-- 	
-- 	local stem_FF = m_common.add_e(PAGENAME, false, false)
-- 	local stem_TF = m_common.add_e(PAGENAME, true, false)
-- 	local stem_FT = m_common.add_e(PAGENAME, false, true)
-- 	
-- 	generated["-es"] = stem_FF .. "s"
-- 	generated["-@es"] = stem_TF .. "s"
-- 	generated["-:es"] = stem_FT .. "s"
-- 	
-- 	generated["-en"] = stem_FF .. "n"
-- 	generated["-@en"] = stem_TF .. "n"
-- 	generated["-:en"] = stem_FT .. "n"
-- 	
-- 	generated["-eren"] = m_common.add_e(PAGENAME .. (PAGENAME:find("n$") and "d" or ""), false, false) .. "ren"
-- 	generated["-:eren"] = stem_FT .. "ren"
-- 	
-- 	if PAGENAME:find("f$") then
-- 		local stem = PAGENAME:gsub("f$", "v")
-- 		local stem_FF = m_common.add_e(stem, false, false)
-- 		local stem_TF = m_common.add_e(stem, true, false)
-- 		local stem_FT = m_common.add_e(stem, false, true)
-- 		
-- 		generated["-ves"] = stem_FF .. "s"
-- 		generated["-@ves"] = stem_TF .. "s"
-- 		generated["-:ves"] = stem_FT .. "s"
-- 		
-- 		generated["-ven"] = stem_FF .. "n"
-- 		generated["-@ven"] = stem_TF .. "n"
-- 		generated["-:ven"] = stem_FT .. "n"
-- 		
-- 		generated["-veren"] = stem_FF .. "ren"
-- 		generated["-:veren"] = stem_FT .. "ren"
-- 	elseif PAGENAME:find("s$") then
-- 		local stem = PAGENAME:gsub("s$", "z")
-- 		local stem_FF = m_common.add_e(stem, false, false)
-- 		local stem_TF = m_common.add_e(stem, true, false)
-- 		local stem_FT = m_common.add_e(stem, false, true)
-- 		
-- 		generated["-zes"] = stem_FF .. "s"
-- 		generated["-@zes"] = stem_TF .. "s"
-- 		generated["-:zes"] = stem_FT .. "s"
-- 		
-- 		generated["-zen"] = stem_FF .. "n"
-- 		generated["-@zen"] = stem_TF .. "n"
-- 		generated["-:zen"] = stem_FT .. "n"
-- 		
-- 		generated["-zeren"] = stem_FF .. "ren"
-- 		generated["-:zeren"] = stem_FT .. "ren"
-- 	elseif PAGENAME:find("heid$") then
-- 		generated["-heden"] = PAGENAME:gsub("heid$", "heden")
-- 	end
-- 	
-- 	return generated
-- end
-- 
-- pos_functions["mulwd"] = {
-- 	params = {
-- 		[1] = {},
-- 		[2] = {},
-- 	},
-- 	func = function(args, data)
-- 		-- Rubryk derby - PiefPafPier
-- 		table.insert(data.categories, "Tiidwurdfoarmen yn it Frysk")
-- 		
-- 		if args[2] == "-" then
-- 			table.insert(data.inflections, {label = "net eigenskiplik brûkt"})
-- 			table.insert(data.categories, "Net-eigenskiplik brûkte mulwurden yn it Frysk")
-- 		end
-- 	end
-- }
-- pos_functions["partp"] = pos_functions["mulwd"]
-- 
-- pos_functions["verbum"] = {
-- 	params = {
-- 		[1] = {},
-- 		[2] = {},
-- 		},
-- 	func = function(args, data)
-- 		if args[2] == "-" then
-- 			table.insert(data.inflections, {label = "gjin bûging"})
-- 			table.insert(data.categories, "Tiidwurden sûnder bûging yn it Frysk")
-- 		end
-- 	end
-- }

return export