Modul:category tree/affix cat
A modult a Modul:category tree/affix cat/doc lapon tudod dokumentálni
local m_links = require("Module:links")
local m_compound = require("Module:compound")
local export = {}
-- Category object
local Category = {}
Category.__index = Category
function Category.new_main(frame)
local params = {
[1] = {required = true},
[2] = {required = true},
[3] = {},
["id"] = {},
["pos"] = {},
["sc"] = {},
["sort"] = {},
["tr"] = {},
}
args = require("Module:parameters").process(frame:getParent().args, params)
local info = {code = args[1], term = args[2], alt = args[3], id = args["id"], pos = args["pos"], sc = args["sc"], sort = args["sort"], tr = args["tr"], affixtype = frame.args["affixtype"]}
return Category.new(info)
end
function Category.new(info)
local self = setmetatable({}, Category)
for key, val in pairs(info) do
if not (key == "affixtype" or key == "alt" or key == "code" or key == "id" or key == "pos" or key == "sc" or key == "sort" or key == "term" or key == "tr") then
error("The parameter \"" .. key .. "\" was not recognized.")
end
end
self._info = info
-- Add default POS, or make POS plural.
self._pos = self._info.pos or "words"
if not self._pos:find("s$") then
if self._pos:find("x$") then
self._pos = self._pos .. "es"
else
self._pos = self._pos .. "s"
end
end
if not self._info.code then
error("No language code was specified.")
end
if not self._info.term then
error("No term was specified.")
end
self._lang = require("Module:languages").getByCode(self._info.code) or error("The language code \"" .. self._info.code .. "\" is not valid.")
self._sc = (self._info.sc and (require("Module:scripts").getByCode(val) or error("The script code \"" .. val .. "\" is not valid.")) or nil)
self._term = m_compound.make_affix(self._info.term, self._lang, self._sc, self._info.affixtype)
self._alt = m_compound.make_affix(self._info.alt, self._lang, self._sc, self._info.affixtype)
self._tr = m_compound.make_affix(self._info.tr, self._lang, require("Module:scripts").getByCode("Latn"), self._info.affixtype)
-- Convert term/alt into affixes if needed
local desc = {
["prefix"] = "beginning with the prefix",
["suffix"] = "ending with the suffix",
["circumfix"] = "bookended with the circumfix",
["infix"] = "spliced with the infix",
["interfix"] = "joined with the interfix",
["transfix"] = "patterned with the transfix",
}
if self._info.affixtype then
self._desc = desc[self._info.affixtype] or error(self._info.affixtype .. " is not a recognized type of affix.")
else
error("Please provide a type of affix in the affixtype parameter.")
end
return self
end
export.new = Category.new
export.new_main = Category.new_main
function Category:getInfo()
return self._info
end
function Category:getBreadcrumbName()
if self._pos and self._pos == "words" then
local affix = require("Module:script utilities").tag_text(
self._alt or self._term,
self._lang,
self._sc,
"term"
)
if self._info.id then
return affix .. " (" .. self._info.id .. ")"
else
return affix
end
else
return self._pos
end
end
function Category:getDataModule()
return "Module:category tree/affix cat"
end
function Category:canBeEmpty()
return false
end
function Category:isHidden()
return false
end
function Category:getCategoryName()
return self._lang:getCanonicalName() .. " " .. self._pos .. " " .. self._info.affixtype .. "ed with " .. self._lang:makeEntryName(self._term) .. (self._info.id and " (" .. self._info.id .. ")" or "")
end
function Category:getDescription()
local description =
self._lang:getCanonicalName() .. " " .. self._pos .. " " .. self._desc .. " " ..
m_links.full_link({lang = self._lang, term = self._term, alt = self._alt, sc = self._sc, id = self._info.id, tr = self._tr}, "term") ..
"."
mw.getCurrentFrame():callParserFunction(
"DISPLAYTITLE",
"Category:" .. self._lang:getCanonicalName() .. " " .. self._pos .. " " .. self._info.affixtype .. 'ed with ' .. require("Module:script utilities").tag_text(self._lang:makeEntryName(self._term), self._lang, self._script, "term") .. (self._info.id and " (" .. self._info.id .. ")" or "")
)
return description
end
function Category:getParents()
local parents = {}
local parent
if self._info.id then
if self._pos and self._pos == "words" then
parent = {}
parent.name = export.new({
code = self._info.code,
term = self._info.term,
affixtype = self._info.affixtype
})
parent.sort = self._info.id
table.insert(parents, parent)
else
parent = {}
parent.name = export.new({
code = self._info.code,
term = self._info.term,
affixtype = self._info.affixtype,
id = self._info.id
})
parent.sort = self._info.id .. ", " .. self._info.pos
table.insert(parents, parent)
parent = {}
parent.name = export.new({
code = self._info.code,
term = self._info.term,
affixtype = self._info.affixtype,
pos = self._info.pos
})
parent.sort = self._info.id
table.insert(parents, parent)
end
else
if self._pos and self._pos ~= "words" then
parent = {}
parent.name = export.new({
code = self._info.code,
term = self._info.term,
affixtype = self._info.affixtype
})
parent.sort = self._info.pos
table.insert(parents, parent)
end
end
parent = {}
parent.name = require("Module:category tree/poscatboiler").new({code = self._info.code, label = "words by " .. self._info.affixtype})
parent.sort = self._lang:makeSortKey(self._info.sort or self._term)
table.insert(parents, parent)
return parents
end
function Category:getChildren()
return nil
end
function Category:getUmbrella()
return nil
end
return export