Module:siwa-headword: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 14: | Line 14: | ||
local NAMESPACE = mw.title.getCurrentTitle().nsText | local NAMESPACE = mw.title.getCurrentTitle().nsText | ||
local SUBPAGENAME = mw.title.getCurrentTitle().subpageText | local SUBPAGENAME = mw.title.getCurrentTitle().subpageText | ||
local gender_key = { | local gender_key = { | ||
["i"] = "in", | ["i"] = "in", | ||
["a"] = "an", | ["a"] = "an", | ||
} | |||
local verb_key = { | |||
["adit"] = "agentive ditransitive", | |||
["ai"] = "agentive intransitive", | |||
["asubj"] = "agentive subjective", | |||
["at"] = "agentive transitive", | |||
["imp"] = "impersonal", | |||
["udit"] = "unagentive ditransitive", | |||
["ui"] = "unagentive intransitive", | |||
["usubj"] = "unagentive subjective", | |||
["ut"] = "unagentive transitive", | |||
["utrans"] = "translative", | |||
} | } | ||
Line 88: | Line 96: | ||
["unc"] = {type = "boolean"}, | ["unc"] = {type = "boolean"}, | ||
["indecl"] = {type = "boolean"}, | ["indecl"] = {type = "boolean"}, | ||
["head"] = {}, | ["head"] = {default = PAGENAME}, | ||
} | } | ||
Line 123: | Line 131: | ||
pos_functions.verbs = function(class, args, data) | pos_functions.verbs = function(class, args, data) | ||
local params = { | local params = { | ||
[1] = { | [1] = {required = true}, | ||
[2] = {list = " | [2] = {list = "inf", required = true}, | ||
[3] = {list = " | [3] = {list = "p", required = true}, | ||
["head"] = {}, | ["head"] = {}, | ||
} | } | ||
Line 132: | Line 140: | ||
data.heads = {args["head"]} | data.heads = {args["head"]} | ||
table.insert(data.categories, " | if match(args.head, "/") then | ||
local kinds = mw.text.split(args[1], "/") | |||
else | |||
local kinds = {args[1]} | |||
end | |||
for n, kind in ipairs(kinds) do | |||
table.insert(data.inflections[n].label, verb_key[kind]) | |||
table.insert(data.categories, "Siwa " .. verb_key[kind] .. " verbs") | |||
end | |||
args[2].label = "infinitive" | |||
args[3].label = "past" | |||
args[2].label = " | |||
args[3].label = " | |||
table.insert(data.inflections, args[2]) | table.insert(data.inflections, args[2]) | ||
table.insert(data.inflections, args[3]) | table.insert(data.inflections, args[3]) |
Revision as of 15:18, 5 August 2021
- The following documentation is located at Module:siwa-headword/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
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 = {
["adit"] = "agentive ditransitive",
["ai"] = "agentive intransitive",
["asubj"] = "agentive subjective",
["at"] = "agentive transitive",
["imp"] = "impersonal",
["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"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = {args["head"]}
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
end
pos_functions["proper nouns"] = pos_functions.nouns
pos_functions.adjectives = function(class, args, data)
local params = {
[1] = {list = "eq"},
[2] = {list = "comp"},
[3] = {list = "sup"},
["unc"] = {type = "boolean"},
["indecl"] = {type = "boolean"},
["head"] = {default = PAGENAME},
}
local args = require("Module:parameters").process(args, params)
local isdet = data.pos_category == "determiners"
data.heads = {args["head"]}
table.insert(data.categories, "High Valyrian " .. data.pos_category)
if args["unc"] or isdet then
table.insert(data.inflections, {label = "not " .. glossary_link("comparable")})
if not isdet then table.insert(data.categories, "High Valyrian uncomparable adjectives") end
elseif args["indecl"] then
table.insert(data.inflections, {label = glossary_link("indeclinable")})
table.insert(data.categories, "High Valyrian indeclinable " .. data.pos_category)
else
args[1] = require("Module:qhv-adj/head").fetch("eq")
args[2] = require("Module:qhv-adj/head").fetch("comp")
args[3] = require("Module:qhv-adj/head").fetch("sup")
args[1].label = glossary_link("equative")
args[2].label = glossary_link("comparative")
args[3].label = glossary_link("superlative")
table.insert(data.inflections, args[1])
table.insert(data.inflections, args[2])
table.insert(data.inflections, args[3])
end
end
pos_functions["proper nouns"] = pos_functions.nouns
pos_functions["determiners"] = pos_functions.adjectives
pos_functions.verbs = function(class, args, data)
local params = {
[1] = {required = true},
[2] = {list = "inf", required = true},
[3] = {list = "p", required = true},
["head"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = {args["head"]}
if match(args.head, "/") then
local kinds = mw.text.split(args[1], "/")
else
local kinds = {args[1]}
end
for n, kind in ipairs(kinds) do
table.insert(data.inflections[n].label, verb_key[kind])
table.insert(data.categories, "Siwa " .. verb_key[kind] .. " verbs")
end
args[2].label = "infinitive"
args[3].label = "past"
table.insert(data.inflections, args[2])
table.insert(data.inflections, args[3])
end
return export