Mòdul:Location/ca: diferència entre les revisions

Contingut suprimit Contingut afegit
copiat de ca.wiki
 
(Cap diferència)

Revisió de 17:32, 23 maig 2020

Aquest mòdul afegeix un referent entre parèntesis a l'etiqueta d'una localitat o unitat administrativa obtinguda de Wikidata. Per exemple: "Mataró (Maresme)" o "Berlín (Alemanya)". Utilitza com a suport Mòdul:Location/ca per la definició de criteris en català.

Vegeu la documentació a w:Mòdul:Location i els criteris usats a w:Mòdul:Location/ca.


local p = {}

p.referentFormat = 'brackets'

-- locations where any referent is redundant or innecessary
function p.namingExceptions(id)
	local exc_id = {
		['Q60'] = true, -- Nova York (Nova York)
		['Q61'] = true, -- Washington DC (EUA)
		['Q84'] = true, -- Londres (Anglaterra)
		['Q90'] = true, -- París (França)
		['Q220'] = true, -- Roma (Itàlia)
		['Q2807'] = true, -- Madrid (Espanya)
	}
	return exc_id[id]
end

---- Cases by state

-- Canada, Quebec
local function namingLocationCA(qid, label, c_date, main)
	local adm = main.fetchAdministrativeEntity(qid, 'ca')
	local adm_entity = main.getAdmByID(adm, 'Q11828004', label) -- província del Canadà
	if adm_entity and adm_entity == 'Quebec' and not string.find(label, adm_entity, 1, true) then -- no Ciutat de Quebec (Quebec)
		return main.addReferent(label, adm_entity, p.referentFormat)
	end
	return main.addReferent(label, 'Canadà', p.referentFormat)
end

-- Espanya, per comarca/illa/província/comunitat
local function namingLocationES(qid, label, c_date, main)
	local adm = main.fetchAdministrativeEntity(qid, 'ca')
	local community = main.getAdmByID(adm, 'Q10742', '') -- comunitat autònoma
	if community == 'Illes Balears' then
		return main.addReferent(label, main.getAdmByID(adm, 'Q23442', label) or 'Balears', p.referentFormat) -- illa
	elseif community == 'Catalunya' then
		if c_date < 1700 then
			return label
		end
		local comarca = main.getAdmByID(adm, 'Q937876', label) -- comarca de Catalunya
		if not comarca then
			comarca = main.getAdmByID(adm, 'Q19920968', label) -- entitat territorial singular
		end
		if comarca
			and (mw.ustring.find(comarca, mw.ustring.sub(label, 1, -2), 1, true) -- no Barcelona (Barcelonès), ...
			or mw.ustring.find(label, comarca, 1, true)) -- no Guardiola de Berguedà (Berguedà)
			then
				return label
		end
		return main.addReferent(label, comarca or community, p.referentFormat)
	elseif community == 'País Valencià' then
		if c_date < 1900 then
			return label
		end
		local comarca = main.getAdmByID(adm, 'Q766277', label) -- comarca del País Valencià
		if comarca
			and (mw.ustring.find(comarca, mw.ustring.sub(label, 1, -2), 1, true) -- no Alancat (Alacantí), ...
			or mw.ustring.find(label, comarca, 1, true))
			then
				return label
		end
		return main.addReferent(label, comarca or community, p.referentFormat)
	elseif community == 'Aragó' then
		if c_date > 1900 then
			local comarca = main.getReferencedEntity(qid, {
				['Q1425491'] = 'Ribagorça',
				['Q1479641'] = 'Llitera',
				['Q804160'] = 'Baix Cinca',
				['Q804156'] = 'Baix Aragó',
				['Q804155'] = 'Baix Aragó - Casp',
				['Q804156'] = 'Baix Aragó',
				['Q1544003'] = 'Matarranya'
				})
			if comarca then
				return main.addReferent(label, comarca, p.referentFormat)
			end
		end
	elseif community == 'Illes Canàries' then
		local adm_entity = main.getAdmByID(adm, 'Q23442', label) -- illa
		if adm_entity == nil and _date < 1800 then
			return main.addReferent(label, 'Canàries', p.referentFormat)
		end
		if adm_entity == nil or mw.ustring.find(label, adm_entity or '', 1, true) then -- no Santa Cruz de Tenerife (Tenerife)...
			adm_entity = main.getAdmByID(adm, 'Q162620', label) -- província d'Espanya
		end
		if adm_entity and mw.ustring.find(label, adm_entity, 1, true) then -- no Las Palmas de Gran Canaria (Las Palmas)
			adm_entity = nil
		end
		return main.addReferent(label, adm_entity or 'Canàries', p.referentFormat)
	elseif c_date < 1800 then
		return label
	end
	local province = main.getAdmByID(adm, 'Q162620', label) or community
	if mw.ustring.find(province or '', label, 1, true) then -- no Madrid (Comunidad de Madrid)...
		province = nil
	end
	return main.addReferent(label, province or 'Espanya', p.referentFormat)
end

