Zum Inhalt springen

Modul:Vorlage:BS/Alt-Text

aus Wikipedia, der freien Enzyklopädie

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",
["tKRZW"] = "Strecke unter Wasserlauf",
["BUE"] = "Bahnübergang",
["GRENZE"] = "Grenze",
["STR+GRZq"] = "Grenze",
["ZOLL"] = "Grenze",
["hZOLLae"] = "Grenze auf Brücke",
["TZOLLWo"] = "Grenze auf Brücke über Wasserlauf",
["hSTRae+GRZq"] = "Grenze auf Brücke",
["hKRZWae+GRZq"] = "Grenze auf Brücke über Wasserlauf",
["TRAJEKT"] = "Eisenbahnfähre"
}

local prefixes = 
{
["x"] = "(Strecke [teilweise] außer Betrieb)",
["e"] = "(Einrichtung außer Betrieb / Strecke teilweise außer Betrieb)",
["ex"] = "(Strecke außer Betrieb)"
}

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 = 
{
["tSTRa"] = "Tunnel Anfang",
["tSTRe"] = "Tunnel Ende",
["WECHSEL"] = "Übergang EBO zu BOStrab",
["uWECHSEL"] = "Übergang BOStrab zu EBO",
["uexWECHSEL"] = "Übergang BOStrab zu EBO (Strecke außer Betrieb)"
}


-- 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 .. ' (Strecke außer Betrieb)'
        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]
    local postfix = nil
    -- Wenn nicht gefunden, Postfix abtrennen
    if not text then
        main = mw.ustring.sub(ID, split1, split2)
        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
-- Präfixe 'e', 'x', 'ex'
   local prefixE = prefix == 'e'
   local prefixX = prefix == 'x'
   local prefixEX = prefix == 'ex'
    
-- Zusatz für Mischbetrieb
    if mixed_traffic then
       if underground then
           text = text .. ' mit Eisenbahn'
       else
           text = text .. ' mit U-Bahn'
       end
    end    

if postfix then
	-- 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
	end

-- Füge Bedeutung des Präfix (ohne 'u'/'m') zum 'text' hinzu
	if prefixEX then
		if main == 'STR' or main == 'ENDE' then
			text = text .. ' (außer Betrieb)'
		else if main == 'KRZ' then
				text = text .. ' (Strecken außer Betrieb)'
			else text = text .. ' (Strecke außer Betrieb)'
			end
		end
	else if prefixE then
			if main == 'KRZ' then
				text = text .. ' (Querstrecke außer Betrieb)'
			else if main == 'STR' or main == 'ABZ' then
				text = text .. ' (teilweise außer Betrieb)'
				else if main == 'BS2' then
					text = text .. ' (Strecke außer Betrieb)'
					else if main == 'ÜST' or main == 'BST' or main == 'KBST' then
						text = 'ehemalige ' .. text
						else text = 'ehemaliger ' .. text
						end
					end
				end
			end
		else if prefixX and not main == 'BS2' then
				if main == 'KRZ' or main == 'TBHF' or main == 'THST' then
					text = text .. ' (Strecke geradeaus außer Betrieb)'
				else if main == 'TRAJEKT' then
						text = text .. ' (Bahntransport eingestellt)'
					else if main == 'STR' or main == 'ABZ' then
							text = text .. ' (teilweise außer Betrieb)'
						else text = text .. ' (Strecke außer Betrieb)'
						end
					end
				end
			end
		end
	end
			
    if prefixes[prefix] then
       text = text .. ' ' .. prefixes[prefix]
    end
    
-- Zusatz für Tunnel
    if tunnel then
        text = text .. ' (im Tunnel)'
    end  

-- Bekannte Fehler:
-- Postfixes bei Überwerfungsbauwerken (+/u/a/e)
-- Ungenauigkeit "teilweise außer Betrieb"

    return text
end

--

return p