Jump to content

Module:ofs-conj

From Wiktionary, the free dictionary

Called by {{ofs-conj}}. Do not use directly.


local export = {}

local m_links = require("Module:links")
local m_utils = require("Module:utilities")

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

local conj_data = {}

conj_data["st"] = {
	params = {
		[1] = {},
		[2] = {},
		[3] = {},
		[4] = {},
		["head"] = {},
		["mutstem"] = {},
		["class"] = {},
		},
}
setmetatable(conj_data["st"], {__call = function(self, args, data)
	if not args.class then
		error("Class parameter required for strong verbs")
	end
	data.conj_type = "strong class " .. args.class
	
	if args[1]:sub(1,1) == "*" then
		error("Redundant asterisks")
	end
	
	data.forms["inf"] = {args.head or (args[1] .. "a")}
	
	data.forms["pres_ind_1s"] = {args[1] .. "e"}
	data.forms["pres_ind_2s"] = {(args.mutstem or args[1]) .. "est", (args.mutstem or args[1]) .. "st"}
	data.forms["pres_ind_3s"] = {(args.mutstem or args[1]) .. "eth", (args.mutstem or args[1]) .. "th"}
	data.forms["pres_ind_p"] = {args[1] .. "ath"}

	data.forms["past_ind_1s"] = {args[2]}
	data.forms["past_ind_2s"] = {args[2] .. "est", args[2] .. "st"}
	data.forms["past_ind_3s"] = {args[2]}
	data.forms["past_ind_p"] = {args[3] .. "en"}

	data.forms["pres_sub_s"] = {args[1] .. "e"}
	data.forms["pres_sub_p"] = {args[1] .. "e", args[1] .. "en"}
	
	data.forms["past_sub_s"] = {args[3] .. "e"}
	data.forms["past_sub_p"] = {args[3] .. "e", args[3] .. "en"}
	
	data.forms["imp_s"] = {args[1]}
	data.forms["imp_p"] = {args[1] .. "eth"}
	
	data.forms["pres_part"] = {args[1] .. "ande"}
	data.forms["past_part"] = {"e" .. args[4] .. "en", args[4] .. "en"}
	
	table.insert(data.categories, "Old Frisian class " .. args.class .. " strong verbs")
end
})

conj_data["wk1"] = {
	params = {
		[1] = {},
		[2] = {},
		[3] = {},
		["head"] = {},
		},
}
setmetatable(conj_data["wk1"], {__call = function(self, args, data)
	data.conj_type = "weak class 1"
	
	if args[1]:sub(1,1) == "*" then
		error("Redundant asterisks")
	end
	
	data.forms["inf"] = {args.head or (args[1] .. "a")}
	
	data.forms["pres_ind_1s"] = {args[1] .. "e"}
	data.forms["pres_ind_2s"] = {args[1] .. "est", args[1] .. "st"}
	data.forms["pres_ind_3s"] = {args[1] .. "eth", args[1] .. "th"}
	data.forms["pres_ind_p"] = {args[1] .. "ath"}

	data.forms["past_ind_1s"] = {(args[2] or (args[1] .. "d")) .. "e"}
	data.forms["past_ind_2s"] = {(args[2] or (args[1] .. "d")) .. "est"}
	data.forms["past_ind_3s"] = {(args[2] or (args[1] .. "d")) .. "e"}
	data.forms["past_ind_p"] = {(args[2] or (args[1] .. "d")) .. "en"}

	data.forms["pres_sub_s"] = {args[1] .. "e"}
	data.forms["pres_sub_p"] = {args[1] .. "e", args[1] .. "en"}
	
	data.forms["past_sub_s"] = {(args[2] or (args[1] .. "d")) .. "e"}
	data.forms["past_sub_p"] = {(args[2] or (args[1] .. "d")) .. "e", (args[2] or (args[1] .. "d")) .. "en"}
	
	data.forms["imp_s"] = {args[1] .. "e"}
	data.forms["imp_p"] = {args[1] .. "ath"}
	
	data.forms["pres_part"] = {args[1] .. "ande"}
	data.forms["past_part"] = {"e" .. (args[3] or (args[1] .. "ed")), args[3] or (args[1] .. "ed")}
	
	table.insert(data.categories, "Old Frisian class 1 weak verbs")
end
})

