Modul:Kommunfakta Färöarna WD

Från Wikipedia

Dokumentation [visa] [redigera] [historik] [rensa sidcachen]


local wikidata = require('Modul:Wikidata2').formatStatementsFromLua
local Ortsfaktarat = require('Modul:Ortsfakta').rat
local namnversalisering = require('Modul:Textformatering').namnversalisering

p = {}

function p.ort( entity, args )
	local ill_kat = ''
	local a = {}
	table.insert(a, "{{Geobox\n| Region")
	
	local namn = args['Kommunnamn_svenska'] or args['kommunnamn']
	if not namn or namn == '' then
		if entity.labels and entity.labels.sv then
			namn = entity.labels.sv.value
		else
			namn = mw.title.getCurrentTitle().text
		end
	end
	table.insert(a, "\n| name = " .. namn)
	if args['alternativnamn'] then
		table.insert(a, "\n| other_name = " .. args['alternativnamn'])
	else
		local fo = entity.labels.fo.value
		local da
		if entity.labels.da then
			da = entity.labels.da.value
		end
		if fo and da then
			fo = mw.getCurrentFrame():preprocess('{{Lang|fo|' .. fo .. '}}')
			da = mw.getCurrentFrame():preprocess('{{Lang|da|' .. da .. '}}')
			table.insert(a, "\n| other_name = " .. (fo .. '<br/>' .. da ))
		elseif fo then
			fo = mw.getCurrentFrame():preprocess('{{Lang|fo|' .. fo .. '}}')
			table.insert(a, "\n| other_name = " .. fo)
		elseif da then
			da = mw.getCurrentFrame():preprocess('{{Lang|da|' .. da .. '}}')
			table.insert(a, "\n| other_name = " .. da)
		end
	end
	
	local fd = false
	local v = wikidata({entity = entity, property = 'P31', avoidqualifier='P582', raw = 'true', noref = 'true'})
	if v[1].item == 'Q96948740' then
		fd = true
		table.insert(a, "\n| category = Tidigare [[Färöarnas kommuner|Kommun]]")
	else
		table.insert(a, "\n| category = [[Färöarnas kommuner|Kommun]]")
	end
	
			
	local bild = args.bild
	local bildtext = args.bildtext
	if not bild then
		local data = wikidata({entity = entity, property = 'P18', raw = 'true', noref='true', enbarten = 'true', langpref = 'sv'})
		if data and #data > 0 then
			bild = data[1].value
			bildtext = data[1].bildtext or data[1].motiv
		end
	end
	if bild and bild ~= '' then
		table.insert(a, "\n| image         = " .. (bild or ''))
		if bildtext then
			table.insert(a, "\n| image_caption = " .. (bildtext or ''))
		end
		if bildstorlek then
			table.insert(a, "\n| image_size    = " .. bildstorlek)
		end
	end

	local flagga = args.flagga
	if flagga and flagga ~= '' then
		table.insert(a, "\n| flag = " .. flagga)
		table.insert(a, "\n| flag_type = Kommunflagga" )
	elseif not flagga then
		local data = wikidata({entity = entity, property = 'P41', raw = 'true', noref='true', enbarten = 'true'})
		if data and #data > 0 then
			table.insert(a, "\n| flag = " .. data[1].value)
			local data2 = wikidata({entity = entity, property = 'P163', raw = 'true', noref='true', enbarten = 'true'})
			if data2 and #data2 > 0 then
				table.insert(a, "\n| flag_type = " .. data2[1].value)
			else
				table.insert(a, "\n| flag_type = Kommunflagga" )
			end
		end
	end
	
	local vapen = args.vapen or args.vapenbild
	if vapen and vapen ~= '' then
		table.insert(a, "\n| symbol      = " .. args.vapen or args.vapenbild)
		table.insert(a, "\n| symbol_type = Kommunvapen")
	elseif not vapen then
		local data = wikidata({entity = entity, property = 'P94', raw = 'true', noref='true', enbarten = 'true'})
		local data2 = wikidata({entity = entity, property = 'P237', raw = 'true', noref='true', enbarten = 'true'})
		if data and #data > 0 then
			table.insert(a, "\n| symbol = " .. data[1].value)
			if data2 and #data2 > 0 then
				table.insert(a, "\n| symbol_type = " .. data2[1].value)
			else
				table.insert(a, "\n| symbol_type = Kommunvapen")
			end
		end
	end

	table.insert(a, "\n| country       = Färöarna")
	table.insert(a, "\n| country_flag  = 1")

	if args['ö'] and args['ö'] ~= '' then
		table.insert(a, "\n| state       = " .. args['ö'])
		table.insert(a, "\n| state_type  = [[Ö (landområde)|Ö]]")
	elseif not args.fylke then 
		local data
		data = wikidata({entity = entity, property = "P706", noref='true'})
		if data and data ~= '' then
			table.insert(a, "\n| state       = " .. data )
			table.insert(a, "\n| state_type  = [[Ö (landområde)|Ö]]")
		end
	end
	if args.sysla and args.sysla ~= '' then
		table.insert(a, "\n| district       = " .. args.sysla)
		table.insert(a, "\n| district_type  = [[Färöarnas regioner|Region]]")
	elseif not args.sysla then 
		local data
		if fd then -- För fd kommuner är det intressant om den har bytt fylke under sin existens
			data = wikidata({entity = entity, property = "P131", noref='true', getonly='Q1000858', modifyqualifiertime = 'Y', conjunction = '<br/>', separator = '<br/>', withintervall = 'true'})
		else -- annars är det inte särskilt intressant
			data = wikidata({entity = entity, property = "P131", noref='true', getonly='Q1000858'})
		end
		if data and data ~= '' then
			table.insert(a, "\n| district       = " .. data )
			table.insert(a, "\n| district_type  = [[Färöarnas regioner|Sýsla]]")
		end
	end

	if args.slogan then
		table.insert(a, "\n| motto      = " .. args.slogan )
		table.insert(a, "\n| motto_type = [[Slogan]]" )
	else
		local data = wikidata({entity = entity, property = 'P6251', noref = 'noimport'})
		if data and data ~= '' then
			table.insert(a, "\n| motto      = " .. data )
			table.insert(a, "\n| motto_type = [[Slogan]]" )
		end
	end
	
	if args.koordinat then
		table.insert(a, "\n| location = " .. args.koordinat)
	end
	
	local elevation = args['höjdläge'] 
	if elevation then
		table.insert(a, "\n| elevation = " .. elevation)
	else
		local v = wikidata({entity=entity, property='P2044', enbarten = 'true', raw = 'true', convertunit='Q11573', noref='noimport'})
		if v and #v > 0 then
			v = v[1]
			if tonumber(v.amount) then
				table.insert(a, "\n| elevation = " .. math.abs( tonumber(v.amount)) )
				if tonumber(v.amount) < 0 then
					table.insert(a, "\n| elevation_unit = muh" )
				else
					table.insert(a, "\n| elevation_unit = möh" )
				end
				if v.ref and v.ref ~= '' then
					table.insert(a, "\n| elevation_note = " .. v.ref)
				end
			end
		end
	end

	local highest = args['högsta punkt namn'] 
	if highest then
		table.insert(a, "\n| highest = " .. highest )
		local highest_elevation = args['högsta punkt meter'] 
		if highest_elevation then
			table.insert(a, "\n| highest_elevation = " .. highest_elevation )
		end
	else
		local v = wikidata({entity=entity, property='P610', enbarten = 'true', raw = 'true'})
		if v and #v > 0 then
			table.insert(a, "\n| highest = " .. v[1].value .. v[1].ref)
			local v2 = wikidata({entityId=v[1].item, property='P2044', enbarten = 'true', raw = 'true', convertunit='Q11573', noref='noimport'})
			if v2 and #v2 > 0 then
				if tonumber(v2[1].amount) then
					table.insert(a, "\n| highest_elevation = " .. math.abs( tonumber(v2[1].amount)) )
					if tonumber(v2[1].amount) < 0 then
						table.insert(a, "\n| highest_elevation_unit = muh" )
					else
						table.insert(a, "\n| highest_elevation_unit = möh" )
					end
					table.insert(a, "\n| highest_elevation_note = " .. v2[1].ref)
				end
			end
			v2 = wikidata({entityId=v[1].item, property='P625', enbarten = 'true', raw = 'true', noref = 'true', nogeodataparser = 'true'})
			if v2 and #v2 > 0 then
				v2 = Ortsfaktarat(v2[1], 'sekund')
				table.insert(a, "\n| highest_lat_d   = " .. (v2.lat_g or ''))
				table.insert(a, "\n| highest_lat_m   = " .. (v2.lat_m or ''))
				table.insert(a, "\n| highest_lat_s   = " .. (v2.lat_s or ''))
				table.insert(a, "\n| highest_lat_NS  = " .. (v2.lat_NS or ''))
				table.insert(a, "\n| highest_long_d  = " .. (v2.long_g or ''))
				table.insert(a, "\n| highest_long_m  = " .. (v2.long_m or ''))
				table.insert(a, "\n| highest_long_s  = " .. (v2.long_s or ''))
				table.insert(a, "\n| highest_long_EW = " .. (v2.long_EW or ''))
				table.insert(a, "\n| highest_coordinates_type = region:FO_type:mountain")
			end
		end
	end

	local lowest = args['lägsta punkt namn'] 
	if lowest then
		table.insert(a, "\n| lowest = " .. lowest )
		local lowest_elevation = args['lägsta punkt meter'] 
		if lowest_elevation then
			table.insert(a, "\n| lowest_elevation = " .. lowest_elevation )
		end
	else
		local v = wikidata({entity=entity, property='P1589', enbarten = 'true', raw = 'true'})
		if v and #v > 0 then
			table.insert(a, "\n| lowest = " .. v[1].value .. v[1].ref)
			local v2 = wikidata({entityId=v[1].item, property='P2044', enbarten = 'true', raw = 'true', convertunit='Q11573', noref='noimport'})
			if v2 and #v2 > 0 then
				if tonumber(v2[1].amount) then
					table.insert(a, "\n| lowest_elevation = " .. math.abs( tonumber(v2[1].amount)) )
					if tonumber(v2[1].amount) < 0 then
						table.insert(a, "\n| lowest_elevation_unit = muh" )
					else
						table.insert(a, "\n| lowest_elevation_unit = möh" )
					end
					table.insert(a, "\n| lowest_elevation_note = " .. v2[1].ref)
				end
			end
			v2 = wikidata({entityId=v[1].item, property='P625', enbarten = 'true', raw = 'true', noref = 'true', nogeodataparser = 'true'})
			if v2 and #v2 > 0 then
				v2 = Ortsfaktarat(v2[1], 'sekund')
				table.insert(a, "\n| lowest_lat_d   = " .. (v2.lat_g or ''))
				table.insert(a, "\n| lowest_lat_m   = " .. (v2.lat_m or ''))
				table.insert(a, "\n| lowest_lat_s   = " .. (v2.lat_s or ''))
				table.insert(a, "\n| lowest_lat_NS  = " .. (v2.lat_NS or ''))
				table.insert(a, "\n| lowest_long_d  = " .. (v2.long_g or ''))
				table.insert(a, "\n| lowest_long_m  = " .. (v2.long_m or ''))
				table.insert(a, "\n| lowest_long_s  = " .. (v2.long_s or ''))
				table.insert(a, "\n| lowest_long_EW = " .. (v2.long_EW or ''))
				table.insert(a, "\n| lowest_coordinates_type = region:FO_type:landmark")
			end
		end
	
	end

	local nordligt = nil
	if args.lat_dec or args.lat_g then
		nordligt = tonumber(args.lat_dec or args.lat_g)
		table.insert(a, "\n| lat_d   = " .. (args.lat_dec or args.lat_g))
		table.insert(a, "\n| lat_m   = " .. (args.lat_m or ''))
		table.insert(a, "\n| lat_s   = " .. (args.lat_s or ''))
		table.insert(a, "\n| lat_NS  = " .. (args.lat_NS or ''))
		table.insert(a, "\n| long_d  = " .. (args.long_dec or args.long_g or ''))
		table.insert(a, "\n| long_m  = " .. (args.long_m or ''))
		table.insert(a, "\n| long_s  = " .. (args.long_s or ''))
		table.insert(a, "\n| long_EW = " .. (args.long_EW or ''))
		table.insert(a, "\n| coordinates_type = region:FO_type:adm2nd")
	elseif not args.koordinat then
		local v = wikidata({entity = entity, property = 'P625', raw = 'true', noref='true', enbarten = 'true', nogeodataparser = 'true'})
		if v and #v > 0 then
			v = Ortsfaktarat(v[1], 'minut')
			if v then
				nordligt = tonumber(v.lat_g)
				table.insert(a, "\n| lat_d   = " .. (v.lat_g or ''))
				table.insert(a, "\n| lat_m   = " .. (v.lat_m or ''))
				table.insert(a, "\n| lat_NS  = " .. (v.lat_NS or ''))
				table.insert(a, "\n| long_d  = " .. (v.long_g or ''))
				table.insert(a, "\n| long_m  = " .. (v.long_m or ''))
				table.insert(a, "\n| long_EW = " .. (v.long_EW or ''))
				table.insert(a, "\n| coordinates_type = region:FO_type:adm2nd")
			end
		end
	end
	
	if args['bildad'] then
		table.insert(a, "\n| established = " .. args['bildad'])
		if args['ersätter'] then
			table.insert(a, "\n| established1 = " .. args['ersätter'])
			table.insert(a, "\n| established1_type = Ersätter")
		end
	elseif not args['bildad'] then
		local v = wikidata({entity = entity, property = 'P571', conjunction = '<br/>', separator = '<br/>', som = 'true', modifytime='longdate', noref = 'noimport'})
		if v and v ~= '' then
			table.insert(a, "\n| established = " .. v)
			local v1 = wikidata({entity = entity, property = 'P1365', conjunction = '<br/>', separator = '<br/>', noref = 'noimport', withdate = 'true', modifyqualifiertime = 'Y'})
			local v2 = wikidata({entity = entity, property = 'P807', conjunction = '<br/>', separator = '<br/>', noref = 'noimport', withdate = 'true', modifyqualifiertime = 'Y'})
			if v1 and v1 ~= '' and v2 and v2 ~= '' then
				table.insert(a, "\n| established1 = " .. v2 .. '<br/>' .. v1)
				table.insert(a, "\n| established1_type = Utbruten ur/<br/>Ersätter")
			elseif v1 and v1 ~= '' then
				table.insert(a, "\n| established1 = " .. v1 )
				table.insert(a, "\n| established1_type = Ersätter")
			elseif v2 and v2 ~= '' then
				table.insert(a, "\n| established1 = " .. v2 )
				table.insert(a, "\n| established1_type = Utbruten ur")
			end
		end
	end
	if args['upphört'] then
		table.insert(a, "\n| abolished = " .. args['upphört'])
		table.insert(a, "\n| abolished_type = Upphört")
		if args['uppgått_i'] and args['uppgått_i'] ~= '' then
			table.insert(a, "\n| abolished1 = " .. args['uppgått_i'])
			table.insert(a, "\n| abolished1_type = Uppgått i")
		end
		if args['nuvarande kommun'] and args['nuvarande kommun'] ~= '' then
			table.insert(a, "\n| abolished2 = " .. args['nuvarande kommun'])
			table.insert(a, "\n| abolished2_type = Nuvarande kommun")
		end
	elseif not args['upphört'] then
		local v = wikidata({entity = entity, property = 'P576', modifytime='longdate', conjunction = '<br/>', separator = '<br/>', noref = 'noimport'})
		local v1 = wikidata({entity = entity, property = 'P1366', conjunction = '<br/>', separator = '<br/>', noref = 'noimport', withdate = 'true', modifyqualifiertime = 'Y'})
		local v2 = wikidata({entity = entity, property = 'P3842', conjunction = '<br/>', separator = '<br/>', noref = 'noimport', withdate = 'true', modifyqualifiertime = 'Y'})
		if v and v ~= '' then
			table.insert(a, "\n| abolished = " .. v)
			table.insert(a, "\n| abolished_type = Upphört")
			if v1 and v1 ~= '' then
				table.insert(a, "\n| abolished1 = " .. v1)
				table.insert(a, "\n| abolished1_type = Uppgått i")
			end
		elseif v1 and v1 ~= '' then
			table.insert(a, "\n| abolished = " .. v1)
			table.insert(a, "\n| abolished_type = Delats upp i")
		end
		if v2 and v2 ~= '' then
			table.insert(a, "\n| abolished2 = " .. v2)
			table.insert(a, "\n| abolished2_type = Nuvarande kommun")
		end
	end

	if not fd then
		table.insert(a, '\n| timezone     = [[Västeuropeisk tid|WET]] | utc_offset = +0 | timezone_type = [[Tidszon]]')
		table.insert(a, '\n| timezone_DST = [[Västeuropeisk sommartid|WEST]]| utc_offset_DST = +1')
	else
		if args['tidszon'] then
			table.insert(a, '\n| timezone     = ' .. args['tidszon'] )
		end
		if args['UTC skilln'] then
			table.insert(a, '\n| utc_offset = ' .. args['UTC skilln'] )
		end				
		if args['tidszon_DST'] then
			table.insert(a, '\n| timezone_DST = ' .. args['tidszon_DST'] )
		end
		if args['DST skilln'] then
			table.insert(a, '\n| utc_offset_DST = ' .. args['DST skilln'] )
		end
	end

	local ledare = false
	
	if args['borgmästare'] and args['borgmästare'] ~= '' then
		ledare = true
		table.insert(a, '\n| leader = ' .. args['borgmästare'])
		table.insert(a, '\n| leader_type = [[Borgmästare]]')
	elseif not args['borgmästare'] then
		local data = wikidata({entity = entity, property = 'P6', withintervall = 'yes', modifyqualifiertime = 'Y', noref = 'noimport', raw = 'true', cat = 'true'})
		if data and #data > 0 then
			ledare = true
			if data[1].tifr then
				table.insert(a, '\n| leader = ' .. data[1].value .. '<small> (' .. data[1].tifr .. ')</small>')
			else
				table.insert(a, '\n| leader = ' .. data[1].value )
			end
			if data[1].parti and data[1].parti ~= '' then
				table.insert(a, '\n| leader_party = ' .. data[1].parti)
			end
			table.insert(a, '\n| leader_type = [[Borgmästare]]')
			if data[1].ref then
				table.insert(a, '\n| leader_note = ' .. data[1].ref)
			end
		end
	end

	local y1 = false
	local y2 = false

	local area = args.yta
	if area and area ~= '' then
		table.insert(a, "\n| area = " .. area)
		if args['yta_datum'] then
			table.insert(a, "\n| area_date = " .. args['yta_datum'])
		end
		if args['yta_ref'] then
			table.insert(a, "\n| area_note = " .. args['yta_ref'])
		end
		if args['yta_land'] then
			table.insert(a, "\n| area_land = " .. args['yta_land'])
			y1 = true
			if args['yta_land_datum'] then
				table.insert(a, "\n| area_land_date = " .. args['yta_land_datum'])
			end
			if args['yta_land_ref'] then
				table.insert(a, "\n| area_land_note = " .. args['yta_land_ref'])
			end
		end		
		if args['yta_vatten'] then
			table.insert(a, "\n| area_water = " .. args['yta_vatten'])
			if args['yta_vatten_datum'] then
				table.insert(a, "\n| area_water_date = " .. args['yta_vatten_datum'])
			end
			if args['yta_land_ref'] then
				table.insert(a, "\n| area_water_note = " .. args['yta_vatten_ref'])
			end
		end		
	elseif not area then
		-- area total
		local v = wikidata({entity = entity, property = "P2046", sortbytime = 'chronological', enbarten = 'yes', raw = 'true', preferqualifier ='P518', rank = 'valid', preferqualifiervalue = 'Q16868672', modifyqualifiertime = 'Y', convertunit = 'Q712226', noref='noimport'})		
		if not v or #v == 0 then 
			-- area total, utan qualifier om ovan inte funkade
			v = wikidata({entity = entity, property = "P2046", sortbytime = 'chronological', enbarten = 'yes', raw = 'true', avoidqualifier='P518', rank = 'valid', modifyqualifiertime = 'Y', convertunit = 'Q712226', noref='noimport'})
		end
		if v and #v > 0 then
			y1 = true
			table.insert(a, "\n| area = " .. tonumber(plus(v[1].amount)))
			table.insert(a, "\n| area_decimals = 2")
			if v[1].datum and v[1].datum ~= '' then
				table.insert(a, "\n| area_date = " .. v[1].datum)
			end
			if v[1].ref then
				table.insert(a, "\n| area_note = " .. v[1].ref)
			end
		end
		local v2 = wikidata({entity = entity, property = "P2046", sortbytime = 'chronological', enbarten = 'yes', raw = 'true', preferqualifier ='P518', rank = 'valid', preferqualifiervalue = 'Q205895', modifyqualifiertime = 'Y', convertunit = 'Q712226', noref='true'})
		local v4 = wikidata({entity = entity, property = "P2046", sortbytime = 'chronological', enbarten = 'yes', raw = 'true', preferqualifier ='P518', rank = 'valid', preferqualifiervalue = 'Q23397', convertunit = 'Q712226', noref='true', modifyqualifiertime = 'Y'}) -- insjövatten
		local v5 = wikidata({entity = entity, property = "P2046", sortbytime = 'chronological', enbarten = 'yes', raw = 'true', preferqualifier ='P518', rank = 'valid', preferqualifiervalue = 'Q4022', convertunit = 'Q712226', noref='true', modifyqualifiertime = 'Y'}) -- floder
		if v2 and #v2 > 0 then
			local land = tonumber(plus(v2[1].amount))
			if v4 and #v4 > 0 then
				land = land - tonumber(plus(v4[1].amount))
			end
			if v5 and #v5 > 0 then
				land = land - tonumber(plus(v5[1].amount))
			end
			table.insert(a, "\n| area_land = " .. land )
			y1 = true
			table.insert(a, "\n| area_land_decimals = 2")
			if v2[1].datum and v2[1].datum ~= '' then
				table.insert(a, "\n| area_land_date = " .. v2[1].datum)
			end
		end
		local vatten = 0
		local v3 = wikidata({entity = entity, property = "P2046", sortbytime = 'chronological', enbarten = 'yes', raw = 'true', preferqualifier ='P518', rank = 'valid', preferqualifiervalue = 'Q213204', convertunit = 'Q712226', noref='true', modifyqualifiertime = 'Y'})
		if v3 and #v3 > 0 then
			vatten = vatten + tonumber(plus(v3[1].amount))
		end
		if v4 and #v4 > 0 then
			vatten = vatten + tonumber(plus(v4[1].amount))
		end
		if v5 and #v5 > 0 then
			vatten = vatten + tonumber(plus(v5[1].amount))
		end
		if vatten > 0 then
			table.insert(a, "\n| area_water = " .. vatten)
			table.insert(a, "\n| area_water_decimals = 2")
			if v3[1].datum and v4[1].datum and v5[1].datum and v3[1].datum == v4[1].datum and v3[1].datum == v5[1].datum then
				table.insert(a, "\n| area_water_date = " .. v3[1].datum)
			end
		end
	end
		
	local inv = args['folkmängd']
	if inv and inv ~= '' then
		table.insert(a, "\n| population = " .. inv)
		y2 = true
		if args.invdatum then
			table.insert(a, "\n| population_date = " .. args['folkmängd_datum'] )
		end
		if args.invref then
			table.insert(a, "\n| population_note = " .. args['folkmängd_ref'] )
		end
	elseif not inv then
		local v = wikidata({entity = entity, property='P1082', sortbytime = 'chronological', enbarten = 'yes', raw = 'true', avoidqualifier='P518', modifyqualifiertime = 'Y', noref='noimport'})
		if v and v[1] and v[1].amount then
			table.insert(a, "\n| population = " .. tonumber(plus(v[1].amount)))
			y2 = true
			if v[1].datum then
				table.insert(a, "\n| population_date = " .. v[1].datum)
			end
			if v[1].ref then
				table.insert(a, "\n| population_note = " .. v[1].ref)
			end
		end
		v = wikidata({entity = entity, property='P1540', sortbytime = 'chronological', enbarten = 'yes', raw = 'true', avoidqualifier='P518', modifyqualifiertime = 'Y', noref='noimport'})
		if v and v[1] and v[1].amount then
			table.insert(a, "\n| population1 = " .. tonumber(plus(v[1].amount)))
			if v[1].datum then
				table.insert(a, "\n| population1_date = " .. v[1].datum)
			end
			if v[1].ref then
				table.insert(a, "\n| population1_note = " .. v[1].ref)
			end
			table.insert(a, "\n| population1_type = män ")
		end
		v = wikidata({entity = entity, property='P1539', sortbytime = 'chronological', enbarten = 'yes', raw = 'true', avoidqualifier='P518', modifyqualifiertime = 'Y', noref='noimport'})
		if v and v[1] and v[1].amount then
			table.insert(a, "\n| population2 = " .. tonumber(plus(v[1].amount)))
			if v[1].datum then
				table.insert(a, "\n| population2_date = " .. v[1].datum)
			end
			if v[1].ref then
				table.insert(a, "\n| population2_note = " .. v[1].ref)
			end
			table.insert(a, "\n| population2_type = kvinnor ")
		end		
	end
	
	if y1 and y2 then
		table.insert(a, "\n| population_density = auto")
	end

	local residensstad = args.residensstad or args.centralort
	if residensstad and residensstad ~= '' then
		table.insert(a, "\n| capital = " .. residensstad)
		table.insert(a, "\n| capital_type = [[Centralort]]")
	elseif not residensstad then
		local v = wikidata({entity = entity, property='P36', noref='true'})
		if v and v ~= '' then
			table.insert(a, "\n| capital = " .. v)
			table.insert(a, "\n| capital_type = [[Centralort]]")
		end
	end

	if args.geonames then
		table.insert(a, '\n| geonames = ' .. args.geonames)
	end

	if args.karta and args.karta ~= '' then
		table.insert(a, '\n| map           = ' .. (args.karta or ''))
		table.insert(a, '\n| map_caption   = ' .. (args.karttext or 'Översiktskarta'))
	elseif not args.karta then
		data = wikidata({entity = entity, property = 'P1943', raw = 'true', noref='true', enbarten = 'true'})
		if not data or #data == 0 then
			data = wikidata({entity = entity, property = 'P242', raw = 'true', noref='true', enbarten = 'true'})
		end
		if data and #data > 0 then 
			table.insert(a, '\n| map   = ' .. data[1].value)
			local mapcaption = 'Översiktskarta'
			if string.find(data[1].value, 'Hordaland') then
				mapcaption = namn .. ' i [[Hordaland fylke]]'
			end
			table.insert(a, '\n| map_caption   = ' .. mapcaption)
		end
	end	

	local kmlfaktaruta = require('Modul:KML faktaruta').main
	local k = kmlfaktaruta(entity)
	if k then
		table.insert(a, '\n| KML                   = ' .. k)
	end
	
	if args.fotnot and args.fotnot ~= '' then
		table.insert(a, '\n| footnotes         = ' .. args.fotnot ..  '<br />[[d:'.. entity.id .. '|Redigera Wikidata]]')
	else
		table.insert(a, '\n| footnotes         = [[d:'.. entity.id .. '|Redigera Wikidata]]')
	end

	if args.commons then
		table.insert(a, '\n| commons               = ' .. args.commons)
	else
		table.insert(a, '\n| commons               = ' .. Comcat(entity))
	end
	
	if args.hemsida and args.hemsida ~= '' then
		table.insert(a, '\n| website = ' .. args.hemsida)
	elseif not args.hemsida and not fd then
		local v = wikidata({entity = entity, property = "P856", enbarten = 'yes', noref='true'})
		if v and v ~= '' then
			table.insert(a, '\n| website = ' .. v)
		end
	end
	table.insert(a, '\n}}')
	return mw.getCurrentFrame():preprocess(table.concat(a))
