Zum Inhalt springen

„Modul:AufEinWort Wortbildung“ – Versionsunterschied

aus AufEinWort, der freien Forschung
Die Seite wurde neu angelegt: „-- Modul:AufEinWortWortbildung local p = {} local function trim(s) return (tostring(s or ""):gsub("^%s+", ""):gsub("%s+$", "")) 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(to…“
 
KKeine Bearbeitungszusammenfassung
Zeile 47: Zeile 47:
     local t = trim(args[i .. "Wortglied"])
     local t = trim(args[i .. "Wortglied"])
     if t ~= "" then
     if t ~= "" then
       table.insert(parts, "[[:Kategorie:" .. t .. "]]")
       table.insert(parts, "[[:Kategorie:" .. t .. "|" .. t .. "]]")
     end
     end
   end
   end
Zeile 54: Zeile 54:


-- Unsichtbare Kategorisierung inkl. Sortierschlüssel
-- Unsichtbare Kategorisierung inkl. Sortierschlüssel
local function hiddenCategories(args)
local function hiddenCategories(args, frame)
  local cats = {}
   for i=1,3 do
   for i=1,3 do
     local t = trim(args[i .. "Wortglied"])
     local t = trim(args[i .. "Wortglied"])
Zeile 61: Zeile 60:
       local sort = trim(args[i .. "Sort"])
       local sort = trim(args[i .. "Sort"])
       if sort == "" then sort = sortkey(t) end
       if sort == "" then sort = sortkey(t) end
       table.insert(cats, "[[Kategorie:" .. t .. "|" .. sort .. "]]")
       frame:preprocess("[[Kategorie:" .. t .. "|" .. sort .. "]]")
     end
     end
   end
   end
   -- Klassifikations-Kategorien
   -- Klassifikations-Kategorien
   local wa = trim(args["Wortart"])
   local wa = trim(args["Wortart"])
   if wa ~= "" then table.insert(cats, "[[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 table.insert(cats, "[[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 table.insert(cats, "[[Kategorie:Sprachstufe " .. sAbk .. "]]") end
   if trim(sAbk) ~= "" then frame:preprocess("[[Kategorie:Sprachstufe " .. sAbk .. "]]") end
   return table.concat(cats)
end
 
local function smwSets(args, frame, pageName)
  -- Oberbegriff
  frame:preprocess("{{#set: ist Wortbildung::" .. pageName .. "}}")
 
  -- Klassifikation (Langform)
  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 (Langform speichern)
  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
end


Zeile 114: Zeile 141:
   local pageName = mw.title.getCurrentTitle().text
   local pageName = mw.title.getCurrentTitle().text


  -- Sichtbare Token (jetzt mit Pipetext)
   local vis = visibleTokens(args)
   local vis = visibleTokens(args)


   -- Abkürzungen für Anzeige
   -- Abkürzungen für Anzeige (unverändert)
   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 displayTail = {}
   local tail = {}
   if trim(waAbk) ~= "" then table.insert(displayTail, waAbk) end
   if trim(waAbk) ~= "" then table.insert(tail, waAbk) end
   if trim(gAbk)  ~= "" then table.insert(displayTail, gAbk)  end
   if trim(gAbk)  ~= "" then table.insert(tail, gAbk)  end
   if trim(sAbk)  ~= "" then table.insert(displayTail, sAbk)  end
   if trim(sAbk)  ~= "" then table.insert(tail, sAbk)  end


   local visible = vis
   local visible = vis
   if #displayTail > 0 then
   if #tail > 0 then
     visible = visible .. " " .. table.concat(displayTail, " ")
     visible = visible .. " " .. table.concat(tail, " ")
   end
   end


   local cats = hiddenCategories(args)
   -- Kategorien & #set still ausführen (keine Ausgabe)
   local sets = smwSets(args, pageName)
  hiddenCategories(args, frame)
   smwSets(args, frame, pageName)


   -- Keine erzwungenen Zeilenumbrüche
   -- WICHTIG: mit Zeilenumbruch enden, damit anschließender Fließtext sicher getrennt ist
   return visible .. cats .. sets
   return visible .. "\n"
end
end


return p
return p

Version vom 4. September 2025, 11:06 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

-- 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ürzungen ↔ Langform
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 > Mapping > Fallback)
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

-- Baut sichtbare Linkfolge der Tokens (ohne Trennzeichen, die Bindestriche stehen im Token)
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 Kategorisierung inkl. Sortierschlüssel
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

local function smwSets(args, frame, pageName)
  -- Oberbegriff
  frame:preprocess("{{#set: ist Wortbildung::" .. pageName .. "}}")

  -- Klassifikation (Langform)
  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 (Langform speichern)
  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

-- SMW #set Blöcke
local function smwSets(args, pageName)
  local sets = {}

  -- Oberbegriff
  table.insert(sets, "{{#set: ist Wortbildung::" .. pageName .. "}}")

  -- Klassifikation (Langform)
  local wa = trim(args["Wortart"])
  if wa ~= "" then table.insert(sets, "{{#set: ist Wortart::" .. wa .. "}}") end

  local g = trim(args["Wortgeschlecht"])
  if g ~= "" then table.insert(sets, "{{#set: ist Wortgeschlecht::" .. g .. "}}") end

  local sLong = trim(args["Sprachstufe"])
  if sLong ~= "" then table.insert(sets, "{{#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]
      table.insert(sets, "{{#set: " .. prop .. "::" .. cleanValue(t) .. "}}")
    end
  end

  return table.concat(sets)
end

function p.render(frame)
  local args = frame:getParent() and frame:getParent().args or frame.args
  local pageName = mw.title.getCurrentTitle().text

  -- Sichtbare Token (jetzt mit Pipetext)
  local vis = visibleTokens(args)

  -- Abkürzungen für Anzeige (unverändert)
  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

  -- Kategorien & #set still ausführen (keine Ausgabe)
  hiddenCategories(args, frame)
  smwSets(args, frame, pageName)

  -- WICHTIG: mit Zeilenumbruch enden, damit anschließender Fließtext sicher getrennt ist
  return visible .. "\n"
end


return p