conj_data["wk2"] = {
	params = {
		[1] = {},
		["head"] = {},
		},
}
setmetatable(conj_data["wk2"], {__call = function(self, args, data)
	data.conj_type = "weak class 2"
	
	if args[1]:sub(1,1) == "*" then
		error("Redundant asterisks")
	end
	
	data.forms["inf"] = {args.head or (args[1] .. "ia")}
	
	data.forms["pres_ind_1s"] = {args[1] .. "ie"}
	data.forms["pres_ind_2s"] = {args[1] .. "ast"}
	data.forms["pres_ind_3s"] = {args[1] .. "ath"}
	data.forms["pres_ind_p"] = {args[1] .. "iath"}

	data.forms["past_ind_1s"] = {args[1] .. "ade"}
	data.forms["past_ind_2s"] = {args[1] .. "adest"}
	data.forms["past_ind_3s"] = {args[1] .. "ade"}
	data.forms["past_ind_p"] = {args[1] .. "aden"}

	data.forms["pres_sub_s"] = {args[1] .. "ie"}
	data.forms["pres_sub_p"] = {args[1] .. "ie", args[1] .. "ien"}
	
	data.forms["past_sub_s"] = {args[1] .. "ade"}
	data.forms["past_sub_p"] = {args[1] .. "ade", args[1] .. "aden"}
	
	data.forms["imp_s"] = {args[1] .. "a"}
	data.forms["imp_p"] = {args[1] .. "iath"}
	
	data.forms["pres_part"] = {args[1] .. "ande"}
	data.forms["past_part"] = {"e" .. args[1] .. "ad", args[1] .. "ad"}
	
	table.insert(data.categories, "Old Frisian class 2 weak verbs")
end
})

conj_data.irregular = {}

conj_data.irregular["dwā"] = function(data)
	data.conj_type = "irregular"
	
	data.forms["inf"] = {"dwā"}
	
	data.forms["pres_ind_1s"] = {"dwē"}
	data.forms["pres_ind_2s"] = {"dēst"}
	data.forms["pres_ind_3s"] = {"dēt(h)"}
	data.forms["pres_ind_p"] = {"dwāt(h)", "dwā"}

	data.forms["past_ind_1s"] = {"dēde"}
	data.forms["past_ind_2s"] = {"dēde"}
	data.forms["past_ind_3s"] = {"dēde"}
	data.forms["past_ind_p"] = {"dēden"}
	
	data.forms["pres_sub_s"] = {"dwē"}
	data.forms["pres_sub_p"] = {"dwā"}

	data.forms["past_sub_s"] = {"dēde"}
	data.forms["past_sub_p"] = {"dēden"}
	
	data.forms["imp_s"] = {"-"}
	data.forms["imp_p"] = {"dwāt(h)"}
	
	data.forms["pres_part"] = {"-"}
	data.forms["past_part"] = {"(e)dēn", "dīen"}
	
end

conj_data.irregular["gān"] = function(data)
	data.conj_type = "irregular, [[suppletive]]"
	
	data.forms["inf"] = {"gān"}
	
	data.forms["pres_ind_1s"] = {"gā"}
	data.forms["pres_ind_2s"] = {"gēst"}
	data.forms["pres_ind_3s"] = {"gēth"}
	data.forms["pres_ind_p"] = {"gāth"}

	data.forms["past_ind_1s"] = {"geng"}
	data.forms["past_ind_2s"] = {"gengest"}
	data.forms["past_ind_3s"] = {"geng"}
	data.forms["past_ind_p"] = {"gengun"}
	
	data.forms["pres_sub_s"] = {"gāe"}
	data.forms["pres_sub_p"] = {"gāe", "gāen"}

	data.forms["past_sub_s"] = {"genge"}
	data.forms["past_sub_p"] = {"genge", "gengen"}
	
	data.forms["imp_s"] = {"gā"}
	data.forms["imp_p"] = {"gāth"}
	
	data.forms["pres_part"] = {"gānde", "gangande"}
	data.forms["past_part"] = {"egangen", "gangen"}
	
	table.insert(data.categories, "Old Frisian suppletive verbs")
end

conj_data.irregular["wesa"] = function(data)
	data.conj_type = "irregular, [[suppletive]]"
	
	data.forms["inf"] = {"wesa"}
	
	data.forms["pres_ind_1s"] = {"bem", "ben"}
	data.forms["pres_ind_2s"] = {"bist"}
	data.forms["pres_ind_3s"] = {"is"}
	data.forms["pres_ind_p"] = {"send"}

	data.forms["past_ind_1s"] = {"was"}
	data.forms["past_ind_2s"] = {"wēre"}
	data.forms["past_ind_3s"] = {"was"}
	data.forms["past_ind_p"] = {"wēron"}
	
	data.forms["pres_sub_s"] = {"sē"}
	data.forms["pres_sub_p"] = {"sē", "sēn"}

	data.forms["past_sub_s"] = {"wēre"}
	data.forms["past_sub_p"] = {"wēre", "wēren"}
	
	data.forms["imp_s"] = {"wese"}
	data.forms["imp_p"] = {"wesath", "wesset"}
	
	data.forms["pres_part"] = {"wesande"}
	data.forms["past_part"] = {"ewesen", "wesen"}
	
	table.insert(data.categories, "Old Frisian suppletive verbs")
end

