Modul:AufEinWort Wortbildung
Erscheinungsbild
Die Dokumentation für dieses Modul kann unter Modul:AufEinWort Wortbildung/Doku erstellt werden
-- Modul:AufEinWortWortbildung
local p = {}
local function trim(s)
return (tostring(s or ""):gsub("^%s+", ""):gsub("%s+$", ""))
end
-- Seitentitel als String (ohne Namensraum) robust holen
local function currentPageText()
local t = mw.title.getCurrentTitle()
if not t then return "" end
-- bevorzugt .text; fallback auf prefixedText
return t.text or t.prefixedText or tostring(t) or ""
end
-- Entfernt nur führende/abschließende Bindestriche für Sortierschlüssel
local function sortkey(token)
token = trim(token)
token = token:gsub("^%-+", ""):gsub("%-+$", "")
return token
end
-- Für Property-Werte: führende/abschließende Bindestriche entfernen
local function cleanValue(token)
return sortkey(token)
end
-- Abkürzungs-Mappings (kannst du nach Bedarf erweitern)
local mapWortartToAbbr = {
["Dingwort"] = "Dgw.",
["Dingname"] = "Dgn."
}
local mapGeschlechtToAbbr = {
["weiblich"] = "wl.",
["männlich"] = "ml.",
["sachlich"] = "sl."
}
local mapSprachToAbbr = {
["Deutsch"] = "deu.",
["deutsch"] = "deu."
}
-- Sichtbare Abkürzung ermitteln (Param-Abk > Mapping der Langform > Langform)
local function abbrOr(paramAbbr, long, tableMap)
local a = trim(paramAbbr)
if a ~= "" then return a end
local longN = trim(long)
return tableMap[longN] or longN
end
-- Sichtbare Token-Links (mit Pipetext = Token), direkt hintereinander
local function visibleTokens(args)
local parts = {}
for i = 1, 3 do
local t = trim(args[i .. "Wortglied"])
if t ~= "" then
table.insert(parts, "[[:Kategorie:" .. t .. "|" .. t .. "]]")
end
end
return table.concat(parts, "")
end
-- Unsichtbare Kategorien via Parser ausführen (keine Rückgabe)
local function hiddenCategories(args, frame)
for i = 1, 3 do
local t = trim(args[i .. "Wortglied"])
if t ~= "" then
local sort = trim(args[i .. "Sort"])
if sort == "" then sort = sortkey(t) end
frame:preprocess("[[Kategorie:" .. t .. "|" .. sort .. "]]")
end
end
-- Klassifikations-Kategorien
local wa = trim(args["Wortart"])
if wa ~= "" then frame:preprocess("[[Kategorie:Wortart " .. wa .. "]]") end
local g = trim(args["Wortgeschlecht"])
if g ~= "" then frame:preprocess("[[Kategorie:Wortgeschlecht " .. g .. "]]") end
local sAbk = abbrOr(args["SprachstufeAbk"], args["Sprachstufe"], mapSprachToAbbr)
if trim(sAbk) ~= "" then frame:preprocess("[[Kategorie:Sprachstufe " .. sAbk .. "]]") end
end
-- SMW-#set via Parser ausführen (keine Rückgabe)
local function smwSets(args, frame, pageName)
-- pageName robust zu String
local pn = trim(type(pageName) == "string" and pageName or tostring(pageName or ""))
if pn == "" then pn = currentPageText() end
-- Oberbegriff
frame:preprocess("{{#set: ist Wortbildung::" .. pn .. "}}")
-- Klassifikation (Langform speichern)
local wa = trim(args["Wortart"])
if wa ~= "" then frame:preprocess("{{#set: ist Wortart::" .. wa .. "}}") end
local g = trim(args["Wortgeschlecht"])
if g ~= "" then frame:preprocess("{{#set: ist Wortgeschlecht::" .. g .. "}}") end
local sLong = trim(args["Sprachstufe"])
if sLong ~= "" then frame:preprocess("{{#set: ist Sprachstufe::" .. sLong .. "}}") end
-- Teile nach Art → Property
local art2prop = {
["Wortbildung"] = "hat Wortbildung",
["Wortandglied"] = "hat Wortandglied",
["Wortendglied"] = "hat Wortendglied",
["Wortfuge"] = "hat Wortfuge"
}
for i = 1, 3 do
local t = trim(args[i .. "Wortglied"])
local a = trim(args[i .. "Wortgliedart"])
if t ~= "" and a ~= "" and art2prop[a] then
local prop = art2prop[a]
frame:preprocess("{{#set: " .. prop .. "::" .. cleanValue(t) .. "}}")
end
end
end
function p.render(frame)
local args = (frame:getParent() and frame:getParent().args) or frame.args
-- **Wichtig**: Seitennamen als String
local pageNameText = currentPageText()
-- sichtbare Token + Abkürzungen
local vis = visibleTokens(args)
local waAbk = abbrOr(args["WortartAbk"], args["Wortart"], mapWortartToAbbr)
local gAbk = abbrOr(args["WortgeschlechtAbk"], args["Wortgeschlecht"], mapGeschlechtToAbbr)
local sAbk = abbrOr(args["SprachstufeAbk"], args["Sprachstufe"], mapSprachToAbbr)
local tail = {}
if trim(waAbk) ~= "" then table.insert(tail, waAbk) end
if trim(gAbk) ~= "" then table.insert(tail, gAbk) end
if trim(sAbk) ~= "" then table.insert(tail, sAbk) end
local visible = vis
if #tail > 0 then
visible = visible .. " " .. table.concat(tail, " ")
end
-- Seiteneffekte ausführen
hiddenCategories(args, frame)
smwSets(args, frame, pageNameText)
-- … sichtbares "visible" ist fertig …
-- Separator: Standard = NBSP (inline, kein Absatz); optional <br/>
local function isYes(v)
v = trim(v):lower()
return v == "ja" or v == "yes" or v == "1" or v == "true"
end
local sep = isYes(args["Umbruch"]) and "<br/>" or " " -- NBSP
return visible .. sep
end
return p