end		


function indexera(v, i)
	if v and #v >= i then
		return v[i].value
	end
	return ''
end

function kommunqids(v)
	local s = {}
	for i, j in pairs(v) do
		table.insert(s, v.item)
	end
	return s
end



function positionskartnamn(frame) -- kartbild för länet som objektet tillhör. används av till exempel mallen "Ortsfakta Sverige WD"
   return mw.getCurrentFrame():preprocess('{{Kartposition Sverige '..lankod2lan(lankod(frame))..'|bild}}')
end 

function positionskarta(frame) -- kartlokalisering (Geolocator) för länet som objektet tillhör. används av till exempel mallen "Ortsfakta Sverige WD"
	return lankod2lan(lankod(frame))
end

function harva(entity, first, second, limit)
	local s = {}
	local l = wikidata({entity = entity, property = "P131", noref='true', avoidqualifier='P582', getonly=second, raw = 'true', getsimpleproperty = '15px', getproperty = 'P94', getenbarten = 'true'})
	if l and #l > limit then 
		return {}
	end
	if l and #l > 0 then
		return l
	else 
		l = wikidata({entity = entity, property = "P131", noref='true', avoidqualifier='P582', getonly=first, raw = 'true', getsimpleproperty = '15px', getproperty = 'P94', getenbarten = 'true'})
		if l and #l > limit then 
			return {}
		end
		local b = {}
		if l then
			for i3, j3 in pairs(l) do
				l2 = wikidata({entityId = j3.item, property = "P131", noref='true', avoidqualifier='P582', getonly=second, raw = 'true', getsimpleproperty = '15px', getproperty = 'P94', getenbarten = 'true'})
				for i, j in pairs(l2) do
					local f = false
					for i2, j2 in pairs(b) do
						if j.item == j2.item then
							f = true
						end
					end
					if not f then
						table.insert(b, j)
					end
				end
			end
		end
		if #b > limit then 
			return {}
		else
			return b
		end
	end
	return {}
