Modul:Klasse/Work: Unterschied zwischen den Versionen
Aus FürthWiki
(Die Seite wurde neu angelegt: „local p = {} local com = require("Module:Common") local str = require("Module:String") local atr = require("Module:Attribut") local frm = require("Modul:Formular/Work") local fab = require("Modul:Faktenbox") local htm = require("Modul:HTML") function p.Faktenbox( frame ) local args = frame:getParent().args local t = p.daten( frame, args ) -- Use preprocess to render the factbox and all contens at once return frame:preprocess(t) end function p.dat…“) |
Keine Bearbeitungszusammenfassung |
||
| Zeile 79: | Zeile 79: | ||
-- Attribut-Tabelle | -- Attribut-Tabelle | ||
attr_list = p. | local attr_list = p.attrListParser(args.AttributListe) | ||
attr_list = p.attrListFlatener(attr_list) | |||
if #attr_list > 0 then | if #attr_list > 0 then | ||
attr = {"Attribut", "Datentyp", "EhemalsAttribut", | attr = {"Attribut", "Datentyp", "EhemalsAttribut", | ||
| Zeile 218: | Zeile 219: | ||
end | end | ||
function p. | function p.attrListParser(attr_list, recursion) | ||
-- Kommandozeile zum Debuggen: | -- Kommandozeile zum Debuggen: | ||
-- mw.logObject(p. | -- mw.logObject(p.attrListParser(";A;{;B;C;};D;")) | ||
local | local attr_list_parsed = {} | ||
local loop_count = 0 | |||
attr_list = str.strip(attr_list or "") | |||
while loop_count < 100 and attr_list ~= "" do -- Schleifenbegrenzung | |||
loop_count = loop_count + 1 | |||
local semicolon = string.find(attr_list, ";") | |||
local brace_open = string.find(attr_list, "\{") | |||
local brace_close = string.find(attr_list, "\}") | |||
if (brace_open ~= nil and brace_close == nil) or -- Klammer nicht paarweise | |||
semicolon = | (brace_open == nil and brace_close ~= nil) or -- oder | ||
(brace_open or 0) >= (brace_close or 1) then -- in falscher Reihenfolge | |||
attr_list = "" -- => Abbruch | |||
elseif semicolon == nil and -- letzer Eintrag | |||
brace_open == nil and brace_close == nil then | |||
table.insert(attr_list_parsed, attr_list) | |||
attr_list = "" | |||
elseif semicolon ~= nil and -- Semikolon | |||
(brace_open == nil or semicolon < brace_open) then -- ggf. vor öffnender Klammer | |||
local attr = str.strip(string.sub(attr_list, 1, semicolon - 1)) | |||
if attr ~= "" then | |||
table.insert(attr_list_parsed, attr) | |||
end | end | ||
attr_list = string.sub(attr_list, semicolon + 1) | |||
-- | elseif brace_open ~= nil and brace_close ~= nil and -- eingebettete Klammerung | ||
brace_open < brace_close then | |||
-- | if not recursion then -- Rekursionsschutz, nur 2 Ebenen bzw. 1 Selbstaufruf | ||
local attr_sublist = -- Klammerinhalt | |||
table.insert( | string.sub(attr_list, brace_open + 1, brace_close - 1) | ||
attr_sublist = p.attrListParser(attr_sublist, true) -- sich selbst aufrufen mit recursion = true | |||
if #attr_sublist > 0 then | |||
table.insert(attr_list_parsed, attr_sublist) | |||
end | |||
end | |||
attr_list = string.sub(attr_list, brace_close + 1) | |||
else -- da stimmt was nicht => Abbruch | |||
attr_list = "" | |||
end | |||
attr_list = str.strip(attr_list) | |||
end | |||
return attr_list_parsed | |||
end | |||
function p.attrListFlatener(attr_list) | |||
local attr_list_flat = {} | |||
for _, outer in ipairs(attr_list) do | |||
if type(outer) ~= "table" then | |||
table.insert(attr_list_flat, outer) | |||
else | |||
for _, inner in ipairs(outer) do | |||
table.insert(attr_list_flat, inner) | |||
end | end | ||
end | |||
end | end | ||
return | return attr_list_flat | ||
end | end | ||
return p | return p | ||
Version vom 28. Februar 2026, 18:34 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Klasse/Work/Doku erstellt werden
local p = {}
local com = require("Module:Common")
local str = require("Module:String")
local atr = require("Module:Attribut")
local frm = require("Modul:Formular/Work")
local fab = require("Modul:Faktenbox")
local htm = require("Modul:HTML")
function p.Faktenbox( frame )
local args = frame:getParent().args
local t = p.daten( frame, args )
-- Use preprocess to render the factbox and all contens at once
return frame:preprocess(t)
end
function p.daten(frame, args)
local title = mw.title.getCurrentTitle().text
local t = '<table class="wikitable">'..
'<th>[[FürthWiki:Semantik]]</th>'..
'<th colspan="3">'..'[[KlassenName::'..title..']]</th>'
t=t..'<tr>'..
'<td>[[Attribut:Bild|Bild dieser Klasse]]</td>'
if not com.isEmpty(args.Bild) then
t=t..'<td colspan="3"><div class="ImageLink">[[Datei:'..
args.Bild..'|48px]]</div></td>'
mw.smw.set{["Bild"] = "Datei:" .. args.Bild}
end
t=t..'</tr><tr>'..
'<td>[[Attribut:KlassenVorlage|Vorlage]]</td>'
t=t..'<td colspan="3">[[KlassenVorlage::Vorlage:'..title..']]</td>'
t=t..'</tr><tr>'..
'<td>[[Attribut:KlassenModul|Modul]]</td>'
t=t..'<td colspan="3">[[KlassenModul::Modul:'..title..']]</td>'
t=t..'</tr><tr>'..
'<td>[[Attribut:KlassenKategorie|Kategorie]]</td>'
if not com.isEmpty(args.KlassenKategorie) then
t=t..'<td colspan="3">[[KlassenKategorie::Kategorie:'..args.KlassenKategorie..']]</td>'
end
t=t..'</tr><tr>'..
'<td>[[Attribut:KlassenFormular|Formular]]</td>'
t=t..'<td colspan="3">[[KlassenFormular::Formular:'..title..']]</td>'
t=t..'</tr><tr>'..
'<td>Attribut</td>'
t=t..'<td colspan="3">[[Attribut:'..title..']]</td>'
t=t..'</tr><tr>'..
'<td>[[Attribut:Suchformular|Suchformular]]</td>'
if not com.isEmpty(args.KlassenKategorie) then
t=t..'<td colspan="2">[[Suchformular::Abfrage_'..args.KlassenKategorie..']]</td>'..
'<td>[[Formular:Abfrage_'..args.KlassenKategorie..']]</td>'
end
t=t..'</tr><tr>'..
'<td>[[Attribut:Suchvorlage|Suchvorlage]]</td>'
if not com.isEmpty(args.KlassenKategorie) then
t=t..'<td colspan="2">[[Suchvorlage::Abfrage_'..args.KlassenKategorie..']]</td>'..
'<td>[[Spezial:Abfrage_ausführen/Abfrage_'..args.KlassenKategorie..']]</td>'
end
t=t..'</tr><tr>'..
'<td>[[Attribut:AttributListe|AttributListe]]</td>'
if not com.isEmpty(args.AttributListe) then
t=t..'<td colspan="3">[[AttributListe::'..args.AttributListe..']]</td>'
end
t=t..'<tr>'..
'<td>[[Bild:IconSearch.svg|16px|semantisches Browsen|link=Spezial:Durchsuchen/{{NAMESPACE}}:{{PAGENAME}}]]</td>'..
'<td colspan="3">[[Spezial:Durchsuchen/{{NAMESPACE}}:{{PAGENAME}}|semantisches Browsen]]</td>'..
'</tr>'
t=t..'</table>'
-- Attribut-Tabelle
local attr_list = p.attrListParser(args.AttributListe)
attr_list = p.attrListFlatener(attr_list)
if #attr_list > 0 then
attr = {"Attribut", "Datentyp", "EhemalsAttribut",
"Anzeigegenauigkeit", "Einzahl", "Mehrzahl", "Delimiter",
"FieldArgs", "Infotext", "Anzeigeformat"}
-- Tabellen-Kopf
t = t .. htm.tableHeader(attr)
-- Tabellen-Zeilen
for i, a in ipairs(attr_list) do
local line = {}
-- Attribut-Attribute
local attr_val = atr.getAttrAttributes(a, title)
attr_val = attr_val or {}
-- Zeile befüllen
for i, l in ipairs(attr) do
if l == "Attribut" then
line[i] = "[[Attribut:" .. a .. "|" .. a .. "]]"
else
line[i] = attr_val[l] or ""
end
end
t = t .. htm.tableLine(line)
end
-- Tabellen-Fuß
t = t .. htm.tableFooter()
end
-- Attribute-Liste in Attribut:Attribut ablegen
for i = 1, #attr_list do
attr_list[i] = "Attribut:" .. attr_list[i]
end
mw.smw.set{["Attribut"] = attr_list}
return t
end
function p.getAttrData(klasse)
local attr_data = {}
local query = {"[[Klasse:" .. klasse .. "]]",
"?AttributListe"}
query = mw.smw.ask(query)
if query ~= nil then
local attr_list = query[1]["AttributListe"]
attr_list = frm.attrListParser(attr_list)
attr_data = p.getAttrDataHelper(attr_list, recursion)
end
return attr_data
end
function p.getAttrDataHelper(attr_list, recursion)
local attr_data = {}
if #attr_list > 0 then
for i, a in ipairs(attr_list) do
if type(a) ~= "table" then
attr_data[i] = atr.getAttrAttributes(a, klasse)
attr_data[i]["Attribut"] = a
elseif not recursion then
local attr_sublist = p.getAttrDataHelper(a, true) -- max. 1 Rekursion
if #attr_sublist > 0 then
attr_data[i] = attr_sublist
end
end
end
end
return attr_data
end
function p.Formular(frame, klasse)
-- Kommandozeile zum Debuggen:
-- frame=mw.getCurrentFrame(); print(p.Formular(frame, "Bauwerk"))
local t = ""
local attr_data = p.getAttrData(klasse)
t = frm.attrForm(frame, attr_data)
return t
end
function p.faktenboxDatenTab(fbdata, kindex)
-- mw.log("datenTab(fbdata)")
-- mw.logObject(frame, "frame")
--[[ Konsolenzeile zum Debuggen:
fab=require("Modul:Faktenbox"); fbdata=fab.getFbdata{pargs={Baujahr="1987",AktenNr="D-5-63-000-1464"}};
fbdata.klasse={"Bauwerk"}; fbdata.kategorie={"Bauwerke"}; fbdata.fullpagename="Pegnitz"; fbdata.subpagename="Pegnitz";
print(p.faktenboxDatenTab(fbdata)); mw.logObject(fbdata)
]]
local t = ""
local klasse = fbdata.klasse[kindex or 1]
local attr_data = p.getAttrData(klasse)
-- Vorbereitung Nicht-unterstützte Argumente testen
local pargs_test = {}
for a, _ in pairs(fbdata.pargs) do
pargs_test[a] = true
end
-- Zusammenbau
t = t .. fab.zeileKategorieSeite(fbdata)
-- EhemalsAttribut ermitteln (gibt es nur 1x)
local ehemals_attribut
for _, a in ipairs(attr_data) do
if a["EhemalsAttribut"] ~= nil then
ehemals_attribut = a["EhemalsAttribut"]
break
end
end
-- Attribut-Zeilen
for _, a in ipairs(attr_data) do
local attr = a["Attribut"]
local delimiter = a["Delimiter"]
if a["Attribut"] == "AktenNr" then -- Denkmalschutz Akten-Nummer
t = t .. fab.zeileAktenNr(fbdata)
elseif a["EhemalsAttribut"] ~= nil then -- Kombi von Ehemals-Attribut und Ende-Datum/Jahr
t = t .. fab.zeileEndeJahr{fbdata = fbdata, -- Z. B. Ehemals bei Abrissjahr, Verstorben bei Todesdatum
attr_year = attr, attr_ended = a["EhemalsAttribut"],
delimiter = delimiter}
elseif attr ~= ehemals_attribut and attr ~= "Bild" then
t = t .. fab.zeile{fbdata = fbdata, attr_name = attr,
delimiter = delimiter}
end
pargs_test[a["Attribut"]] = nil -- Argumente ausklammern
end
-- Rest der Tabelle
t = fab.table_header_footer(t)
t = t .. fab.zeileSemantikBrowsenAbfrage(fbdata)
-- Tab draus machen
t = fab.tab(t, "Daten")
-- Nicht-unterstützte Argumente testen
for _, a in ipairs(fab.karten_args ) do -- Karten-Argumente ausklammern
pargs_test[a] = nil
end
local pargs_test_fail = false
for _, _ in pairs(pargs_test) do -- Argumente übrig?
pargs_test_fail = true
break
end
if pargs_test_fail then
fab.addWartungsmeldung(fbdata, "Faktenbox-Daten nicht unterstützt (Einzelwerte)")
end
-- mw.logObject(t, "t")
return t
end
function p.attrListParser(attr_list, recursion)
-- Kommandozeile zum Debuggen:
-- mw.logObject(p.attrListParser(";A;{;B;C;};D;"))
local attr_list_parsed = {}
local loop_count = 0
attr_list = str.strip(attr_list or "")
while loop_count < 100 and attr_list ~= "" do -- Schleifenbegrenzung
loop_count = loop_count + 1
local semicolon = string.find(attr_list, ";")
local brace_open = string.find(attr_list, "\{")
local brace_close = string.find(attr_list, "\}")
if (brace_open ~= nil and brace_close == nil) or -- Klammer nicht paarweise
(brace_open == nil and brace_close ~= nil) or -- oder
(brace_open or 0) >= (brace_close or 1) then -- in falscher Reihenfolge
attr_list = "" -- => Abbruch
elseif semicolon == nil and -- letzer Eintrag
brace_open == nil and brace_close == nil then
table.insert(attr_list_parsed, attr_list)
attr_list = ""
elseif semicolon ~= nil and -- Semikolon
(brace_open == nil or semicolon < brace_open) then -- ggf. vor öffnender Klammer
local attr = str.strip(string.sub(attr_list, 1, semicolon - 1))
if attr ~= "" then
table.insert(attr_list_parsed, attr)
end
attr_list = string.sub(attr_list, semicolon + 1)
elseif brace_open ~= nil and brace_close ~= nil and -- eingebettete Klammerung
brace_open < brace_close then
if not recursion then -- Rekursionsschutz, nur 2 Ebenen bzw. 1 Selbstaufruf
local attr_sublist = -- Klammerinhalt
string.sub(attr_list, brace_open + 1, brace_close - 1)
attr_sublist = p.attrListParser(attr_sublist, true) -- sich selbst aufrufen mit recursion = true
if #attr_sublist > 0 then
table.insert(attr_list_parsed, attr_sublist)
end
end
attr_list = string.sub(attr_list, brace_close + 1)
else -- da stimmt was nicht => Abbruch
attr_list = ""
end
attr_list = str.strip(attr_list)
end
return attr_list_parsed
end
function p.attrListFlatener(attr_list)
local attr_list_flat = {}
for _, outer in ipairs(attr_list) do
if type(outer) ~= "table" then
table.insert(attr_list_flat, outer)
else
for _, inner in ipairs(outer) do
table.insert(attr_list_flat, inner)
end
end
end
return attr_list_flat
end
return p