Module:User:Balyozxane: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
m oops, italicize Latin-script affixes |
modified breadcrumbs to be less redundant, and modified category structure: specific POSes under the corresponding "words" category, specific POS with id under specific POS category |
||
Line 39: | Line 39: | ||
self._info = info |
self._info = info |
||
-- |
-- Add default POS, or make POS plural. |
||
self._pos = self._info.pos or "words" |
self._pos = self._info.pos or "words" |
||
Line 90: | Line 90: | ||
function Category:getBreadcrumbName() |
function Category:getBreadcrumbName() |
||
local affix = require("Module:script utilities").tag_text( |
|||
local link = m_links.full_link({lang = self._lang, alt = self._alt or self._term, sc = self._sc, tr = "-"}, "term") |
|||
self._alt or self._term, |
|||
return self._pos .. " " .. self._info.affixtype .. "ed with " .. link .. (self._info.id and " (" .. self._info.id .. ")" or "") |
|||
self._lang, |
|||
self._sc, |
|||
"term" |
|||
⚫ | |||
if self._pos and self._pos == "words" then |
|||
⚫ | |||
return affix .. " (" .. self._info.id .. ")" |
|||
else |
|||
return affix |
|||
⚫ | |||
else |
|||
return self._pos |
|||
end |
|||
end |
end |
||
Line 133: | Line 147: | ||
local parents = {} |
local parents = {} |
||
local parent |
local parent |
||
if self._info.id then |
|||
if self._pos and self._pos == "words" then |
|||
⚫ | |||
parent.name = export.new({ |
|||
code = self._info.code, |
|||
term = self._info.term, |
|||
affixtype = self._info.affixtype |
|||
}) |
|||
⚫ | |||
⚫ | |||
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 = {} |
||
Line 138: | Line 196: | ||
parent.sort = self._lang:makeSortKey(self._info.sort or self._term) |
parent.sort = self._lang:makeSortKey(self._info.sort or self._term) |
||
table.insert(parents, parent) |
table.insert(parents, parent) |
||
⚫ | |||
⚫ | |||
⚫ | |||
parent.name = export.new({code = self._info.code, term = self._info.term, affixtype = self._info.affixtype}) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
return parents |
return parents |
Revision as of 21:31, 13 July 2017
- This module lacks a documentation subpage. You may create it.
- Useful links: subpage list • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of Balyozxane, for their own experimentation. Items in this module may be added and removed at Balyozxane's discretion; do not rely on this module's stability.
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",
}
self._desc = desc[self._info.affixtype] or error("Invalid affixtype specified.")
return self
end
export.new = Category.new
export.new_main = Category.new_main
function Category:getInfo()
return self._info
end
function Category:getBreadcrumbName()
local affix = require("Module:script utilities").tag_text(
self._alt or self._term,
self._lang,
self._sc,
"term"
)
if self._pos and self._pos == "words" then
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