« Module:Infobox/Fonctions/Personne » : différence entre les versions
ajoute des qualificatifs entre parenthèses pour la ligne "Fonctions", on va dire que c'est moche, mais je ne vois pas trop comment on peut faire mieux pour l'instant |
p.fonction row -> table (plus de place) affiche le qualificatif diplôme de la formation |
||
| Ligne 6 : | Ligne 6 : | ||
-- libellés spéciaux lorsque ceux de Wikidata ne conviennent pas | -- libellés spéciaux lorsque ceux de Wikidata ne conviennent pas | ||
local occupations = mw.loadData "Module:Dictionnaire Wikidata/Métiers" | |||
local function setgender() -- établit la valeur de la variable "gender" qui sert à adapter la grammaire au sexe de la personne | local function setgender() -- établit la valeur de la variable "gender" qui sert à adapter la grammaire au sexe de la personne | ||
| Ligne 31 : | Ligne 31 : | ||
} | } | ||
-- ========== Fonctions d'aide ==================================== | |||
local function getdatetopic() -- obtient 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} | ||
| Ligne 54 : | Ligne 55 : | ||
local post = wikidata.formatStatement(statement, {showqualifiers = {'P642', 'P768', 'P708', 'P194', 'P102', 'P108'}}) | local post = wikidata.formatStatement(statement, {showqualifiers = {'P642', 'P768', 'P708', 'P194', 'P102', 'P108'}}) | ||
local period = wikidata.getFormattedDate(statement, {precision = 'year', linktopic = '-'}) | local period = wikidata.getFormattedDate(statement, {precision = 'year', linktopic = '-'}) | ||
local row = {type = 'row', label = period, value = function() return post end} | |||
table.insert(vals, row) | |||
end | end | ||
return | return vals | ||
end | end | ||
local function dateandplace(thedate, theplace) | local function dateandplace(thedate, theplace) | ||
| Ligne 213 : | Ligne 209 : | ||
-- parcours professionel | -- parcours professionel | ||
function p.education() -- à améliorer | function p.education() -- à améliorer | ||
local query = {sorttype= 'chronological', property = 'P69', showdate = true, conjtype = '<br />'} | local query = {sorttype= 'chronological', property = 'P69', showdate = true, showqualifiers = 'P512', conjtype = '<br />'} | ||
return { | return { | ||
type = 'row', | type = 'row', | ||
| Ligne 250 : | Ligne 246 : | ||
function p.officialposition() | function p.officialposition() | ||
local title = 'Fonctions' | |||
local singtitle = 'Fonctions' | |||
local rows | |||
if localdata['fonction'] then | |||
rows = {type = 'row', label = title, value = 'fonction'} | |||
else | |||
local statements = wikidata.getClaims{property = 'P39', entity = item, sorttype = 'chronological'} | |||
if not statements then | |||
return nil | |||
end | end | ||
if #statements == 1 then | |||
title = singtitle | |||
end | |||
} | rows = timeline(statements) | ||
end | |||
return | |||
{ | |||
type = 'table', | |||
title = title, | |||
rows = rows, | |||
} | |||
end | end | ||
Version du 26 juillet 2015 à 08:11
-- 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"
-- libellés spéciaux lorsque ceux de Wikidata ne conviennent pas
local occupations = mw.loadData "Module:Dictionnaire Wikidata/Métiers"
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 }
-- ========== Fonctions d'aide ==================================== 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()
local function timeline(statements) -- affiche date : événement (suppose les événements déjà triés) if not statements then return nil end local vals = {} for i, statement in pairs(statements) do local post = wikidata.formatStatement(statement, {showqualifiers = {'P642', 'P768', 'P708', 'P194', 'P102', 'P108'}}) local period = wikidata.getFormattedDate(statement, {precision = 'year', linktopic = '-'}) local row = {type = 'row', label = period, value = function() return post end} table.insert(vals, row) end return vals end
local function dateandplace(thedate, theplace)
if thedate and theplace then
return thedate .. '
' .. theplace
else
return thedate or theplace --retourne tout ce qu'il trouve
end
end
--Titre
function p.title(icon, style)
return general.title(icon, style)
end
--Image function p.mainimage() return general.mainimage('Article à illustrer/Biographie', 'Defaut 2.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 de pinceau', 'Noms de pinceau'}, }
local rows = {type = 'multi', rows = {}}
for i, j in pairs(names) do
local query = {property = j[1], showqualifiers = {'P1721'}, conjtype = ',
'}
table.insert(rows.rows, {type = 'row', wikidata = query, label = j[2], plurallabel = j[3]})
end
return rows
end
-- NAISSANCE ET MORT local function wikidatadate(prop) local val = wikidata.getClaims{entity = item, property = prop} if val and val[1].mainsnak.snaktype == 'value' and val[1].mainsnak.datavalue.value.precision < 8 then -- les dates précises au siècle près seulement ne marchent sont problématiques return nil end return wikidata.formatAndCat{entity = item, property = prop, vals = vals, 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 = 'row',
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 = 'row', 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 = 'row', label = 'Nationalité', plurallabel = 'Nationalités', 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) < 1700 then return nil end end -- local nation = require "Module:Country data".nationality local statements = wikidata.getClaims{entity = item, property = 'P27'} if not statements then return nil end return wikidata.formatAndCat{ property = 'P27', vals = statements, showdate = true, conjtype = 'comma', linktopic = '-', displayformat = function(snak) local val, success = nation(wikidata.getid(snak), 'f') if not success then val = wikidata.formatSnak(snak) end return val end }, #statements end } end
-- parcours professionel
function p.education() -- à améliorer
local query = {sorttype= 'chronological', property = 'P69', showdate = true, showqualifiers = 'P512', conjtype = '
'}
return {
type = 'row',
value = {'éducation', 'formation'},
wikidata = query,
label = 'Formation',
}
end
function p.occupation() local speciallabels if gender == 'f' then speciallabels = occupations.female elseif gender == 'm' then speciallabels = occupations.male end
return { type = 'row', value = 'activité', wikidata = {property = 'P106', showdate = true, conjtype = 'comma', speciallabels = speciallabels}, label = 'Activité', plurallabel = 'Activités' } end
function p.employer() return { type = 'row', value = 'employeur', wikidata = {property = 'P108', showdate = true}, label = 'Employeur', plurallabel = 'Employeurs' } end
function p.officialposition() local title = 'Fonctions' local singtitle = 'Fonctions'
local rows if localdata['fonction'] then rows = {type = 'row', label = title, value = 'fonction'} else local statements = wikidata.getClaims{property = 'P39', entity = item, sorttype = 'chronological'} if not statements then return nil end if #statements == 1 then title = singtitle end rows = timeline(statements) end return { type = 'table', title = title, rows = rows, }
end
function p.politicalparty()
return {
type = 'row',
value = 'parti politique',
label = 'Parti politique',
plurallabel = 'Partis politiques',
wikidata = { property = 'P102', sorttype= 'chronological', showdate = true, conjtype = '
'},
}
end
function p.awards() -- à améliorer
return {
type = 'row',
value = {'prix', 'récompenses', 'distinction', 'distinctions'},
wikidata = { property= 'P166', sorttype= 'chronological' , showdate= true, conjtype= '
'},
label = 'Distinction',
plurallabel = 'Distinctions',
}
end
-- Influences function p.influencedby() return { type = 'row', 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', wikidata = {property = 'P737'},
}
end
function p.influenced() return { type = 'row', label = 'A influencé', value = {'a influencé', 'influence de'}, wikidata = {property = 'P738'}, } end
-- Famille function p.family() return {type = 'multi', rows = { { type = 'row', label = 'Père', value = 'père', property = 'P22', }, { type = 'row', label = 'Mère', value = 'mère', property = 'P25', }, { type = 'row', label = 'Conjoint', -- à faire : le féminin plurallabel = 'Conjoints', value = 'conjoint', wikidata = {property = 'P26', sorttype = 'chronological', textformat = 'long', showdate = true, precision = 'year', linktopic = '-'} -- textformat = long sinon on se demande si c'est pas les dates de vie du conjoint }, { type = 'row', label = 'Enfant', plurallabel = 'Enfants', value = 'enfant', wikidata = {property = 'P40'} }, }} 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