Module:Infobox/Fonctions/Personne : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
m (orthographe (pitié c’est la 2eme fois que je corrige cette erreur de conjugaison))
Ligne 31 : Ligne 31 :
 
local maleoccupations = {}
 
local maleoccupations = {}
 
local femaleoccupations = {  
 
local femaleoccupations = {  
Q33999 =  '[[acteur|actrice]]',-- les liens internes sont-il nécessaires ,
+
Q33999 =  '[[acteur|actrice]]',-- les liens internes sont-il nécessaires ?
 
Q177220 = '[[chanteur|chanteuse]]',
 
Q177220 = '[[chanteur|chanteuse]]',
 
Q639669 = '[[musicien|musicienne]]',
 
Q639669 = '[[musicien|musicienne]]',
Ligne 61 : Ligne 61 :
 
end
 
end
  
local function getdatetopic() -- obtien le lien le plus approprié pour une date en fonction de la profession
+
local function getdatetopic() -- obtient le lien le plus approprié pour une date en fonction de la profession
 
local claims = wikidata.getClaims{entity = item, property = 'P106', excludespecial = true}
 
local claims = wikidata.getClaims{entity = item, property = 'P106', excludespecial = true}
 
if not claims then
 
if not claims then

Version du 17 juillet 2015 à 19:06

La documentation pour ce module peut être créée à Module:Infobox/Fonctions/Personne/doc

-- Functions utilisées par les infobox personnes
local p = {}
local wikidata = require "Module:Wikidata"
local general = require "Module:Infobox/Fonctions"
local datemodule = require "Module:Date"

local function setgender() -- établit la valeur de la variable "gender" qui sert à adapter la grammaire au sexe de la personne
	local validvalues = {
		m = 'm',
		f = 'f',
		['féminin'] = 'f',
		['masculin'] = 'm',
		['Q6581072'] = 'f',
		['Q6581097'] = 'm',
	}
	local gender = localdata['sexe'] or localdata['genre'] or wikidata._formatStatements{item= item, property = 'P21', format = 'raw'}
	return validvalues[gender]
end

local gender = gender or setgender()

local datelinks = { -- lien vers le domaine d'activité approprié
	Q483501 = 'en arts plastiques', -- artiste
	Q1028181 = 'en arts plastiques', -- peintre
	Q1281618 = 'en arts plastiques', -- sculpteur
	Q2309784 = 'en cyclisme', -- cycliste
	Q16947657 = 'en arts plastiques', -- lithographe
}

 -- libellés spéciaux lorsque ceux de Wikidata ne conviennent pas
local maleoccupations = {}
local femaleoccupations = { 
	Q33999 =  '[[acteur|actrice]]',-- les liens internes sont-il nécessaires ?
	Q177220 = '[[chanteur|chanteuse]]',
	Q639669 = '[[musicien|musicienne]]',
	Q1650915 = '[[chercheur|chercheuse]]',
}

local function makerow(parameter, query, singlabel, plurallabel)
	query.entity = item
	local label = singlabel
	local val
	if type(parameter) == 'table' then
		for i, j in pairs(parameter) do if localdata[j] then val = j break end end
	elseif type(parameter) == 'string' then
		val = localdata[parameter]
	end
	if val then
		return {type = 'row', label = label, value = function() return val end}
	end
	local claims = wikidata.getClaims(query)
	if not claims then
		return nil
	end	
	if #claims > 1 then
		label = plurallabel or label
	end
	query.claims = claims
	local val = wikidata.formatAndCat(query)
	return {type = 'row', label = label, value = function() return val end}
end

local function getdatetopic() -- obtient le lien le plus approprié pour une date en fonction de la profession
	local claims = wikidata.getClaims{entity = item, property = 'P106', excludespecial = true}
	if not claims then
		return nil
	end
	for i, j in pairs(claims) do
		local v = wikidata.getRawvalue(j.mainsnak)
		if datelinks[v] then
			return datelinks[v]
		end
	end
end

local linktopic = getdatetopic()

-- ========== Fonctions d'aide ====================================

local function dateandplace(thedate, theplace)
	if thedate and theplace then
		return thedate .. '<br />' .. theplace
	else
		return thedate or theplace --retourne tout ce qu'il trouve
	end
end


--Titre
function p.title()
	return {
			type = 'title',
			value = 'nom',
	}
end

--Image
function p.mainimage()
	return  general.mainimage('Article à illustrer/Biographie', 'defaut.svg')
end

-- Noms
function p.othernames()
	
	-- si "autres noms" existe, le renvoie, sinon, fait plusieurs lignes en utilisant diverses propriétés ed Wikidata
	if localdata['autres noms'] or localdata['nom de naissance'] then
		return {type = 'multi', rows = {
			{type = 'row', label = 'Autres noms', value = 'autres noms'},
			{type = 'row', label ='Nom de naissance', value = 'nom de naissance'},
			}
		}
	end
	
	local names = {
		{'P1477', 'Nom de naissance', 'Noms de naissance',},
		{'P742', 'Peudonyme', 'Pseudonymes'},
		{'P1782', 'Prénom social', 'Prénoms sociaux'},
		{'P1787', 'Nom d’artiste', 'Noms d’artiste'},
	}
	local function getval(row)
		local property = row[1]
		local claims = wikidata.getClaims{entity = item, property = property}
		if claims and #claims > 1 then
			label = row[3]
		else
			label = row[2]
		end
		local val = wikidata.formatAndCat{entity = item, property = property, showqualifiers = {'P1721'}, conjtype = ',<br />'}
		return val, label
	end
	local rows = {type = 'multi', rows = {}}
	for i, j in pairs(names) do
		local val, label = getval(j)
		if val then
			table.insert(rows.rows, {type = 'row', label = label, wikidata = function() return val end})
		end
	end
	return rows
end

-- NAISSANCE ET MORT
local function wikidatadate(prop)
	return wikidata.formatAndCat{entity = item, property = prop, conjtype = ' ou ', linktopic = linktopic}
end

local birthdate = localdata['naissance'] or localdata['date de naissance'] or wikidatadate('P569') or ''
local deathdate = localdata['décès'] or localdata['date de décès'] or wikidatadate('P570') or ''


function p.birth() -- date de naissance en première ligne, lieu de naissance en deuxième
	return {
		type = 'mixed',
		label = 'Naissance',
		value =
			function()
			local thedate = datemodule.dateInfobox{args = {[1] = 'naissance', [2] = birthdate, [3] = deathdate, qualificatif = linktopic}}
			local theplace = localdata['lieu de naissance'] or wikidata._formatAndCat({item = item, property= 'P19', rank = 'best', conjtype= ' ou '})
			return dateandplace(thedate, theplace)
			end
	}
end

function p.death() -- même fonctionnement que la fonction p.birth
	return {
		type = 'mixed',
		label = 'Décès',
		value = 
			function()
			local thedate = datemodule.dateInfobox{args = {[1] = 'décès', [3] = birthdate, [2] = deathdate, qualificatif = linktopic}}
			local theplace = localdata['lieu de décès'] or wikidata._formatAndCat({item = item, property= 'P20', rank = 'best', conjtype= ' ou '})
			return dateandplace(thedate, theplace)
			end
	}
end

function p.floruit()
	return {
		type = 'row',
		label = 'Période d’activité' ,
		value = 'Période d\'activité',
		wikidata =
			function()
				local claims = wikidata.getClaims{entity = item, property = 'P1317', numval = 1}
				if not claims then
					return
				end
				local startpoint = wikidata.getFormattedQualifiers(claims[1], {'P580'})
				local endpoint = wikidata.getFormattedQualifiers(claims[1], {'P582'})
				return require "Module:Date complexe".daterange(startpoint, endpoint)
			end
	}
end

function p.nationality() -- Wikidata désactivé avant 1800 (problème de fiabilité des données
	return {
		type = 'mixed',
		label = 'Nationalité',
		value = 'nationalité',
		wikidata = 
			function()
				-- désactivé pour les personnes nées avant 1800, trop d'erreurs
				local timestamp = wikidata.formatStatements{entity = entity, property = 'P569', numval = 1, displayformat = 'raw'}
				if timestamp then 
					local era, year = timestamp:match("(%W)(%d+)%-(%d+)%-(%d+)")
					if (not year) or tonumber(year) < 1800 then
						return nil
					end
				end
				--
				local nation = require "Module:Country data".nationality
				return wikidata.formatAndCat{entity = item, property = 'P27', displayformat = 
					function(snak)
						local val, success = nation(wikidata.getid(snak), 'f')
						if not success then
							val = wikidata.formatSnak(snak)
						end
						return val
					end
				}
			end
	}
end

-- parcours professionel
function p.education() -- à améliorer
	local query = {sorttype= 'chronological', property = 'P69', showdate = true, conjtype = '<br />'}
	return makerow({'éducation', 'formation'}, query, 'Formation')
end

function p.occupation()
	local speciallabels
	if gender == 'f' then
		speciallabels = femaleoccupations
	elseif gender == 'm' then
		speciallabels = maleoccupations
	end
	local query = {property = 'P106', showdate = true, conjtype = 'comma', speciallabels = speciallabels}
	return makerow('activité', query, 'Activité','Activités')
end

function p.politicalparty()
	local query = { property = 'P102', sorttype= 'chronological', showdate = true, conjtype = '<br />'}
	return makerow('parti politique', query, 'Parti politique', 'Partis politiques')
end	

function p.awards() -- à améliorer
	query = { property= 'P166', sorttype= 'chronological' , showdate= true, conjtype= '<br />'}
	return makerow({'prix', 'récompenses', 'distinctions'}, query, 'Distinction', 'Distinctions')
end


-- Influences 
function p.influencedby()
	return {
		type = 'mixed',
		label = 
		function(localdata, item) 
		if not gender then setgender(localdata, item) end
		if gender == 'f' then
			return 'Influencée par'
		elseif gender == 'm' then
			return 'Influencé par'
		else
			return 'Influencé(e) par'
		end
		end,
		value = 'influencé par',
		property = 'P737',
    }
end

function p.influenced()
	return {
		type = 'mixed',
		label = 'A influencé',
		value = function(localdata) return localdata['a influencé'] or localdata['influence de'] end,
		property = 'P738',
}
end

-- Signature
function p.signature(default)
	return {
		type = 'images',
		imageparameters =  {'signature'},
		defaultimage = default,
		defaultsize = '150px',
		captionparameter = 'légende signature',
		defaultcaption = 'signature',
		property = 'P109',
		numval = 1
	}
end

--== Site web
function p.website()
	return p.website()
end

return p