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

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
(local datelinks : cycliste)
(activation de Wikidata pour les nationalité, seulement si date de naissance > 1800 ajout de fonctions "autres noms" et "floruit")
Ligne 10 : Ligne 10 :
 
Q1281618 = 'en arts plastiques', -- sculpteur
 
Q1281618 = 'en arts plastiques', -- sculpteur
 
Q2309784 = 'en cyclisme', -- cycliste
 
Q2309784 = 'en cyclisme', -- cycliste
}  
+
}
  
 
local function getdatetopic(item) -- obtien le lien le plus approprié pour une date en fonction de la profession
 
local function getdatetopic(item) -- obtien le lien le plus approprié pour une date en fonction de la profession
Ligne 58 : Ligne 58 :
 
return  general.mainimage('Article à illustrer/Biographie', '240px')
 
return  general.mainimage('Article à illustrer/Biographie', '240px')
 
end
 
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
 +
if true then
 +
return rows
 +
end
 +
 +
local function getName(property) --fonctions différentes pour le nom
 +
if localdata['autres nomss'] then
 +
return nil
 +
end
 +
return wikidata.formatAndCat{entity = item, property = property, showqualifiers = {'P1721'}, conjtype = ',<br />'}
 +
end
 +
local function getLabel(property, plural)
 +
local claims = wikidata.getClaims
 +
end
 +
return {
 +
type = 'multi',
 +
rows = {
 +
 +
{type = 'row', label = 'Pseudonyme', wikidata = getName('P742')},
 +
{type = 'row', label = 'Prénom social', wikidata = getName('P1782')},
 +
{type = 'row', label = 'Nom d’artiste', wikidata = getName('P1787')},
 +
}
 +
}
 +
end
 +
  
 
--Naissance, décès  
 
--Naissance, décès  
Ligne 102 : Ligne 163 :
 
end
 
end
  
function p.nationality() --
+
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 {
 
return {
 
type = 'mixed',
 
type = 'mixed',
 
label = 'Nationalité',
 
label = 'Nationalité',
 
value = 'nationalité',
 
value = 'nationalité',
-- property = 'P27' que faire avec les données Wikidata Parfois, elle peuvent paraitre discutable du type Platon : "Athènes" ou "Goethe: Allemagne".
+
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'}
 +
local era, year = timestamp:match("(%W)(%d+)%-(%d+)%-(%d+)")
 +
if (not year) or tonumber(year) < 1800 then
 +
return nil
 +
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))
 +
if not success then
 +
val = wikidata.formatSnak(snak)
 +
end
 +
return val
 +
end
 +
}
 +
end
 
}
 
}
 
end
 
end

Version du 31 mai 2015 à 18:03

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 gender -- set by 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
}

local function getdatetopic(item) -- obtien le lien le plus approprié pour une date en fonction de la profession
	local val = wikidata._formatStatements{displayformat = 'raw', item = item, property = 'P106', numval = 1}
	return datelinks[val]
end

-- ========== 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


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

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

--Image
function p.mainimage()
	return  general.mainimage('Article à illustrer/Biographie', '240px')
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
	if true then
		return rows
	end

	local function getName(property) --fonctions différentes pour le nom 
		if localdata['autres nomss'] then
			return nil
		end
		return wikidata.formatAndCat{entity = item, property = property, showqualifiers = {'P1721'}, conjtype = ',<br />'}
	end
	local function getLabel(property, plural)
		local claims = wikidata.getClaims	
	end
	return {
		type = 'multi',
		rows = {
			
			{type = 'row', label = 'Pseudonyme', wikidata = getName('P742')},
			{type = 'row', label = 'Prénom social', wikidata = getName('P1782')},
			{type = 'row', label = 'Nom d’artiste', wikidata = getName('P1787')},
		}
	}
end


--Naissance, décès 
function p.birth() -- date de naissance en première ligne, lieu de naissance en deuxième
	return {
		type = 'mixed',
		label = 'Naissance',
		value =
			function(localdata, item)
					local thedate = localdata['date de naissance'] or localdata['naissance'] 
					local theplace = localdata['lieu de naissance']
					if not thedate then
						local link = getdatetopic(item)
						thedate = wikidata._formatAndCat({item = item, property= 'P569', rank = 'best', conjtype= ' ou ', linktopic = link})
						if not theplace then
							-- mis ici  pour ne pas récupérer le lieu Wikidata si la date ne vient pas de Wikidata (risque de collision)
							theplace =  wikidata._formatAndCat({item = item, property= 'P19', rank = 'best', conjtype= ' ou '})
						end
					end
					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(localdata, item)
					local thedate = localdata['date de décès'] or localdata['décès']
					local theplace = localdata['lieu de décès']
					if not thedate then
						local link = getdatetopic(item)
						thedate = wikidata._formatAndCat{item= item, property= 'P570', rank = 'best', conjtype= ' ou ', linktopic = link}
						if not theplace then
							-- mis ici  pour ne pas récupérer le lieu Wikidata si la date ne vient pas de Wikidata (risque de collision)
							theplace =  wikidata._formatAndCat({item = item, property= 'P20', rank = 'best', conjtype= ' ou '})
						end
					end
					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'}
				local era, year = timestamp:match("(%W)(%d+)%-(%d+)%-(%d+)")
				if (not year) or tonumber(year) < 1800 then
					return nil
				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))
						if not success then
							val = wikidata.formatSnak(snak)
						end
						return val
					end
				}
			end
	}
end

-- parcours professionel
function p.education() -- à améliorer
	return {
		type = 'mixed',
		label = 'Formation',
		value = function(localdata) return locadata['éducation'] or localdata['formation'] end,
		wikidata = function(item) return wikidata._formatAndCat{item=item, property = 'P69', showdate = true, conjtype = '<br />'} end
	}
end

function p.awards() -- à améliorer
	return {
		type = 'mixed',
		label = 'Distinctions',
		value = function(localdata) return localdata['prix'] or localdata['récompenses'] or localdata['distinctions'] end,
		wikidata = function(item) return wikidata._formatAndCat{item = item, property= 'P166', sorttype= 'chronological' , showdate= true, conjtype= '<br />'} end,
	}
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