local function add_asterisks(forms, data)
	for _, form in ipairs(forms) do
		for i, subform in ipairs(data.forms[form]) do
			data.forms[form][i] = "*" .. subform
		end
	end
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)

	local parent_args = frame:getParent().args
	local conj_type = (frame.args["conj"] or parent_args["conj"]) or "st"

	if not conj_data[conj_type] then
		error("Unknown conjugation '" .. conj_type .. "'")
	end
	
	local data = {forms = {}, categories = {}}
	
	data.head = parent_args["head"] or nil

	local args = require("Module:parameters").process(parent_args, conj_data[conj_type].params, true)
	
	-- Override for templates
	if not args[1] then
		setmetatable(args, {__index = function(self, key)
			return "{{{" .. key .. "}}}"
		end
		})
	end
	
	-- Generate the forms
	if parent_args.irr then
		table.insert(data.categories, "Old Frisian irregular verbs")
		if conj_data.irregular[parent_args.irr] then
			conj_data.irregular[parent_args.irr](data)
		else
			conj_data[conj_type](args, data)
		end
	else
		conj_data[conj_type](args, data)
	end

	-- Make the table
	return make_table(data)
end

function make_table(data)
	local function show_form(form)
		if not form then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			if mw.title.getCurrentTitle().nsText == "Reconstruction" and subform ~= "—" then
				subform = "*" .. subform
			end
			table.insert(ret, m_links.full_link({lang = lang, term = subform}))
		end
			
		return table.concat(ret, ", ")
	end
	
	local function repl(param)
		if param == "conj_type" then
			return data.conj_type
		else
			return show_form(data.forms[param])
		end
	end
	
	local wikicode = [=[
<div class="NavFrame" style="width: 42em">
<div class="NavHead" style="background-color:#8FBC8F;">Conjugation of ''{{{inf}}}'' ({{{conj_type}}})</div>
<div class="NavContent">
{| style="width: 100%; border:1px solid #8FBC8F; line-height: 125%; background-color:#F9F9F9; text-align:center; border: 1px solid #CCCCFF;" cellspacing="1" cellpadding="3" cellspacing="1" class="inflection-table"
|- style="background-color:#F2FFF2;"
|-
! style="background-color:#ACE1AF;" | infinitive
| colspan="2" style="background-color:#EFEFEF;" | {{{inf}}}
|-
! style="background-color:#8FBC8F;" | [[indicative mood|indicative]]
! style="background-color:#DEDEEE;" | [[present tense|present]]
! style="background-color:#DEDEEE;" | [[past tense|past]]
|-
! style="background-color:#ACE1AF;" | 1st&nbsp;person&nbsp;singular
| style="background-color:#efefff;" | {{{pres_ind_1s}}}
| style="background-color:#efefff;" | {{{past_ind_1s}}}
|-
! style="background-color:#ACE1AF;" | 2nd&nbsp;person&nbsp;singular
| style="background-color:#efefff;" | {{{pres_ind_2s}}}
| style="background-color:#efefff;" | {{{past_ind_2s}}}
|-
! style="background-color:#ACE1AF;" | 3rd&nbsp;person&nbsp;singular
| style="background-color:#efefff;" | {{{pres_ind_3s}}}
| style="background-color:#efefff;" | {{{past_ind_3s}}}
|-
! style="background-color:#ACE1AF;" | plural
| style="background-color:#efefff;" | {{{pres_ind_p}}}
| style="background-color:#efefff;" | {{{past_ind_p}}}
|-
! style="background-color:#8FBC8F;" | [[subjunctive mood|subjunctive]]
! style="background-color:#eeeede;" | present
! style="background-color:#eeeede;" | past
|-
! style="background-color:#ACE1AF;" | singular
| style="background-color:#ffffef;" | {{{pres_sub_s}}}
| style="background-color:#ffffef;" | {{{past_sub_s}}}
|-
! style="background-color:#ACE1AF;" | plural
| style="background-color:#ffffef;" | {{{pres_sub_p}}}
| style="background-color:#ffffef;" | {{{past_sub_p}}}
|-
! style="background-color:#8FBC8F;" | [[imperative mood|imperative]]
! style="background-color:#eedede;" | present
! rowspan="3" style="background-color:#e0e0e0;" |
|-
! style="background-color:#ACE1AF;" | singular
| style="background-color:#ffefef;" | {{{imp_s}}}
|-
! style="background-color:#ACE1AF;" | plural
| style="background-color:#ffefef;" | {{{imp_p}}}
|-
! style="background-color:#8FBC8F; font-weight:bold;" | [[participle]]
! style="background-color:#deeede; font-weight:bold;" | [[present tense|present]]
! style="background-color:#deeede; font-weight:bold;" | [[past tense|past]]
|-
! style="background-color:#ACE1AF; font-weight:bold;" |
| style="background-color:#efffef;" | {{{pres_part}}} 
| style="background-color:#efffef;" | {{{past_part}}}
|}</div></div>]=]

	return (mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. m_utils.format_categories(data.categories, lang)
end

return export