Zum Inhalt springen

Modul:Vorlage:BS/Alt-Text

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 13. April 2024 um 17:23 Uhr durch Wickie37 (Diskussion | Beiträge). Sie kann sich erheblich von der aktuellen Version unterscheiden.

Die Dokumentation für dieses Modul kann unter Modul:Vorlage:BS/Alt-Text/Doku erstellt werden

local p = {} 

-- Generelle Objekttypen
local types = 
{
["STR"] = "Strecke",
["KMW"] = "Kilometer-Wechsel",
["EIU"] = "Wechsel des Eisenbahninfrastrukturunternehmens",
["GIPl"] = "Kulminations-/Scheitelpunkt",
["ÜST"] = "Überleitstelle / Spurwechsel",
["ABZ"] = "Abzweig",
["KRZ"] = "Kreuzung",
["BHF"] = "Bahnhof / Station",
["KBHF"] = "Kopfbahnhof",
["ABHF"] = "Spitzkehrbahnhof",
["SBHF"] = "S-Bahnhof",
["S+BHF"] = "Bahnhof mit S-Bahn-Halt",
["KSBHF"] = "S-Kopfbahnhof",
["DST"] = "Dienststation / Betriebs- oder Güterbahnhof",
["KDST"] = "Betriebs-/Güterbahnhof",
["HST"] = "Haltepunkt / Haltestelle",
["KHST"] = "Haltepunkt / Haltestelle",
["SHST"] = "S-Bahn-Halt",
["KSHST"] = "S-Bahn-Halt",
["BST"] = "Blockstelle",
["KBST"] = "Betriebsstelle",
["TBHF"] = "Turmbahnhof",
["TSBHF"] = "Turm-S-Bahnhof",
["THST"] = "Turmhaltepunkt",
["TSHST"] = "S-Bahn-Turmhaltepunkt",
["BS2"] = "Verschwenkung",
["BRÜCKE"] = "Brücke",
["SBRÜCKE"] = "Strecke mit Straßenbrücke",
["WBRÜCKE"] = "Brücke über Wasserlauf",
["TUNNEL"] = "Tunnel",
["BUE"] = "Bahnübergang",
["GRENZE"] = "Grenze",
["ZOLL"] = "Grenze",
["TRAJEKT"] = "Fährverbindung "
}

local prefixes = 
{
["x"] = "Strecke außer Betrieb / teilweise außer Betrieb",
["e"] = "Einrichtung außer Betrieb / teilweise außer Betrieb",
["ex"] = "außer Betrieb",
["m"] = "mit U-Bahn",
["mu"] = "mit Eisenbahn",
}

local postfixes = 
{
["q"] = "quer",
["l"] = "nach links",
["r"] = "nach rechts",
["xl"] = "ehemals nach links",
["xr"] = "ehemals nach rechts",
["+l"] = "von links",
["+r"] = "von rechts",
["+xl"] = "ehemals von links",
["+xr"] = "ehemals von rechts",
["g"] = "geradeaus",
["a"] = "Streckenanfang",
["e"] = "Streckenende",
["xa"] = "Strecke bis hier außer Betrieb",
["xe"] = "Strecke ab hier außer Betrieb",
["t"] = "mit Tunnel",
["o"] = "geradeaus oben",
["u"] = "geradeaus unten",
["xo"] = "geradeaus oben, quer außer Betrieb",
["xu"] = "geradeaus unten, quer außer Betrieb",
["2"] = "nach halblinks",
["3"] = "nach halbrechts",
["+1"] = "von halblinks",
["+4"] = "von halbrechts",
}

