Modul:Vorlage:BS/Alt-Text

Die Dokumentation für dieses Modul kann unter Modul: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",
["KBHF"] = "Kopfbahnhof",
["ABHF"] = "Spitzkehrbahnhof",
["AKBHF"] = "Spitzkehrbahnhof",
["SBHF"] = "S-Bahnhof",
["S+BHF"] = "Bahnhof mit S-Bahn-Halt",
["KSBHF"] = "S-Kopfbahnhof",
["DST"] = "Dienststation / Betriebs- oder Güterbahnhof",
["KDST"] = "Betriebs-/Güterbahnhof",
["DSTeBHF"] = "Dienststelle, ehemals Bahnhof",
["HST"] = "Haltepunkt / Haltestelle",
["KHST"] = "Haltepunkt / Haltestelle",
["SHST"] = "S-Bahn-Halt",
["KSHST"] = "S-Bahn-Halt",
["HSTeBHF"] = "Haltepunkt / Haltestelle, ehemals Bahnhof",
["BHF+KHST"] = "Bahnhof, jetzt Haltepunkt", --nur mit Präfix 'ex' sinnvoll
["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",
["KRZWea"] = "Brücke über Wasserlauf",
["KRZWu"] = "Tunnel bzw. Unterführung unter Wasserlauf",
["TUNNEL1"] = "Tunnel",
["TUNNEL2"] = "Tunnel",
["KRZW"] = "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",
["ah"] = "Anfang Hochstrecke",
["eh"] = "Ende Hochstrecke",
["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",
["a@"] = "Tunnelanfang",
["e@"] = "Tunnelende",
["ah"] = "Anfang Hochstrecke",
["eh"] = "Ende Hochstrecke",
["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]
    
    local split1, split2 = mw.ustring.find(ID, 'h?%u*%+?%u+')
    if split1 == nil then return '' end -- no uppercase characters found
    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
    local postfix = nil
    local high = false
    if not text then
        main = mw.ustring.sub(ID, split1, split2)
        postfix = mw.ustring.sub(ID, split2 + 1)
        high = mw.ustring.sub(main, 1, 1) == 'h'
        if high then
           main = mw.ustring.sub(main, 2)
        end
        -- 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]
        -- Keinen Text erzeugen, wenn Hauptteil unbekannt
        if not text then
        	return ""
        end
	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
       if main == 'THST' then 
           text = text .. '-Strecke quer'
       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
    -- Sonderfall 'ht' (kann auch 'zwischen Tunneln' bedeuten)
    if tunnel then
       lastPrefix = mw.ustring.sub(prefix, mw.ustring.len(prefix))
       if lastPrefix == 'h' then
          tunnel = false
       end
    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 str == "a" or str == "e" then
              local next = mw.ustring.sub(postfix, i, i)
              if next == '@' then
                 str = str .. '@'
              else if high then
                      str = str .. 'h'
                 end
              end
           end
	       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 if main == 'BHF+KHST' then
						text = 'ehemaliger ' .. text
					else text = text .. ' (Strecke außer Betrieb)'
					end
				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 .. "|" .. text
end
--

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.