Module:siwa-headword: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
 
(90 intermediate revisions by the same user not shown)
Line 1: Line 1:
local export = {}
local export = {}
local pos_functions = {}


function format_pos(poscat)
local sub = mw.ustring.sub
if poscat == "noun" then
local find = mw.ustring.find
return "'''" .. args[1] .. "'''"
local match = mw.ustring.match
end
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit
 
local PAGENAME = mw.title.getCurrentTitle().text
local NAMESPACE = mw.title.getCurrentTitle().nsText
local SUBPAGENAME = mw.title.getCurrentTitle().subpageText
 
local gender_key = {
["i"] = "in",
["a"] = "an",
}
 
local verb_key = {
["aditr"] = "agentive ditransitive",
["adit"] = "agentive ditransitive",
["ai"] = "agentive intransitive",
["asubj"] = "agentive subjective",
["at"] = "agentive transitive",
["imp"] = "impersonal",
["pass"] = "passive",
["udit"] = "unagentive ditransitive",
["ui"] = "unagentive intransitive",
["usubj"] = "unagentive subjective",
["ut"] = "unagentive transitive",
["utrans"] = "translative",
["?"] = "?",
}
 
local lang = require("Module:languages").getByCode("siwa")
 
local function glossary_link(entry, text)
return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. (text or entry) .. "]]"
end
end


Line 10: Line 45:
-- This is the only function that can be invoked from a template.
-- This is the only function that can be invoked from a template.
function export.show(frame)
function export.show(frame)
local PAGENAME = mw.title.getCurrentTitle().text
if NAMESPACE == "Template" and SUBPAGENAME ~= "doc" then return end
local params = {
local parent_args = frame:getParent().args
[2] = { default = PAGENAME },
[1] = {},
}
local args = require("Module:parameters").process(getParent().args, params)
local head = args[2]
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
if head == "" then
local class = frame.args[2]; if class == "" then class = nil end
head = nil
end
local poscat = args[1]
local data = {
local data = {lang = lang, pos_category = (postype and postype .. " " or "") .. poscat, categories = {}, heads = {head}, genders = {}, inflections = {}}
lang = lang,
heads = {},
inflections = {},
genders = {},
pos_category = poscat,
categories = {"Siwa " .. poscat}
}
if poscat == "adjectives" then
if pos_functions[poscat] then
if PAGENAME:find("^-") then
pos_functions[poscat](class, parent_args, data)
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic adjective-forming suffixes"}
end
adjective(args, data)
elseif poscat == "adverbs" then
if SUBPAGENAME:find("^-") then
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic adverb-forming suffixes"}
end
adverb(args, data)
elseif poscat == "determiners" then
adjective(args, data)
elseif poscat == "nouns" then
if PAGENAME:find("^-") then
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic noun-forming suffixes"}
end
noun_gender(args, data)
elseif poscat == "proper nouns" then
noun_gender(args, data)
elseif poscat == "verbs" then
if PAGENAME:find("^-") then
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic verb-forming suffixes"}
end
end
end
return format_pos(poscat)
return require("Module:headword").full_headword(data)
end
end


-- Display information for a noun's gender
pos_functions.nouns = function(class, args, data)
-- This is separate so that it can also be used for proper nouns
local params = {
function noun_gender(args, data)
[1] = {required = true},
local valid_genders = {
[2] = {},
["m"] = true,
["m"] = {list = true},
["f"] = true,
["head"] = {default = PAGENAME},
["n"] = true,
["decl"] = {},
["m-p"] = true,
["cat2"] = {},
["f-p"] = true,
["cat3"] = {},
["n-p"] = true}
["sort"] = {},
["affix"] = {list = true},
}
local args = require("Module:parameters").process(args, params)
data.heads = {args["head"]}
data.affix = args["affix"]
table.insert(data.genders, gender_key[args[1]] or args[1])
if args[2] then table.insert(data.genders, gender_key[args[2]] or args[2]) end
data.inflections[1] = args.m
data.inflections[1].label = "marked"
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
if args.decl then table.insert(data.categories, "Siwa " .. args.decl .. "-declension " .. data.pos_category) end
local g = args[1] or ""; if g == "" then g = "?" end
if args.cat2 then table.insert(data.categories, "Siwa " .. args["cat2"]) end
local i = 2
if args.cat3 then table.insert(data.categories, "Siwa " .. args["cat3"]) end
while g ~= "" do
data.sort_key = args["sort"] or nil
if not valid_genders[g] then
g = "?"
end
-- If any of the specifications is a "?", add the entry
-- to a cleanup category.
if g == "?" then
table.insert(data.categories, "Requests for gender in Proto-Germanic entries")
elseif g == "m-p" or g == "f-p" or g == "n-p" then
table.insert(data.categories, "Proto-Germanic pluralia tantum")
end
table.insert(data.genders, g)
g = args["g" .. i] or ""
i = i + 1
end
end
end


function adjective(args, data)
pos_functions["proper nouns"] = pos_functions.nouns
local adverb = args["adv"]; if adverb == "" then adverb = nil end
 
local comparative = args[1]; if comparative == "" then comparative = nil end
pos_functions["proper nouns"] = pos_functions.nouns
local superlative = args[2]; if superlative == "" then superlative = nil end
 