-- EUA, per estat/territori
local function namingLocationUSA(qid, label, c_date, main)
	local adm = main.fetchAdministrativeEntity(qid, 'ca')
	local adm_entity = main.getAdmByID(adm, 'Q35657', label) -- estat dels Estats Units
	if adm_entity == nil then
		adm_entity = main.getAdmByID(adm, 'Q783733', label) -- territori no incorporat dels Estats Units
	end
	return main.addReferent(label, adm_entity or 'EUA', p.referentFormat)
end

-- França, per comarca/regió_històrica/ultramar
local function namingLocationFR(qid, label, c_date, main)
	local adm = main.fetchAdministrativeEntity(qid, 'ca')
	local adm_entity = main.getAdmByID(adm, 'Q6465', label) -- departament francès
	if adm_entity == 'Pirineus Orientals' and c_date > 1700 then
		local comarca = main.getReferencedEntity(qid, {
			['Q15475'] = 'Vallespir',
			['Q15476'] = 'Rosselló',
			['Q15477'] = 'Conflent',
			['Q15478'] = 'Capcir',
			['Q15479'] = 'Alta Cerdanya',
			['Q15481'] = 'Fenolleda'
		})
		if comarca and mw.ustring.find(label, comarca, 1, true) then -- no Cornellà de Conflent (Conflent)
			return label
		elseif comarca then
			return main.addReferent(label, comarca, p.referentFormat)
		else
			return main.addReferent(label, 'Catalunya del Nord', p.referentFormat)
		end
	end
	adm_entity = main.getAdmByID(adm, 'Q36784', label) -- regió de França
	if adm_entity == 'Guadalupe' or adm_entity == 'Martinica' or adm_entity == 'Guaiana Francesa'
		or adm_entity == 'Mayotte' or adm_entity == 'Illa de la Reunió' or adm_entity == 'Còrsega'
		or adm_entity == 'Bretanya' then
			return main.addReferent(label, adm_entity, p.referentFormat)
	end
	adm_entity = main.getAdmByID(adm, 'Q719487', label) -- col·lectivitat d'ultramar
	if not adm_entity then main.getAdmByID(adm, 'Q161243', label) end -- territori dependent
	if adm_entity then
		return main.addReferent(label, adm_entity, p.referentFormat)
	elseif c_date > 1700 then
		return main.addReferent(label, 'França', p.referentFormat)
	end
	return label
end

-- Itàlia, per illa
local function namingLocationIT(qid, label, c_date, main)
	local adm = main.fetchAdministrativeEntity(qid, 'ca')
	local region = main.getAdmByID(adm, 'Q1710033', label) -- Regió amb Estatut Especial
	if region == 'Sardenya' or region == 'Sicília' then
		return main.addReferent(label, region, p.referentFormat)
	end
	return main.addReferent(label, 'Itàlia', p.referentFormat)
end

-- Portugal, per regió autònoma
local function namingLocationPT(qid, label, c_date, main)
	local adm = main.fetchAdministrativeEntity(qid, 'ca')
	local adm_entity = main.getAdmByID(adm, 'Q2914565', label) -- regió autònoma de Portugal
	return main.addReferent(label, adm_entity or 'Portugal', p.referentFormat)
end

-- Regne Unit, per país/territori
local function namingLocationUK(qid, label, c_date, main)
	if c_date < 1000 then
		return label
	end
	local adm = main.fetchAdministrativeEntity(qid, 'ca')
	local adm_entity = main.getAdmByID(adm, 'Q3336843', label) -- país del Regne Unit
	if adm_entity == nil then
		if c_date < 1700 then
			return label
		else
			adm_entity = main.getAdmByID(adm, 'Q46395', label) -- territori britànic d'ultramar
		end
	end
	return main.addReferent(label, adm_entity or 'Regne Unit', p.referentFormat)
end

-- Xina, Tibet
local function namingLocationCN(qid, label, c_date, main)
	local adm = main.fetchAdministrativeEntity(qid, 'ca')
	local region = main.getAdmByID(adm, 'Q57362', label) -- regió autònoma de la República Popular de la Xina
	if region == 'Tibet' then
		return main.addReferent(label, region, p.referentFormat)
	end
	return main.addReferent(label, 'RP Xina', p.referentFormat)
end

function p.namingLocation(state_id, loc_id, loc_label, context_date, main)
	if state_id == 'Q16' then -- Canadà
		return namingLocationCA(loc_id, loc_label, context_date, main)
	elseif state_id == 'Q29' then -- Espanya
		return namingLocationES(loc_id, loc_label, context_date, main)
	elseif state_id == 'Q30' then -- EUA
		return namingLocationUSA(loc_id, loc_label, context_date, main)
	elseif state_id == 'Q38' then -- Itàlia
		return namingLocationIT(loc_id, loc_label, context_date, main)
	elseif state_id == 'Q45' then -- Portugal
		return namingLocationPT(loc_id, loc_label, context_date, main)
	elseif state_id == 'Q142' then -- França
		return namingLocationFR(loc_id, loc_label, context_date, main)
	elseif state_id == 'Q145' then -- Regne Unit
		return namingLocationUK(loc_id, loc_label, context_date, main)
	elseif state_id == 'Q148' then -- República Popular de la Xina
		return namingLocationCN(loc_id, loc_label, context_date, main)
	end
	return
end

return p