Modul:Vorlage:BS/Alt-Text

Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 19. Mai 2024 um 13:51 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",
["hSTRae"] = "Brücke",
["STRo"] = "Brücke",
["BRÜCKE2"] = "Brücke",
["SBRÜCKE"] = "Strecke mit Straßenbrücke",
["hKRZWae"] = "Brücke über Wasserlauf",
["WBRÜCKE1"] = "Brücke über Wasserlauf",
["WBRÜCKE2"] = "Brücke über Wasserlauf",
["KRZWu"] = "Tunnel bzw. Unterführung unter Wasserlauf",
["TUNNEL1"] = "Tunnel",
["TUNNEL2"] = "Tunnel",
["BUE"] = "Bahnübergang",
["GRENZE"] = "Grenze",
["STR+GRZq"] = "Grenze",
["ZOLL"] = "Grenze",
["hZOLLae"] = "Grenze auf Brücke",
["TZOLLWo"] = "Grenze auf Brücke mit Wasserlauf",
["TRAJEKT"] = "Fährverbindung"
}

local prefixes = 
{
["x"] = "(Strecke [teilweise] außer Betrieb)",
["e"] = "(Einrichtung außer Betrieb / Strecke teilweise außer Betrieb)",
["ex"] = "(Strecke 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",
["L"] = "links",
["R"] = "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 = 
{
["tKRZW"] = "Tunnel unter Wasserlauf",
["tSTRa"] = "Tunnel Anfang",
["tSTR"] = "Tunnel",
["tSTRe"] = "Tunnel Ende",
["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, 2) == "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, 'h?%u*%+?%u+')
    local prefix = mw.ustring.sub(ID, 1, split1 - 1)
    local main = mw.ustring.sub(ID, split1)
    
    -- Hole Hauptteil (generelle Art des Objekts) aus 'types'
    text = types[main]
    -- Wenn nicht gefunden, Postfix abtrennen
    if not text then
        main = mw.ustring.sub(ID, split1, split2)
        local postfix = mw.ustring.sub(ID, split2 + 1)
        -- Workaround für Hauptteil "BS2"
        if main == 'BS' and mw.ustring.find(postfix, '%d+') == 1 then
    	    -- "BS2c*" ignorieren
    	    if mw.ustring.sub(postfix, 2, 2) == 'c' then
    		    return ""
    	    end
            main = main .. mw.ustring.sub(postfix, 1, 1)
            postfix = mw.ustring.sub(postfix, 2)
        end
	    -- Postfix-Anpassung für Spitzkehrbahnhof
	    if main == "ABHF" then
	    	postfix = mw.ustring.upper(mw.ustring.sub(postfix, 1, 1))
	    end
	    -- Hole Hauptteil (generelle Art des Objekts) aus 'types'
    	text = types[main] or ""
	end

-- U-Bahn? (Präfix 'u')
    local underground = mw.ustring.sub(prefix, 1, 1) == 'u'
    if underground then
       prefix = mw.ustring.sub(prefix, 2)
       text = "U-Bahn-" .. text
    end
-- Mischbetrieb? (Präfix 'm')
    local lastPrefix = mw.ustring.sub(prefix, mw.ustring.len(prefix))
    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, mw.ustring.len(prefix) - 1)
    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   	
    	
-- Wandel die Postfixes in lesbaren Text
    local posttexts = {}
    local i = 1
    local j = 1
    local count = mw.ustring.len(postfix)
    local plus = false
    while i <= count do       
       local str = ""
       if plus then
       	  str = "+"
       end
       repeat
          local c = mw.ustring.sub(postfix, i, i)
          str = str .. c
          i = i + 1
          if c == '+' then
          	  plus = true
          end
       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

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

-- Bekannte Fehler:
-- Postfixes bei Überwerfungsbauwerken (+/u/a/e)
-- Ungenauigkeit "teilweise außer Betrieb", insb. bei Abzw.
-- (e)x bei Turmbf

    return text
end

--

return p