pos_functions.verbs = function(class, args, data)
local params = {
[1] = {required = true},
[2] = {list = "inf", required = true},
[3] = {list = "p", required = true},
[4] = {type = "boolean"},
["head"] = {},
["cat2"] = {},
["sort"] = {},
["affix"] = {list = true},
}
if adverb then
local args = require("Module:parameters").process(args, params)
table.insert(data.inflections, {label = "adverb", adverb})
data.heads = {args["head"]}
for n, kind in ipairs(mw.text.split(args[1], "/")) do
if kind ~= "?" then
data.inflections[n] = {nil}
data.inflections[n].label = verb_key[kind]
table.insert(data.categories, "Siwa " .. verb_key[kind] .. " verbs")
end
end
end
if comparative then
args[2].label = "infinitive"
table.insert(data.inflections, {label = "comparative", comparative})
table.insert(data.inflections, args[2])
end
if superlative then
args[3].label = "past"
table.insert(data.inflections, {label = "superlative", superlative})
table.insert(data.inflections, args[3])
end
end
 
function adverb(args, data)
local adjective = args["adj"]; if adjective == "" then adjective = nil end
local comparative = args[1]; if comparative == "" then comparative = nil end
local superlative = args[2]; if superlative == "" then superlative = nil end
if adjective then
if args[4] then table.insert(data.categories, "Siwa irregular verbs") end
table.insert(data.inflections, {label = "adjective", adjective})
if args.cat2 then table.insert(data.categories, "Siwa " .. args["cat2"]) end
end
if comparative then
if args[1] == "?" or args[2] == "?" or args[3] == "?" then table.insert(data.categories, "Contionary stubs") end
table.insert(data.inflections, {label = "comparative", comparative})
end
if superlative then
data.sort_key = args["sort"] or nil
table.insert(data.inflections, {label = "superlative", superlative})
data.affix = args["affix"]
end
end
end


return export
return export

Latest revision as of 22:49, 4 July 2023



local export = {}
local pos_functions = {}

local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit

local PAGENAME = mw.title.getCurrentTitle().text
local NAMESPACE = mw.title.getCurrentTitle().nsText
local SUBPAGENAME = mw.title.getCurrentTitle().subpageText

local gender_key = {
	["i"] = "in",
	["a"] = "an",
}

local verb_key = {
	["aditr"] = "agentive ditransitive",
	["adit"] = "agentive ditransitive",
	["ai"] = "agentive intransitive",
	["asubj"] = "agentive subjective",
	["at"] = "agentive transitive",
	["imp"] = "impersonal",
	["pass"] = "passive",
	["udit"] = "unagentive ditransitive",
	["ui"] = "unagentive intransitive",
	["usubj"] = "unagentive subjective",
	["ut"] = "unagentive transitive",
	["utrans"] = "translative",
	["?"] = "?",
}

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

local function glossary_link(entry, text)
	return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. (text or entry) .. "]]"
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	if NAMESPACE == "Template" and SUBPAGENAME ~= "doc" then return end
	local parent_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 class = frame.args[2]; if class == "" then class = nil end
	
	local data = {
		lang = lang,
		heads = {},
		inflections = {},
		genders = {},
		pos_category = poscat,
		categories = {"Siwa " .. poscat}
	}
	
	if pos_functions[poscat] then
		pos_functions[poscat](class, parent_args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

pos_functions.nouns = function(class, args, data)
	local params = {
		[1] = {required = true},
		[2] = {},
		["m"] = {list = true},
		["head"] = {default = PAGENAME},
		["decl"] = {},
		["cat2"] = {},
		["cat3"] = {},
		["sort"] = {},
		["affix"] = {list = true},
	}
	
	local args = require("Module:parameters").process(args, params)
	data.heads = {args["head"]}
	data.affix = args["affix"]
	
	table.insert(data.genders, gender_key[args[1]] or args[1])
	if args[2] then table.insert(data.genders, gender_key[args[2]] or args[2]) end
	
	data.inflections[1] = args.m
	data.inflections[1].label = "marked"
	
	if args.decl then table.insert(data.categories, "Siwa " .. args.decl .. "-declension " .. data.pos_category) end
	if args.cat2 then table.insert(data.categories, "Siwa " .. args["cat2"]) end
	if args.cat3 then table.insert(data.categories, "Siwa " .. args["cat3"]) end
	
	data.sort_key = args["sort"] or nil
end

pos_functions["proper nouns"] = pos_functions.nouns

pos_functions["proper nouns"] = pos_functions.nouns

pos_functions.verbs = function(class, args, data)
	local params = {
		[1] = {required = true},
		[2] = {list = "inf", required = true},
		[3] = {list = "p", required = true},
		[4] = {type = "boolean"},
		["head"] = {},
		["cat2"] = {},
		["sort"] = {},
		["affix"] = {list = true},
	}
	
	local args = require("Module:parameters").process(args, params)
	data.heads = {args["head"]}
	
	for n, kind in ipairs(mw.text.split(args[1], "/")) do
		if kind ~= "?" then
			data.inflections[n] = {nil}
			data.inflections[n].label = verb_key[kind]
			table.insert(data.categories, "Siwa " .. verb_key[kind] .. " verbs")
		end
	end
	
	args[2].label = "infinitive"
	table.insert(data.inflections, args[2])
	
	args[3].label = "past"
	table.insert(data.inflections, args[3])
	
	if args[4] then table.insert(data.categories, "Siwa irregular verbs") end
	if args.cat2 then table.insert(data.categories, "Siwa " .. args["cat2"]) end
	
	if args[1] == "?" or args[2] == "?" or args[3] == "?" then table.insert(data.categories, "Contionary stubs") end
	
	data.sort_key = args["sort"] or nil
	data.affix = args["affix"]
end

return export