„Modul:AufEinWort Wortbildung“ – Versionsunterschied
Erscheinungsbild
KKeine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
| Zeile 4: | Zeile 4: | ||
local function trim(s) | local function trim(s) | ||
return (tostring(s or ""):gsub("^%s+", ""):gsub("%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 | end | ||
| Zeile 18: | Zeile 26: | ||
end | end | ||
-- | -- Abkürzungs-Mappings (kannst du nach Bedarf erweitern) | ||
local mapWortartToAbbr = { | local mapWortartToAbbr = { | ||
["Dingwort"] = "Dgw.", | ["Dingwort"] = "Dgw.", | ||
| Zeile 33: | Zeile 41: | ||
} | } | ||
-- Sichtbare Abkürzung ermitteln (Param > Mapping > | -- Sichtbare Abkürzung ermitteln (Param-Abk > Mapping der Langform > Langform) | ||
local function abbrOr(paramAbbr, long, tableMap) | local function abbrOr(paramAbbr, long, tableMap) | ||
local a = trim(paramAbbr) | local a = trim(paramAbbr) | ||
| Zeile 41: | Zeile 49: | ||
end | end | ||
-- | -- Sichtbare Token-Links (mit Pipetext = Token), direkt hintereinander | ||
local function visibleTokens(args) | local function visibleTokens(args) | ||
local parts = {} | local parts = {} | ||
for i=1,3 do | for i = 1, 3 do | ||
local t = trim(args[i .. "Wortglied"]) | local t = trim(args[i .. "Wortglied"]) | ||
if t ~= "" then | if t ~= "" then | ||
| Zeile 53: | Zeile 61: | ||
end | end | ||
-- Unsichtbare | -- Unsichtbare Kategorien via Parser ausführen (keine Rückgabe) | ||
local function hiddenCategories(args, frame) | local function hiddenCategories(args, frame) | ||
for i=1,3 do | for i = 1, 3 do | ||
local t = trim(args[i .. "Wortglied"]) | local t = trim(args[i .. "Wortglied"]) | ||
if t ~= "" then | if t ~= "" then | ||
| Zeile 66: | Zeile 74: | ||
local wa = trim(args["Wortart"]) | local wa = trim(args["Wortart"]) | ||
if wa ~= "" then frame:preprocess("[[Kategorie:Wortart " .. wa .. "]]") end | if wa ~= "" then frame:preprocess("[[Kategorie:Wortart " .. wa .. "]]") end | ||
local g = trim(args["Wortgeschlecht"]) | local g = trim(args["Wortgeschlecht"]) | ||
if g ~= "" then frame:preprocess("[[Kategorie:Wortgeschlecht " .. g .. "]]") end | if g ~= "" then frame:preprocess("[[Kategorie:Wortgeschlecht " .. g .. "]]") end | ||
local sAbk = abbrOr(args["SprachstufeAbk"], args["Sprachstufe"], mapSprachToAbbr) | local sAbk = abbrOr(args["SprachstufeAbk"], args["Sprachstufe"], mapSprachToAbbr) | ||
if trim(sAbk) ~= "" then frame:preprocess("[[Kategorie:Sprachstufe " .. sAbk .. "]]") end | if trim(sAbk) ~= "" then frame:preprocess("[[Kategorie:Sprachstufe " .. sAbk .. "]]") end | ||
end | end | ||
-- SMW-#set via Parser ausführen (keine Rückgabe) | |||
local function smwSets(args, frame, pageName) | 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 | -- Oberbegriff | ||
frame:preprocess("{{#set: ist Wortbildung::" .. | frame:preprocess("{{#set: ist Wortbildung::" .. pn .. "}}") | ||
-- Klassifikation (Langform) | -- Klassifikation (Langform speichern) | ||
local wa = trim(args["Wortart"]) | local wa = trim(args["Wortart"]) | ||
if wa ~= "" then frame:preprocess("{{#set: ist Wortart::" .. wa .. "}}") end | if wa ~= "" then frame:preprocess("{{#set: ist Wortart::" .. wa .. "}}") end | ||
local g = trim(args["Wortgeschlecht"]) | local g = trim(args["Wortgeschlecht"]) | ||
if g ~= "" then frame:preprocess("{{#set: ist Wortgeschlecht::" .. g .. "}}") end | if g ~= "" then frame:preprocess("{{#set: ist Wortgeschlecht::" .. g .. "}}") end | ||
local sLong = trim(args["Sprachstufe"]) | local sLong = trim(args["Sprachstufe"]) | ||
if sLong ~= "" then frame:preprocess("{{#set: ist Sprachstufe::" .. sLong .. "}}") end | if sLong ~= "" then frame:preprocess("{{#set: ist Sprachstufe::" .. sLong .. "}}") end | ||
-- Teile nach Art → Property | -- Teile nach Art → Property | ||
local art2prop = { | local art2prop = { | ||
["Wortbildung"] = "hat Wortbildung", | ["Wortbildung"] = "hat Wortbildung", | ||
| Zeile 91: | Zeile 108: | ||
["Wortfuge"] = "hat Wortfuge" | ["Wortfuge"] = "hat Wortfuge" | ||
} | } | ||
for i=1,3 do | for i = 1, 3 do | ||
local t = trim(args[i .. "Wortglied"]) | local t = trim(args[i .. "Wortglied"]) | ||
local a = trim(args[i .. "Wortgliedart"]) | local a = trim(args[i .. "Wortgliedart"]) | ||
| Zeile 99: | Zeile 116: | ||
end | end | ||
end | end | ||
end | end | ||
function p.render(frame) | function p.render(frame) | ||
local args = frame:getParent() and frame:getParent().args or frame.args | local args = (frame:getParent() and frame:getParent().args) or frame.args | ||
local | -- **Wichtig**: Seitennamen als String | ||
local pageNameText = currentPageText() | |||
-- | -- sichtbare Token + Abkürzungen | ||
local vis = visibleTokens(args) | local vis = visibleTokens(args) | ||
local waAbk = abbrOr(args["WortartAbk"], args["Wortart"], mapWortartToAbbr) | |||
local waAbk = abbrOr(args["WortartAbk"], args["Wortart"], mapWortartToAbbr) | local gAbk = abbrOr(args["WortgeschlechtAbk"], args["Wortgeschlecht"], mapGeschlechtToAbbr) | ||
local gAbk = abbrOr(args["WortgeschlechtAbk"], args["Wortgeschlecht"], mapGeschlechtToAbbr) | local sAbk = abbrOr(args["SprachstufeAbk"], args["Sprachstufe"], mapSprachToAbbr) | ||
local sAbk = abbrOr(args["SprachstufeAbk"], args["Sprachstufe"], mapSprachToAbbr) | |||
local tail = {} | local tail = {} | ||
| Zeile 159: | Zeile 140: | ||
end | end | ||
-- | -- Seiteneffekte ausführen | ||
hiddenCategories(args, frame) | hiddenCategories(args, frame) | ||
smwSets(args, frame, | smwSets(args, frame, pageNameText) | ||
-- | -- Mit Zeilenumbruch enden, damit nachfolgender Fließtext nicht eingesogen wird | ||
return visible .. "\n" | return visible .. "\n" | ||
end | end | ||
return p | return p | ||
Version vom 4. September 2025, 11:12 Uhr
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)
-- Mit Zeilenumbruch enden, damit nachfolgender Fließtext nicht eingesogen wird
return visible .. "\n"
end
return p