Modul:autocat
Tampilan
Dokumentasi untuk modul ini dapat dibuat di Modul:autocat/doc
local p = {}
local U = require("Modul:utilitas")
local Lang = require("Modul:bahasa")
-- Category definitions
local categoryTree = {
-- Bawaan
["Lambang"] = { base = true, global = true },
["Pamiaroan laman"] = { base = true, global = true },
["Rima"] = { base = true, global = true },
["Lema"] = { base = true, global = true },
["Sublema"] = { base = true, global = true },
["Ragam bahaso"] = { base = true, global = true },
["Istilah manuruik asa mulo"] = { base = true, global = true },
["Istilah homonim"] = { base = true, global = true },
["Istilah nan tapiliah"] = { base = true, global = true },
-- Lema turunannya
["Kato saru"] = { parents = { "Lema" }, global = true },
["Kato karajo"] = { parents = { "Lema" }, global = true },
["Namo diri"] = { parents = { "Kato bando" }, global = true },
["Kato bando"] = { parents = { "Lema" }, global = true },
["Kato katarangan"] = { parents = { "Lema" }, global = true },
["Kato bilangan"] = { parents = { "Lema" }, global = true },
["Kato ganti"] = { parents = { "Lema" }, global = true },
["Kato sambuang"] = { parents = { "Lema" }, global = true },
["Kato sipaik"] = { parents = { "Lema" }, global = true },
["Kato apik"] = { parents = { "Lema" }, global = true },
["Kato balakang"] = { parents = { "Lema" }, global = true },
["Kato muko"] = { parents = { "Lema" }, global = true },
["Artikel"] = { parents = { "Lema" }, global = true },
["Partikel"] = { parents = { "Lema" }, global = true },
["Papatah-patitiah"] = { parents = { "Lema" }, global = true },
["Morfem"] = { parents = { "Lema" }, global = true },
["Istilah rangkaian kato"] = { parents = { "Lema" }, global = true },
-- Morfem
["Awalan"] = { parents = { "Morfem" }, global = true },
["Akiran"] = { parents = { "Morfem" }, global = true },
-- Sublema
["Bantuak kato karajo"] = { parents = { "Sublema", "Kato karajo" }, global = true },
["Bantuak namo diri"] = { parents = { "Sublema", "Namo diri" }, global = true },
["Bantuak kato bando"] = { parents = { "Sublema", "Kato bando" }, global = true },
["Bantuak kato katarangan"] = { parents = { "Sublema", "Kato katarangan" }, global = true },
["Bantuak kato bilangan"] = { parents = { "Sublema", "Kato bilangan" }, global = true },
["Bantuak kato ganti"] = { parents = { "Sublema", "Kato ganti" }, global = true },
["Bantuak kato sipaik"] = { parents = { "Sublema", "Kato sipaik" }, global = true },
["Bantuak artikel"] = { parents = { "Sublema", "Artikel" }, global = true },
["Partisipel"] = { parents = { "Bantuak kato karajo" }, global = true },
-- Pamiaroan laman
["Istilah jo panyabuikan IPA"] = { parents = { "Pamiaroan laman" }, global = true },
["Istilah jo pautan suaro"] = { parents = { "Pamiaroan laman" }, global = true },
["Istilah jo kutipan"] = { parents = { "Pamiaroan laman" }, global = true },
["Istilah jo contoh kalimat"] = { parents = { "Pamiaroan laman" }, global = true },
["Istilah jo ragam bantuak uruih"] = { parents = { "Pamiaroan laman" }, global = true },
["Istilah jo bantuak Latin"] = { parents = { "Pamiaroan laman" }, global = true },
["Istilah jo pamintaan definisi"] = { parents = { "Pamiaroan laman" }, global = true },
}
-- Etymology category types
-- If value = true → base type
-- If value = "<parent>" → subtype, parent = that base type
local etymTypes = {
otherlang = {
["Pinjaman"] = true,
["Pinjaman palsu"] = "Pinjaman",
["Katurunan"] = true,
["Warisan"] = true,
},
samelang = {
["Gabungan"] = true,
["Paduan"] = true,
},
}
-- Unified global category insertion
local globalCats = function(cat)
return { U.cat(cat .. " manuruik bahaso") }
end
-- Helper: lowercase first letter only
local function lcFirst(str)
if not str or str == "" then return str end
return mw.ustring.lower(mw.ustring.sub(str, 1, 1)) .. mw.ustring.sub(str, 2)
end
-- Unified description generation
local function makeDescription(usePart, langNameNocap, rhyme, syll, etyType, srcLangName, isSamelang)
if etyType and srcLangName then
return string.format("Kategori ko mamuek %s dari %s dalam %s.", lcFirst(etyType), srcLangName, langNameNocap)
elseif isSamelang then
return string.format("Kategori ko mamuek %s dalam %s.", lcFirst(usePart), langNameNocap)
elseif usePart == "Rima" then
return string.format("Kategori ko mamuek rima dalam %s.", langNameNocap)
elseif rhyme and not syll then
return string.format("Kategori ko mamuek rima -%s dalam %s.", rhyme, langNameNocap)
elseif rhyme and syll then
return string.format("Kategori ko mamuek rima -%s dengan %s suku kato dalam %s.", rhyme, syll, langNameNocap)
else
return string.format("Kategori ko mamuek %s dalam %s.", lcFirst(usePart), langNameNocap)
end
end
function p.main(frame)
local title = mw.title.getCurrentTitle().text
local langCode, usePart = title:match("^([^:]+):(.+)$")
if not langCode or not usePart then return "" end
local langName = Lang.getLangName{ args = { langCode } }
local langNameNocap = lcFirst(langName)
if not langName then return U.errorcat("basa") end
local output, parents = {}, {}
-- detect rhyme and syllable
local rhyme, syll = usePart:match("^Rima/([^/]+)/(%d+) ucap$")
if not rhyme then rhyme = usePart:match("^Rima/([^/]+)$") end
-- detect cross-language
local etyType, srcLangName = usePart:match("^(.+) deri (.+)$")
if etyType and not etymTypes.otherlang[etyType] then
etyType, srcLangName = nil, nil
end
-- etymology parents
if etymTypes.otherlang[usePart] or etymTypes.samelang[usePart] then
local etyParent = etymTypes.otherlang[usePart] or etymTypes.samelang[usePart]
if etyParent == true then
-- base type
table.insert(parents, U.langcat(langCode, "Istilah manuruik asa mulo"))
else
-- subtype
table.insert(parents, U.langcat(langCode, etyParent))
end
for _, cat in ipairs(globalCats(usePart)) do
table.insert(parents, cat)
end
end
-- Rhymecats hierarchy
if usePart == "Rima" then
elseif rhyme and not syll then
table.insert(parents, U.langcat(langCode, "Rima"))
elseif rhyme and syll then
table.insert(parents, U.langcat(langCode, "Rima/" .. rhyme))
end
-- tree-defined parents
local def = categoryTree[usePart]
if def then
if def.parents then
for _, parent in ipairs(def.parents) do
table.insert(parents, U.langcat(langCode, parent))
end
end
if def.global then
table.insert(parents, U.cat(usePart .. " manuruik bahaso"))
end
end
-- base language category
if def and def.base then
table.insert(parents, U.cat(langName))
end
-- cross-language parents
if etyType and srcLangName then
table.insert(parents, U.langcat(langCode, etyType))
table.insert(parents, U.cat(etyType .. " deri " .. srcLangName .. " manuruik bahaso"))
end
-- stack parents below description
table.insert(output, makeDescription(usePart, langNameNocap, rhyme, syll, etyType, srcLangName, etymTypes.samelang[usePart]))
if #parents > 0 then
table.insert(output, table.concat(parents, "\n"))
end
return table.concat(output, "\n")
end
return p