Modul:Benutzer:Wickie37/Vorlage:BS/Alt-Text

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

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

local p = {} 

-- Generelle Objekttypen
local types = 
{
["STR"] = "Strecke",
["STRa"] = "Tunnelanfang",
["STRe"] = "Tunnelende",
["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",
["WECHSEL"] = "Übergang EBO zu BOStrab",
["uWECHSEL"] = "Übergang BOStrab zu EBO"
}

--'Postfixe für 'STR', 'ABZ', 'BS2'
local postfixes_STR_ABZ = 
{
["q"] = "quer",
["xq"] = "ehemals 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",
["xg"] = "ehemals geradeaus",
["a"] = "Tunnelanfang",
["+e"] = "Tunnelende",
["2"] = "nach halblinks",
["3"] = "nach halbrechts",
["+1"] = "von halblinks",
["+4"] = "von halbrechts",
["x2"] = "ehemals nach halblinks",
["x3"] = "ehemals nach halbrechts",
["+x1"] = "ehemals von halblinks",
["+x4"] = "ehemals von halbrechts",
}

-- Postfixe für andere Elemente (Bahnhöfe, Kreuzungen etc.)
local postfixes_BHF_KRZ = 
{
["q"] = "quer",
["l"] = "links",
["r"] = "rechts",
["a"] = "Streckenanfang",
["e"] = "Streckenende",
["xa"] = "Strecke bis hier außer Betrieb",
["xe"] = "Strecke ab hier außer Betrieb",
["t"] = "mit Tunnelstrecke",
["o"] = "geradeaus oben",
["u"] = "geradeaus unten",
["xo"] = "geradeaus oben (Querstrecke außer Betrieb)",
["xu"] = "geradeaus unten (Querstrecke außer Betrieb)",
}

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

-- 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
        -- "STRc*" ignorieren
        if main == 'STR' and mw.ustring.sub(postfix, 1, 1) == 'c' then
        	return ""
        end
	    -- Hole Hauptteil
    	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)
        if main == 'WECHSEL' then
       		text = types['uWECHSEL']
        else text = "U-Bahn-" .. text
       	end
    end
-- Mischbetrieb? (Präfix 'm')
    local lastPrefix = mw.ustring.sub(prefix, mw.ustring.len(prefix))
    local mixed_traffic = lastPrefix  == 'm'
    if mixed_traffic then
       if underground then
           text = text .. ' mit Eisenbahn'
       else
           text = text .. ' mit U-Bahn'
       end
    end   
-- 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'
   -- für Präfixe 'x' und 'e' bei ABZweigungen ermitteln welche Teile außer Betrieb sind
    if postfix and (main == 'ABZ' or main == 'STR') then
    	if prefixX then
    		local matches = 0
    		postfix, matches = mw.ustring.gsub(postfix, '[gq]', 'x%0', 1)
    		if matches == 0 then
    			if mw.ustring.match(postfix, '%d') then
		   			postfix = mw.ustring.gsub(postfix, '(%+?)(.)', '%1x%2', 1)
	    		else postfix = mw.ustring.gsub(postfix, '[lr]%+?', '%0x', 1)
	    		end
	    	end
	   	else if prefixE then
		   		if mw.ustring.match(postfix, '^[gq]') then
		   			postfix = mw.ustring.gsub(postfix, '(.%+?)([lr%d])', '%1x%2')
		    		postfix = mw.ustring.gsub(postfix, 'lr', 'lxr', 1)
		    	else if not mw.ustring.match(postfix, '%d') then
		   				postfix = mw.ustring.gsub(postfix, '(%+?)(.)', '%1x%2', 1)
		   			end
		   		end
	   		end
   		end
   	end
	    
if postfix then
	-- Wandel die Postfixe in lesbaren Text
	    local posttexts = {}
	    local postfixes = nil
	    if main == 'STR' or main == 'ABZ' or main == 'BS2' then
	    	postfixes = postfixes_STR_ABZ
	    else postfixes = postfixes_BHF_KRZ
	    end
	    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
	    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 == 'TBHF' or main == 'THST' or main == 'TSBHF' or main == 'TSHST' then
				text = 'ehemaliger ' .. text .. ' (Strecke geradeaus außer Betrieb)'
			else if main == 'KRZ' then
					text = text .. ' (Strecken außer Betrieb)'
				else text = text .. ' (Strecke außer Betrieb)'
				end
			end
		end
	else if prefixE and main ~= 'ABZ' and main ~= 'STR' then
			if main == 'KRZ' then
				text = text .. ' (Querstrecke außer Betrieb)'
			else if main == 'BS2' then
				text = text .. ' (Strecke außer Betrieb)'
				else if main == 'ÜST' or main == 'BST' or main == 'KBST' or main == 'GRENZE' then
					text = 'ehemalige ' .. text
					else text = 'ehemaliger ' .. text
					end
				end
			end
		else if prefixX and main ~= 'BS2' and main ~= 'ABZ' and main ~= 'STR' then
				if main == 'KRZ' or main == 'TBHF' or main == 'THST' or main == 'TSBHF' or main == 'TSHST' then
					text = text .. ' (Strecke geradeaus außer Betrieb)'
				else if main == 'TRAJEKT' then
						text = text .. ' (Bahntransport eingestellt)'
					else text = text .. ' (Strecke außer Betrieb)'
					end
				end
			end
		end
	end
-- Zusatz für Tunnel; nicht bei Tunnelanfang oder -ende
    if tunnel and not mw.ustring.match(text, 'Tunnel[ae]') then
    	if text == 'Kreuzung' then --Klarstellung für 'tKRZ'
    		text = text .. ' mit oberirdischer Strecke'
    	end
        text = text .. ' (im Tunnel)'
    end  
    
    return text
end
--

return p