-- Bezeichnungen die nicht ins allgemeine Schema passen
local special_strings = 
{
["hSTRae"] = "Brücke",
["STRo"] = "Brücke",
["hKRZWae"] = "Brücke über Wasserlauf",
["KRZWu"] = "Tunnel bzw. Unterführung unter Wasserlauf",
["tKRZW"] = "Tunnel unter Wasserlauf",
["tSTRa"] = "Tunnel Anfang",
["tSTR"] = "Tunnel",
["tSTRe"] = "Tunnel Ende",
["STR+GRZq"] = "Grenze",
["hZOLLae"] = "Grenze auf Brücke",
["TZOLLWo"] = "Grenze auf Brücke mit Wasserlauf",
["xhZOLLae"] = "Grenze auf Brücke (Strecke außer Betrieb)",
["xTZOLLWo"] = "Grenze auf Brücke mit Wasserlauf (Strecke außer Betrieb)",
["hSTRae+GRZq"] = "Grenze auf Brücke",
["hKRZWae+GRZq"] = "Grenze auf Brücke mit Wasserlauf",
["WECHSEL"] = "Übergang EBO zu BOStrab",
["uWECHSEL"] = "Übergang BOStrab zu EBO"
}


-- Hauptfunktion
function p.get(frame)
-- ID
    local ID = frame.args[1]

-- Prüfe ob ID in 'special_strings' (evtl. mit Präfix "ex")
    local text = special_strings[ID]
    if text then
        return text
    end
    if mw.ustring.sub(ID, 1, 3) == "ex" then
        text = special_strings[mw.ustring.sub(ID, 3)]
        if text then
            return text .. ' ' .. prefixes["ex"]
        end
    end

-- Sonst zerlege die ID
    local split1, split2 = mw.ustring.find(ID, '%u+%+?%u*')
    local prefix = mw.ustring.sub(ID, 1, split1)
    local main = mw.ustring.sub(ID, split1, split2)
    local postfix = mw.ustring.sub(ID, split2)
    if main == 'BS' and mw.ustring.find(postfix, '%d+') == 1 then
        main = main .. mw.ustring.sub(postfix, 1, 2)
        postfix = mw.ustring.sub(postfix, 2)
    end

-- Mischbetrieb? (Präfix 'm')
    local lastPrefix = mw.ustring.sub(prefix, split1 - 1)
    local mixed_traffic = lastPrefix  == 'm'
-- Tunnel? (Präfix 't')
    local tunnel = lastPrefix == 't'
    if mixed_traffic or tunnel then
       prefix = mw.ustring.sub(prefix, 1, split1 - 1)
    end
-- U-Bahn? (Präfix 'u')
    local underground = mw.ustring.sub(prefix, 1, 2) == 'u'
    if underground then
       prefix = mw.ustring.sub(prefix, 2)
       text = "U-Bahn-"
    end

-- Hole Hauptteil (generelle Art des Objekts) aus 'types'
    text = (text or "") .. (types[main] or "")

-- Wandel die Postfixes in lesbaren Text
    local posttexts = {}
    local i = 1
    local j = 1
    local count = mw.ustring.len(postfix)
    while i <= count do       
       local str = ""
       repeat
          local c = mw.ustring.sub(postfix, i, i + 1)
          str = str .. c
          i = i + 1
       until c ~= '+' and c ~= 'x'
       if postfixes[str] then
          posttexts[j] = postfixes[str]
          j = j + 1
       end
    end
-- Hänge Postfix-Texte (mit Trenner) an 'text' an
    if j > 1 then
       text = text .. ' '
       for k = 1, j-1 do
          text = text .. posttexts[k]
          if k == j - 2 then
             text = text .. ' und '
          else if k < j - 2 then
             text = text .. ', '          
             end
          end
        end
    else if type == 'BS2' then
       text = ""
       end
    end

-- Zusatz für Mischbetrieb
    if mixed_traffic then
       if underground then
          text = text .. ' mit Eisenbahn'
       else
          text = text .. ' mit U-Bahn'
       end
    end
-- Zusatz für Tunnel
    if tunnel then
        text = text .. ' im Tunnel'
    end

-- Füge Bedeutung des Präfix (ohne 'u'/'m') zum 'text' hinzu
    if prefixes[prefix] then
       text = text .. ' ' .. prefixes[prefix]
    end

-- Bekannte Fehler:
-- (Überwerfungsbauwerke "tSTR..[a/e]")
-- Ungenauigkeit "teilweise außer Betrieb"

    return text
end

--

return p