Module:User:Goldzahn/test

From Wikipedia

Documentation for this module may be created at Module:User:Goldzahn/test/doc

local p = {}
  function p.personendaten(frame) -- Eine ganze Tabelle als Argument
	birthplace = {}  
    entity = mw.wikibase.getEntityObject() -- Q22, Kitten
    if entity ~= nil then 
    	birthday = entity.claims["P18"][1].mainsnak.datavalue.value.time -- Ausgabe: +00000002013-03-01T00:00:00Z
		precision =entity.claims["P18"][1].mainsnak.datavalue.value.precision 
		-- precision 11: taggenau, 10: monatgenau, 9: jahrgenau 8: jahrzehntgenau, 7:Jahrhundertgenau 
		-- "-00000000095-00-00T00:00:00Z" precision 7: --> 1. century BCE
		birthplace_id = "Q"..tostring(entity.claims["P342"][1].mainsnak.datavalue.value["numeric-id"]) -- Ausgabe Q344
		birthplace = mw.wikibase.label( birthplace_id ) -- Berlin
    else
    	if frame.args[2] == "Test" then 
    		birthday = frame.args[3] 
    		precision=frame.args[4] 
    		birthplace=frame.args[5] 
    		end
   	end
   	
   	
    --birthday = "-00000002013-03-09T00:00:00Z"
    deathday = "2014"  -- entity.claims["P25"][1].mainsnak.datavalue.value.time
    month = {"January", "February", "March", "May", "June", "July", "August", "September", "October", "November", "December"}
    comand = {";", "*", "†", "in", false}

	function fun1 (input_WP, sign, d_WD, m_WD, y_WD)
		status = " "
		local d_diff = false
    	local m_diff = false
    	local y_diff = false
    	local sign_diff = false
    	
    	i1, j1 = string.find(input_WP, "(%d+)") -- suche nach dem 1. Tag
    	i2, j2 = string.find(input_WP, "(%a+)") -- suche nach dem 1. Monat
    	i4, j4 = string.find(input_WP, "v. Chr.") -- suche nach BC oder AC 
		
		if i2 == i4 then
			status= status.."KeinErsterTag " 
			status= status.."KeinErsterMonat " 
			i3, j3 = string.find(input_WP, "(%d+)")  -- suche nach dem 1. Jahr
			if string.sub(input_WP, i3, j3) ~= y_WD then y_diff = true end
		else	
   			if i1 > i2 then 
    			status= status.."KeinErsterTag " 
    			i3, j3 = string.find(input_WP, "(%d+)")  -- suche nach dem 1. Jahr
    			if string.sub(input_WP, i2, j2) ~= month[tonumber(m_WD)] then m_diff = true end
    			if string.sub(input_WP, i3, j3) ~= y_WD then y_diff = true end
    		else 
				status= status.."EinErsterTag " 
				i3, j3 = string.find(input_WP, "(%d+)",j2) -- suche nach dem 1. Jahr
				if string.sub(input_WP, i1, j1) ~= d_WD then d_diff = true end
				if string.sub(input_WP, i2, j2) ~= month[tonumber(m_WD)] then m_diff = true end
    			if string.sub(input_WP, i3, j3) ~= y_WD then y_diff = true end
		 	end
		end
		
	    if i4 == nil and sign == "-" then sign_diff = true end
	    if i4 ~= nil and sign == "+" then sign_diff = true end
	    
		if d_diff or m_diff or y_diff or sign_diff then diff = true else diff = false end	
		return diff
	end

	a = {}
	table.insert(a, 1, frame.args[1])
	g1, h1 = string.find(a[1], comand[1]) -- suche nach ;
    if g1 ~= nil then
    	a[2] = string.sub(a[1], h1+1, string.len (a[1])) 
    	a[1] = string.sub(a[1], 1, g1-1) 
    else -- falls kein ;
    	a[2] = ""
    end
 
    g1, h1 = string.find(a[1], comand[2]) -- suche nach * im vorderen String
    if g1 ~= nil then
    	table.insert(a, 2, string.sub(a[1], h1+1, string.len (a[1]))) -- hinter dem *
    	a[1] = string.sub(a[1], 1, g1-1) 	 -- vor dem *
    else
    	table.insert(a, 2, "") -- wenn kein *
    end
    
    g1, h1 = string.find(a[3], comand[3])  -- suche nach † im hinteren String 
    if g1 ~= nil then
    	a[4] = string.sub(a[3], h1+1, string.len (a[3]))  -- hinter dem †
    	a[3] = string.sub(a[3], 1, g1-1) -- vor dem †
    else 
       	a[4] = ""-- wenn kein †
    end    

    g1, h1 = string.find(a[2], comand[4])  -- suche nach erstem "in"  
    if g1 ~= nil then
    	table.insert(a, 3, string.sub(a[2], h1+2, string.len (a[2]))) -- hinter dem erstem "in"
    	a[2] = string.sub(a[2], 1, g1-1) 	 -- vor dem "in"
    else 
    	table.insert(a, 3, "") -- wenn kein erstes "in"
    end

    g1, h1 = string.find(a[5], comand[4])  -- suche nach zweitem "in"  
    if g1 ~= nil then
    	table.insert(a, 6, string.sub(a[5], h1+2, string.len (a[5]))) -- hinter dem zweiten "in"
    	a[5] = string.sub(a[5], 1, g1-1) 	 -- vor dem zweiten "in"
    else 
    	table.insert(a, 6, "") -- wenn kein zweites "in"
    end

   -- aus Wikidata einlesen
   local _, _, sign, y_WD, m_WD, d_WD = string.find(birthday, "(%p)(%d+)-(%d+)-(%d+)") -- y = 00000002013, m = 03, d = 01 | capture mechanism
    y_WD = string.format("%d", y_WD)  -- y = 2013
    m_WD = string.format("%d", m_WD)  -- m = 3
    d_WD = string.format("%d", d_WD)  -- d = 1

	-- Suche nach Tag der Geburt
	
	if fun1(a[2], sign, d_WD, m_WD, y_WD) == true and precision == tostring(11) then a[2] = a[2].."diff" else a[2] = a[2].."" end
	 -- diff = " (<span id='d_WD' title='Bitte prüfe das Datum hier und auf Wikidata'>→Wikidata</span>)" 

	mt = {}
	mt["\\u00e4"] = "ä"; mt["\\u00f6"] = "ö"; mt["\\u00fc"] = "ü"; mt["\\u00df"] = "ß"; 
	mt["\\u00c4"] = "Ä"; mt["\\u00d6"] = "Ö"; mt["\\u00dc"] = "Ü"; 
	utf = ""
	--birthplace = "\\u00d6l\\u00e4b\\u00fc\\u00df" 
	local start = 0
	repeat
	i, j = string.find(birthplace, "\\u", start) -- nur ein Unicode-Zeichen? 
	if i~= nil then 
		utf = string.sub(birthplace, i, j+4)
		birthplace = string.gsub(birthplace, utf, mt[utf])
	end
	start=start+1
	until i == nil
	
	k = string.match(a[3], "%p%p(.+)]]") -- Alias-Name finden und mit "birthplace" vergleichen
 	g1, h1 = string.find(k, "|")
 	if g1 ~= nil then k = string.sub(k, h1+1, string.len(k)) end	
    if k == birthplace then a[3] = a[3].."" else a[3] = a[3].." diff" end

	-- Suche nach Todestag
	if fun1(a[5], sign, d_WD, m_WD, y_WD) == true and precision == tostring(11) then a[5] = a[5].."diff" else a[5] = a[5].."" end
   --s = string.gsub(input_WP, "(%d+)..(%s)in", first_y_WP.."]]"..diff.." in" ) 
 
  return a[1].."*"..a[2].."in"..a[3]..";"..a[4].."†"..a[5].."in"..a[6]..")" --.." "..birthday.." "..precision.." "..birthplace
end 
  	
return p