end

function harva2(entity, first, second, limit)
	local s = {}
	local l = wikidata({entity = entity, property = "P131", noref='true', getonly=second, raw = 'true', getsimpleproperty = '15px', getproperty = 'P94', getenbarten = 'true'})
	if l and #l > limit then 
		return {}
	end
	if l and #l > 0 then
		return l
	else 
		l = wikidata({entity = entity, property = "P131", noref='true', getonly=first, raw = 'true', getsimpleproperty = '15px', getproperty = 'P94', getenbarten = 'true'})
		if l and #l > limit then 
			return {}
		end
		local b = {}
		if l then
			for i3, j3 in pairs(l) do
				l2 = wikidata({entityId = j3.item, property = "P131", noref='true', getonly=second, raw = 'true', getsimpleproperty = '15px', getproperty = 'P94', getenbarten = 'true'})
				for i, j in pairs(l2) do
					local f = false
					for i2, j2 in pairs(b) do
						if j.item == j2.item then
							f = true
						end
					end
					if not f then
						table.insert(b, j)
					end
				end
			end
		end
		if #b > limit then 
			return {}
		else
			return b
		end
	end
	return {}
end

function Comcat(entity)
	if not entity or not entity.claims or not entity.claims.P373 then
		return ''
	else
		if entity.claims.P373[1].mainsnak.snaktype ~= 'value' then
			return ''
		else
			return entity.claims.P373[1].mainsnak.datavalue.value
		end
	end
end

function plus(a)
	if string.sub(a, 1, 1) == '+' then
		return string.sub(a, 2)
	end
	return a
end

return p