Módulo:Infobox/Funções/Pessoa

Origem: Wikiquote, a coletânea de citações livre.

A documentação para este módulo pode ser criada na página Módulo:Infobox/Funções/Pessoa/doc

-- Funções utilizadas dentro das infobox sobre pessoas
local p = {}
local localdata = require( 'Módulo:Infobox/Localdata' )
local item = localdata.item
local wikidata = require( "Módulo:Infobox/Wikidata" )
local general = require "Módulo:Infobox/Funções"
local datemodule = require "Módulo:Data"
local complexdate = require "Módulo:Data complexa"
local linguistic = require "Módulo:Linguística"
local militaryranks = require "Módulo:Dicionário Wikidata/Graus militares"
--=== Acordo em género

-- define a variável genêro para o elemento
local function getgender(id)
    local vals = {
    ['Q6581072'] = 'f',
    ['Q6581097'] = 'm',
    default       = '?'
    }
    local gender = wikidata.formatStatements{entity = id, property = 'P21', displayformat = 'raw'}
    return vals[gender] or vals.default
end

local gender = getgender(item)

-- recuperação de rótulos genotipados da Wikidata
local function genderedlabel(id, labelgender)
    local label
    if not labelgender then
       labelgender = gender -- se o gênero não é indicado, é o da pessoa cuja infobox
    end
    if labelgender == 'f' then -- feminino: procure o texto em P2521 (texto feminino)
       label = wikidata.formatStatements{entity = id, property = 'P2521', isinlang = 'pt', numval = 1, ucfirst = '-'}
    elseif labelgender == 'm' then -- homem : procurar para o texto em P3321 (texto masculino)
           label = wikidata.formatStatements{entity = id, property = 'P3321', isinlang = 'pt', numval = 1, ucfirst = '-'}
    end
    if not label then
       label = wikidata.getLabel(id)
    end
    return label
end

-- === Gestão das datas

-- Links temáticos para datas
local datelinks = { -- link para a área apropriada de atividade
    Q483501 = 'nas artes plásticas', -- artista
    Q1028181 = 'nas artes plásticas', -- pintura
    Q1281618 = 'nas artes plásticas', -- escultura
    Q2309784 = 'no ciclismo', -- ciclista
    Q16947657 = 'nas artes plásticas', -- litografia
    Q11569986 = 'nas artes plásticas', -- gravura
    Q13365770 = 'nas artes plásticas', -- gravador de cobre
    Q21925567 = 'nas artes plásticas', -- serigrafia
    Q10862983 = 'nas artes plásticas', -- aquafortiste
}

local function getdatetopic() -- Obtém o link mais apropriado para uma data baseada na ocupação
    local claims = wikidata.stringTable{entity = item, property = 'P106', excludespecial = true, displayformat = "raw"}
    if not claims then
       return nil
    end
    for i, j in pairs(claims) do
        if datelinks[j] then
           return datelinks[j]
        end
    end
end

local linktopic = getdatetopic()


local unknowndatelabel = "data desconhecida"

local birthdate = localdata['data_nascimento'] or
    localdata['nascimento_data'] or
    wikidata.formatAndCat{
    entity = item,
    property = 'P569',
    unknownlabel = unknowndatelabel,
    minprecision = 9,
    conjtype = 'or',
    sorttype = 'chronological'
    }

local dead = wikidata.getClaims{entity = item, property = 'P570'} -- usado como um booleano que diz que se uma pessoa está morta para mudar algum elemento de exibição
local deathdate = localdata ['morte_data'] or localdata['data_morte']
local wddeathdate = wikidata.formatAndCat{
    entity = item,
    property = 'P570',
    unknownlabel = unknowndatelabel,
    minprecision = 9,
    conjtype = 'or',
    sorttype = 'chronological',
}

local function format1(event, period, predecessor, together, successor, displayformat)
    local mainstr = event
    if predecessor then
       local s = 'precedido por ' .. predecessor
       if gender == 'f' then
             s = 'precedido por ' .. predecessor
       end
       mainstr = mainstr .. '<small><br />&nbsp;' .. s .. '</small>'
    end
    if together then
       local s = 'com ' .. together
       mainstr = mainstr .. '<small><br />&nbsp;' .. s .. '</small>'
    end
    if successor then
       local s = 'sucedido por ' .. successor
       if gender == 'f' then
             s = 'sucedido por ' .. successor
       end
       mainstr = mainstr .. '<small><br />&nbsp;' .. s .. '</small>'
    end
    return {type = 'row', label = period or '', value = function() return mainstr end}
end

-----------------

local function format2(event, period, predecessor, together, successor, displayformat)
    if (not event) then
    return nil
    end
 
    local rows = {}

    local eventrow = {type = 'row1col', color = 'secondcolor', value = event }
    table.insert(rows, eventrow)

    if period then
       period = '<span style="font-weight:normal">' .. period .. '</span>'
       local periodrow = {type = 'row1col', color = '#F9F9F9', value = period }
       table.insert(rows, periodrow)
    end

    if predecessor then
       local prederow = {type = 'row', label = 'Predecessor', value = function() return predecessor end}
       table.insert(rows, prederow)
    end

    if together then
       local succrow = {type = 'row', label = 'Com', value = function() return together end}
       table.insert(rows, succrow)
    end

    if successor then
       local succrow = {type = 'row', label = 'Sucessor', value = function() return successor end}
       table.insert(rows, succrow)
    end
    return {type = 'multi', rows = rows}
end


local function format3(event, period, predecessor, together, successor, displayformat, details)
    if details then
       details = '<span style="font-weight:normal">' .. details .. '</span>'
       event = linguistic.conj({event, details}, "new line")
    end
    local mainrow =  {type = 'row1col', color = 'secondcolor', value = event }
    if period then
       period = '<span style="font-weight:normal">' .. period .. '</span>'
    end
    local periodrow = {type = 'row1col', color = '#F9F9F9', value = period }
    local successionrow = {
          style = {['background-color'] = '#F9F9F9', ['padding-bottom'] = '2%'},
          type = 'navbox',
          inner = true,
          previousval = function() return predecessor end,
          nextval = function() return successor end,
    }

    return {type = 'multi', rows = {mainrow, periodrow, successionrow}}
end


local function timeline(localparam, wdconf, timelineformat, title, singtitle, details) -- data do poster: event (assume eventos já classificados)
    local rows = {}
    local function returnTable()
    return {
           type = "table",
           title = title,
           rows = rows
    }
    end
 
    -- com dados locais
    local val = localdata[localparam]
    if val == '-' then
       return nil
    elseif val then
       table.insert(rows, {type = 'row1col', color = 'secondcolor', value = val})
    return returnTable()
    end
    -- com dados wikidata
    if not wdconf then
       return nil
    end
 
    wdconf.entity = wdconf.entity or item
    wdconf.sorttype = wdconf.sorttype or "chronological"
    wdconf.labelformat = wdconf.labelformat  or function(id) return genderedlabel(id) end
    wdconf.linktopic = wdconf.linktopic or "-"
    wdconf.stilltrue = not dead -- se a pessoa está viva, nós usamos "de" em vez de "de" (mas quando está terminado, mas a data final está faltando, ela se torna falsa) em tradução
 
    local statements = wikidata.getClaims(wdconf)
    if not statements then
       return nil
    end
    if #statements == 1 then
       title = singtitle
    end
    local displayformats = {
    A = format1,
    B = format2,
    C = format3,
    }
    local applyformat = displayformats[timelineformat] or displayformats['A']
 
    rows = {}
    for i, statement in pairs(statements) do
        local event =  linguistic.ucfirst(wikidata.formatStatement(statement, wdconf))
        local predecessor = wikidata.getFormattedQualifiers(statement, {'P155', 'P1365'})
        local together = wikidata.getFormattedQualifiers(statement, {'P1706', ''})
        local successor = wikidata.getFormattedQualifiers(statement, {'P156', 'P1366'})
        local period = wikidata.getFormattedDate(statement, {linktopic = wdconf.linktopic, stilltrue = not dead } ) -- dont pass all wdconf or else qualifiers will show up
        local detailstr 
        if type(details) == "function" then
           detailstr = details(statement)
        end
        local row = applyformat(event, period, predecessor, together, successor, wdconf, detailstr)
        if row then
           table.insert(rows, row)
        end
    end
    table.insert(rows, {type = "external text", value = function() return wikidata.addTrackingCat(wdconf.property) end})
    return returnTable()
end


local function dateandplace(thedate, theplace)
    if thedate and theplace and mw.ustring.find(thedate, "desconhecido") and mw.ustring.find(theplace, "desconhecido") then
       theplace = nil
       thedate =  mw.ustring.gsub(thedate, linguistic.ucfirst(unknowndatelabel), "Data e local desconhecido")
    end
    return linguistic.conj({thedate, theplace}, "new line")
end


--Título
function p.title(icon, style)
    return general.title(icon, style)
end

--Imagem
function p.mainimage(cat)
 
     -- pedido de ilustração apenas se a pessoa nasceu ou morreu depois de 1900, caso contrário, muitas vezes é impossível encontrar
    local defaultimage = 'Padrao 2.svg'
    local age = wikidata.stringTable{property = 'P569,P570', entity = item, displayformat = 'raw', excludespecial = true}

    if age then
       local pattern = "(%W)(%d+)%-(%d+)%-(%d+)"
       local era, year = age[1]:match(pattern)
       if (era == '-') or (tonumber(year)) < 1900 then
             defaultimage = nil
       end
    end
    return  general.mainimage(cat or '!Artigos de biografia sem imagens', defaultimage)
end

-- Nomes
function p.othernames()

    local names = {
    --{'P1477', 'Nome nativo', 'Nomes nativos', 'nome nativo'}, --nome de nascimento mesmo que P1559 
    --{'P1559', 'Nome no idioma nativo', 'Nomes nos idiomas nativos', 'nomecompleto', 'nome nativo'}, --nome de nascimento no idioma nativo
    {'P1449', 'Apelido', 'Apelidos', 'apelido'}, -- sobrenome
    {'P2001', 'Romanização revisada', 'Romanização revisada', 'romanização'},
    {'P1942', 'McCune-Reischauer', 'McCune-Reischauer', 'romanização mccune-reischauer'},
--  {'P460', 'Pseudónimo', 'Pseudónimos', 'pseudónimo'}, -- igual a P742
    {'P742', 'Pseudónimo', 'Pseudónimos', 'pseudónimo'},
    {'P1782', 'Nome de cortesia', 'Nomes de cortesias', 'nome de cortesia'},
    {'P1786', 'Nome póstumo', 'Nomes póstumos', 'nome póstumo'},
    {'P1785', 'Nome de templo', 'Nomes de templo', 'nome de templo'},
    {'P1787', 'Nome artístico', 'Nomes artísticos', 'nome artístico'},
    {'P428', 'Abreviação em botânica', 'Abreviações em botânica', 'abreviação em botânica'}, --abreviação do autor botânico
    {'P835', 'Abreviação', 'Abreviações', 'abreviação'}, -- citação de autor
    {nil, 'Outros nomes', 'Outros nomes', 'outros_nomes'},
    {nil, 'Conhecido por', 'Conhecido por', 'conhecido_por'},
    }

    local birthnamerow = { -- um pouco peculiar, tão distante
    type = "row",
    wikidata  = function()
        local s = wikidata.formatAndCat{entity = item, property = "P1559"}
        if (not s) then
              return nil
        end
        -- ver se o nome do valor se parece com o texto (tendo em conta a poluição dos marcadores de idioma
        local label = mw.ustring.lower(wikidata.getLabel(item) or "")
        local useless
        if mw.ustring.find(mw.ustring.lower(s), mw.ustring.lower(label), 0, true) then
              useless = true
        end
        if useless then
              return nil
        end
        return s
    end,
    label = 'Nome nativo',
    plurallabel = 'Nomes nativos',
    value = {'nome_completo', 'nome_nativo'},
    }
 
    local rows = {type = "multi", rows = {birthnamerow}}
    for i, j in pairs(names) do
        local query
        if j[1] and not localdata['outros nomes'] then -- quando existe um parâmetro "outros nomes", o Wikidata fica desabilitado para evitar riscos duplicados
              query = {property = j[1], showqualifiers = {'P1721'}, conjtype = 'new line'}
        end
        table.insert(rows.rows, {type = 'row', value = j[4], wikidata = query, label = j[2], plurallabel = j[3]})
    end
    return rows
end

-- NASCIMENTO E MORTE
function p.birth() -- data de nascimento na primeira linha, local do nascimento no segundo
    return {
    type = 'row',
    label = 'Nascimento',
    value =
    function()
    local thedate = datemodule.dataInfobox{args = {[1] = 'nascimento', [2] = birthdate or '', [3] = deathdate or wddeathdate or '', qualificativo = linktopic, unknownlabel = "data desconhecida"}}
    local theplace = localdata ['local_nascimento'] or localdata ['nascimento_local'] or localdata ['cidadenatal'] or wikidata.formatAndCat({entity =item, property= 'P19', rank = 'best', conjtype= ' ou ', unknownlabel = "local desconhecido"})
    return dateandplace(thedate, theplace)
    end
    }
end

function p.death() -- mesma função que a função p.birth
 
    --- de Wikidata apenas na ausência de dados locais
    local ddate = deathdate --declarado para o módulo inteiro
    if (not ddate) and (not localdata['data de desaparecimento']) then
    deathdate = wddeathdate
    end
    local thedate = datemodule.dataInfobox{args = {[1] = 'morte', [2] = birthdate or '', [3] = deathdate or '', qualificativo = linktopic, unknownlabel = "data desconhecida"}}
    local theplace = localdata['local_morte'] or wikidata.formatAndCat{entity = item, property= 'P20', rank = 'best', conjtype= ' ou ', unknownlabel = "local desconhecido"}

    local val = dateandplace(thedate, theplace)

    return
--    {type = 'row', rows = {
--    { -- desaparecimento
--    type = 'row',
--    label = 'Desaparecimento',
--    value = function() return --val end,
--    },
    { -- morte
      type = 'row',
      label = 'Morte',
      value = function() return val end,
    }
--    }}
end

function p.atividade()
    return {
           type = 'row',
           label = "Período de atividade",
           value = "período de atividade",
           wikidata = function()
           local startDate = wikidata.formatAndCat{entity = item, property = "P2031", conjtype = "or", sorttype = "chronological"}
           local endDate =    wikidata.formatAndCat{entity = item, property = "P2032", conjtype = "or", sorttype = "chronological"}
           if not (startDate or endDate) then
                 return wikidata.formatAndCat{entity = item, property = 'P1317'}
           end
           return complexdate.daterange(startDate, endDate, {precision = 11})
    end
    }
end

function p.placeofburial()
    return
    {type = 'row', label = "Sepultamento", value = "sepultamento", property = 'P119'}
end

function p.nationality()
 
    -- para melhorar as maneiras que Wikidata lida com nacionalidade: Império Alemão (1901-1918) República de Weimar (1918-1933))
    local function wdDate()
    local nation = require "Módulo:Country data".nationality
 
    -- desativação se data de nascimento antes da era contemporânea: muitas imprecisões e anacronismos
    local mindate = '1789'
 
    local birthdate = wikidata.formatStatements{entity = item, property = 'P569', displayformat = 'raw', numval = 1}
    if (not birthdate) or complexdate.before(mindate, birthdate) then
       return nil
    end
 
    return {
           property = 'P27',
           -- vals = statements, -- statments é uma variável não declarada neste módulo
           showdate = true,
           entity = item,
           conjtype = 'comma',
           removedupes = true,
           linktopic = '-',
           displayformat =
           function(snak)
           local g = gender -- tipo da pessoa, para exibição do gentio
           if g == '?' then -- se desconhecido, em masculino
                 g = 'm'
           end
           local val, success = nation(wikidata.getId(snak), g)
           if not success then
                 val = wikidata.formatSnak(snak)
           end
           return val
           end
    }
    end
 
    return {
           type = 'row',
           label = 'Cidadania',
           plurallabel = 'Cidadanias',
           value = {'nacionalidade', 'cidadania', 'país'},
           wikidata = wdDate() -- wdDate() devolve uma tabela
    }

end
--Etnia
function p.etnia()
    return
    {type = 'row', label = "[[Etnia]]", value = "etnia", property = 'P172'}
end

-- língua materna
function p.nativelanguage()
    return
    {type = 'row', label = 'Língua materna', value = 'língua materna', property = 'P103'}
end

-- Domicílios
function p.places()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Demo',
    plurallabel = 'Demos',
    value = 'demo',
    wikidata = {property = 'P2462', showdate = true, sorttype= 'chronological', precision = 'year'},
},
{
    type = 'row',
    label = 'Residência',
    plurallabel = 'Residências',
    value = {'residência', 'residencia'},
    wikidata = {property = 'P551', showdate = true, sorttype= 'chronological', precision = 'year'},
},
{
    type = 'row',
    label = 'Local de trabalho',
    plurallabel = 'Local de trabalho',
    value = 'local de trabalho',
    wikidata = {property = 'P937', sorttype= 'chronological', showdate = true, precision = 'year'},
},
    }}
end

-- carreira profissional
function p.education() -- a melhorar
    local query = {sorttype= 'chronological', property = 'P69', showdate = true, showqualifiers = 'P512', conjtype = 'new line', linktopic = '-'}
    return {
    type = 'row',
    value = {'alma mater', 'formação', 'educação', 'formaçao'},
    wikidata = query,
    label = '[[Alma mater]]',
    }
end

function p.occupation()

    local speciallabels = {
    f = {
    ['Q33999'] = '[[atriz]]',
    ['Q10798782'] = '[[atriz]]',
    ['Q10800557'] = '[[atriz]]',
    ['Q2405480'] = '[[atriz]]',
    ['Q2259451'] = '[[atriz]]',
    ['Q948329'] = '[[atriz]]'
    },
    m = {
    ['Q33999'] = '[[ator]]',
    ['Q10798782'] = '[[ator]]',
    ['Q10800557'] = '[[ator]]',
    ['Q10798782'] = '[[ator]]',
    ['Q2405480'] = '[[ator]]',
    ['Q2259451'] = '[[ator]]',
    ['Q948329'] = '[[ator]]'
    }
    }

    return {
    type = 'row',
    value = {'atividade', 'atividades', 'profissão', 'ocupação', 'desporto'},
    wikidata = {
    property = 'P106',
    defaultlink = '-',
    defaultlinkquery = {property = 'P425'},
    labelformat = function(id) return genderedlabel(id) end,
    speciallabels = speciallabels[gender] or speciallabels['m'],
    removedupes = true,
    excludevalues = { -- ocupações que não merecem ser exibidas
    'Q482980', -- autor
    --'Q15980158', "autor de não-ficção" já foi traduzido como "ensaísta"
    'Q18814623', -- autobiografia
    'Q1209498', -- jurista-poeta
    }
    },
    label = 'Atividade',
    plurallabel = 'Atividades'
    }
end

function p.employer()
    return {
        type = 'row',
        value = 'empregador',
        wikidata = {property = 'P108', showdate = true, sorttype= 'chronological'},
        label = function() return localdata['titulo empregador'] or 'Empregador' end,
    }
end

function p.victories()
    local title, singtitle = "Vitórias", "Vitória"
    local localparam = "vitoria"
    local wdconf = {property = 'P2522'}
    local displayformat = "B"
 
    return timeline(localparam, wdconf, displayformat, title, singtitle)
end


function p.officialposition()
    local title, singtitle = "Funções", "Função"
    local localparam = "função"
    local wdconf =  {
    property = 'P39',
    rank = 'valid',
    sorttype = 'inverted',
    defaultlinkquery =      {property = {'P2354', 'P2389', 'P453', 'P361', 'P108'}}, -- links padrão: lista, corpo direcionado ao corpo, "membro de", "parte de", empregador
    }
    -- em uma linha separada: jurisdição, "de", distrito eleitoral, diocese, afiliação, assembleia, partido, empregador
    local details = function(statement) return wikidata.getFormattedQualifiers(statement, {'P1001', 'P642', 'P768', 'P708', 'P1416', 'P194', 'P108', 'P937'}) end
    local displayformat = "C"
 
    return timeline(localparam, wdconf, displayformat, title, singtitle, details)
end

function p.nobilitytitle()
    local title, singtitle = "Títulos de nobreza", "Título de nobreza"
    local localparam = "titulo de nobreza"
    local wdconf = {
    property = 'P97',
    entity = item, rank = 'valid',
    showqualifiers =  {'P642'},
    defaultlinkquery =      {property = {'P2354', 'P361'}}, -- links padrão: list, body directed, "member of" e "part of"
    }
    local displayformat = "B"
 
    return timeline(localparam, wdconf, displayformat, title, singtitle)
end


function p.honorifictitle()
    local title, singtitle = "Título honoríficos", "Títulos honoríficos"
    local localparam = "titulo honorifico"
    local wdconf = {property = 'P511', entity = item, rank = 'valid'}
    local displayformat = "C"
 
    return timeline(localparam, wdconf, displayformat, title, singtitle)
end

function p.sepultura()
    return {
           type = 'images',
           imageparameters =  {'sepultura'},
           defaultimages = nil,
           defaultupright = 1,
           uprightparameter = 'upright sepultura',
           sizeparameter = 'tamanho urna', -- obsoleto
           captionparameter = 'legenda sepultura',
           defaultcaption = 'Vista da sepultura.',
           property = 'P1442',
           numval = 1,
    }
end

function p.placa()
    return {
           type = 'images',
           imageparameters =  {'placa'},
           defaultimages = nil,
           defaultupright = 1,
           uprightparameter = 'upright placa',
           sizeparameter = 'tamanho placa', -- obsoleto
           captionparameter = 'legenda placa',
           defaultcaption = 'placa comemorativa',
           property = 'P1801',
           numval = 1,
    }
end

function p.brazao()
    return {
           type = 'images',
           imageparameters =  {'brazão'},
           defaultimages = nil,
           defaultupright = 0.7,
           uprightparameter = 'upright brazão',
           sizeparameter = 'tamanho brazão', -- obsoleto
           captionparameter = 'legenda brazão',
           defaultcaption = 'brazão',
           property = 'P94',
           numval = 1,
    }
end

function p.sinete()
    return {
           type = 'images',
           imageparameters =  {'emblema'},
           defaultimages = nil,
           defaultupright = 0.7,
           uprightparameter = 'upright emblema',
           sizeparameter = 'tamanho emblema', -- obsoleto
           captionparameter = 'legenda emblema',
           defaultcaption = 'emblema',
           property = 'P158',
           numval = 1,
    }
end

function p.monogram()
    return {
           type = 'images',
           imageparameters =  {'monograma'},
           defaultimages = nil,
           defaultsize =      '100px',
           sizeparameter = 'tamanho monograma',
           captionparameter = 'legenda monograma',
           defaultcaption = 'Monograma',
           property = 'P1543',
           numval = 1,
    }
end

function p.flag()
    return {
           type = 'images',
           imageparameters =  {'bandeira'},
           defaultimages = nil,
           defaultsize =      '150px',
           sizeparameter = 'tamanho bandeira',
           captionparameter = 'legenda bandeira',
           defaultcaption = 'Bandeira',
           property = 'P41',
           numval = 1,
    }
end

function p.logo()
    return {
           type = 'images',
           imageparameters =  {'logotipo'},
           defaultimages = nil,
           defaultsize =      '150px',
           sizeparameter = 'tamanho logotipo',
           captionparameter = 'legenda logotipo',
           defaultcaption = 'Marca ou logotipo',
           property = 'P154',
           numval = 1,
    }
end

function p.politicalparty()
    return {
           type = 'row',
           value = 'partido político',
           label = 'Partido político',
           plurallabel = 'Partidos políticos',
           wikidata = { property = 'P102', sorttype= 'chronological', showdate = true, conjtype = 'new line', excludespecial = true},
    }
end

function p.memberof()
    return {type = 'multi', rows = {
{
    type = 'row',
    value = 'ordem de cavalaria',
    label = 'Ordens de Cavalarias',
    plurallabel = 'Ordens de Cavalarias',
    wikidata = {property = 'P550', sorttype= 'chronological', showdate = true},
},
{
    type = 'row',
    label = 'Membro de',
    value = {'membro de', 'filiação'},
    wikidata = {property = 'P463', sorttype= 'chronological', showdate = true, precision = 'year', textformat = 'minimum', conjtype = 'new line'},
},
    }}
end

function p.awards()
 
    local function awardsList()
    local majorawards = require "Módulo:Dicionário Wikidata/Distinções"
    local query = {
          entity = item,
          property= 'P166',
          sorttype= 'chronological',
          grouped = true,
          showqualifiers = 'P642',
          showdate= true,
          precision = 'year',
          conjtype = 'new line',
          textformat = 'minimum',
          linktopic = '-',
          defaultlinkquery = {property = {'P2354', 'P361' , 'P1027'}},
          excludevalues = 'Q15631401', -- membro da Royal Society, redundância com o campo "membro de" (P463)
          speciallabels = majorawards,
          labelformat = function(id) return genderedlabel(id) end,
    }
    local claims = wikidata.getClaims(query)
    if (not claims) then
       return nil
    end
    local str = wikidata.formatAndCat(query)
    if #claims < 4 then
       return str, #claims
    end

    --Se muitos valores, apenas exibir os importantes de [[Módulo: Dicionário Wikidata / Distinções]], e colocar os outros em um menu dobrável

    --- recuperação dos importantes
    local majorStr
    local targetvalues = {}
    for i, j in pairs(majorawards) do
        table.insert(targetvalues, i)
    end
    query.targetvalue = targetvalues
    query.value, query.claims, query.valuetable = nil, nil, nil -- aparentemente se não, por quê? BUG IMPORTANTE
    majorStr = wikidata.formatAndCat(query)

    --- dobrar dos outros
    local message = "'''Lista detalhada'''"
    local allAwardsTable = mw.html.create('div')
    :addClass("toccolours mw-collapsible mw-collapsed")
    :wikitext(message)
    :css{border = "none"}
    :tag('div')
    :addClass("mw-collapsible-content")
    :css{['line-height'] = '150%'} -- caso contrário, é realmente apertado
    :wikitext( str)
    :done()
    :allDone()

    return linguistic.conj({majorStr, tostring(allAwardsTable)}, "<br />"), #claims
    end
 
    return {
           type = 'row',
           value = {'prêmios', 'prémios', 'distincoes', 'distinções'},
           label = 'Distinções',
           singularlabel = 'Distinção',
           wikidata = function() return awardsList() end
    }
end

-- Influences
function p.influencedby()
    return {
           type = 'row',
           label =
           function(localdata, item)
           if gender == 'f' then
              return 'Influenciada por'
           elseif gender == 'f' then
               return 'Influenciado por'
           else
        return 'Influências'
           end
           end,
           value = {'influencias', 'influências'},
           wikidata = {property = 'P737'},
    }
end

function p.influenced()
    return {
    type = 'row',
    label = 'Influenciados',
    value = {'influenciados', 'influenciou'},
}
end

-- Movimentos
function p.movement()
    return
    {
    type = 'row',
        label = 'Movimento',
        value = {'movimento', 'movimentos', 'movimento(s)'},
        wikidata = {property = 'P135', sorttype= 'chronological', showdate = true, precision = 'year'},
    }
end

-- Religião
function p.religion()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Religão',
    plurallabel = 'Religiões',
    value = {'religião', 'religiao'},
    wikidata = {property = 'P140', sorttype= 'chronological', showdate = true, precision = 'year', excludevalues = 'Q7066'},
},
{
    type = 'row',
    label = 'Data de baptismo',
    value = {'data de baptismo', 'data de batismo'},
    property = 'P1636',
},
{
    type = 'row',
    label = 'Paróquia',
    plurallabel = 'Paróquias',
    value = {'paroquia', 'paróquia'},
    property = 'P1290',
},
{
    type = 'row',
    label = 'Nome em religião',
    plurallabel = 'Nomes em religião',
    value = {'nome em religiao', 'nome em religião'},
    property = 'P1635',
},
{
    type = 'row',
    label = 'Ordem religiosa',
    plurallabel = 'Ordens religiosas',
    value = 'ordem religiosa',
    property = 'P611',
},
{
    type = 'row',
    label = 'Consagramento',
    plurallabel = 'Consagramentos',
    value = 'consagramento',
    property = 'P1598',
},
{
    type = 'row',
    label =
    function(localdata, item)
        if gender == 'f' then
              return 'Venerada por'
        elseif gender == 'm' then
           return 'Venerado por'
        else
       return 'Venerada por'
        end
    end,
    value = 'venerado por',
    property = 'P1049',
},
{
    type = 'row',
    label = 'Etapa de canonização',
    value = 'etapa de canonização',
    wikidata = {
    property = 'P411',
    labelformat = function(id) return genderedlabel(id) end,
    },
},
    }}
end

-- Carreira militar
function p.military()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Exército',
    plurallabel = 'Exércitos',
    value = 'arma',
    wikidata = {property = 'P241', showdate = true, sorttype= 'chronological', precision = 'year'},
},
{
    type = 'row',
    label = 'Grau militar',
    plurallabel = 'Graus militares',
    value = 'grau militar',
    wikidata = {property = 'P410', showdate = true, sorttype= 'chronological', precision = 'year', speciallabels = militaryranks, conjtype ='new line'},
},
{
    type = 'row',
    label = 'Conflito',
    plurallabel = 'Conflitos',
    value = 'conflito',
    wikidata = {property = 'P607', conjtype = 'new line', showdate = true, sorttype= 'chronological', precision = 'year'},
},
    }}
end

-- Carreira de toureiro
function p.toureiro()
    return {type = 'multi', rows = {
{
    type = "row",
    label = "Alternativo",
    value = "alternativo",
    wikidata = function() return wikidata.keyDate("Q2840411", item) end
},
{
    type = "row",
    label = "Confirmação alternativa",
    value = "confirmacao alt",
    wikidata = function() return wikidata.keyDate("Q23308805", item) end
},
    }}
end

-- Desporto
function p.sport()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Especialidade',
    plurallabel = 'Especialidades',
    value = 'especialidade',
    wikidata = {property = 'P413',
    labelformat = function(id) return genderedlabel(id) end,
    },
},
{
    type = 'row',
    label = 'Disciplina desportiva',
    plurallabel = 'Disciplinas desportivas',
    value = {'disciplina desportiva', 'disciplina'},
    wikidata = {property = 'P2416'},
},
{
    type = 'row',
    label = 'Mão de jogo',
    value = 'mao de jogo',
    wikidata = {property = 'P741'},
},
{
    type = 'row',
    label = 'Destreza de',
    value = 'destreza',
    wikidata = {property = 'P423'},
},
{
    type = 'row',
    label = 'Repescagem por',
    plurallabel = 'Repescagens por',
    value = 'repescagem',
    wikidata = {
        property = 'P647',
        statementformat = function(statement)
        local team = wikidata.formatStatement(statement)
        local moment = wikidata.getFormattedQualifiers(statement, {'P793'}) or    wikidata.getFormattedQualifiers(statement, {'P585'})
        local rank = wikidata.getFormattedQualifiers(statement, {'P1836'})
        if rank then
              rank = require "Módulo:Name2text".ordinal(rank) .. ' escolha'
        end
        local qualifs = linguistic.conj({moment, rank}, '&nbsp;– ')
        if not qualifs then
              return team
        end
        return team .. ' <small>(' .. qualifs  .. ')</small>'
    end
 
    },
},
{
    type = 'row',
    label = 'Equipa',
    plurallabel = 'Equipas',
    value = 'equipa',
    wikidata = {
    property = 'P54',
    sorttype= 'chronological',
    conjtype = "new line",
    statementformat = function(statement)
    local str = wikidata.formatStatement(statement, {showdate = true})
    local compets = wikidata.getFormattedQualifiers(statement, {"P1350"})
    if tonumber(compets) and (tonumber(compets) > 1) then
       compets = compets .. " jogos jogados"
    elseif compets then
       compets = compets .. " jogo jogado"
    end
    local points = wikidata.getFormattedQualifiers(statement, {"P1351"})
    if tonumber(points) and (tonumber(points) > 1) then
       points = points .. " pontos marcados"
    elseif points then
       points = points     .. "ponto marcado"
    end
    local qualifiers = linguistic.conj{compets, points}
    if qualifiers then
       str= str .. " <small> – " .. qualifiers .. " </small>"
    end
    return str
    end
    }
},
{
    type = 'row',
    label = 'Jogos internationais',
    value = 'jogos',
    wikidata = {property = 'P1129', numval = 1},
},
{
    type = 'row',
    label = 'Título no xadrez',
    plurallabel = 'Títulos no xadrez',
    value = 'titulo no xadrez',
    wikidata = {property = 'P2962', sorttype= 'chronological', showdate = true, precision = 'year'},
},
{
    type = 'row',
    label = 'Classificação Elo',
    value = 'classificação elo',
    wikidata = {property = 'P1087', numval = '3', sorttype = 'inverted', conjtype = 'new line', showdate = true, precision = 'month', removedupes = true},
},
{
    type = 'row',
    label = 'Registo realizado',
    plurallabel = 'Registos realizados',
    value = {'registo realizado', 'registro realizado'},
    wikidata = {property = 'P1000', sorttype= 'chronological', showdate = true},
},
{
    type = 'row',
    label = 'Treinador',
    plurallabel = 'Treinadores',
    value = 'treinador',
    wikidata = {property = 'P286', sorttype= 'chronological', showdate = true, precision = 'year'},
},
{
    type = 'row',
    label = 'Co-piloto',
    plurallabel = 'Co-pilotos',
    value = 'co-piloto',
    wikidata = {property = 'P2095', sorttype= 'chronological', showdate = true, precision = 'year'},
},
{
    type = 'row',
    label = 'Patrocinador',
    plurallabel = 'Patrocinadores',
    value = {'patrono', 'patrocinador'},
    wikidata = {property = 'P859', sorttype= 'chronological', showdate = true, precision = 'year'},
},
    }}
end

-- Contatos
function p.contacts()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = localdata['estudante de'] or 'estudante',
    plurallabel = 'estudantes',
    value = {'estudante', 'estudantes'},
    wikidata = {property = 'P1066', sorttype= 'chronological', showdate = true, precision = 'year'},
},
{
    type = 'row',
    label = 'Orientador de doutorado',
    plurallabel = 'Orientador de doutorado',
    value = 'orientador de doutorado',
    wikidata = {property = 'P184', sorttype= 'chronological', showdate = true, precision = 'year'},
},
{
    type = 'row',
    label = 'Agente',
    label =
    function(localdata, item)
        if gender == 'f' then
              return 'Representada por'
        elseif gender == 'm' then
              return 'Representado por'
        else
       return 'Representado por'
        end
    end,
    value = 'representado por',
    wikidata = {property = 'P1875'},
},
{
    type = 'row',
    label = 'Sócio',
    plurallabel = 'Sócios',
    value = {'sócio', 'socio'},
    wikidata = {property = 'P1327'},
},
{
    type = 'row',
    label = localdata['instituto superior'] or 'Superior',
    plurallabel = 'Superiores',
    value = {'superior', 'superiores'},
    wikidata = {property = 'P802', sorttype= 'chronological', showdate = true, precision = 'year', numval = 5},
},
{
    type = 'row',
    label = 'Estudante de doutorado',
    plurallabel = 'Estudantes de doutoramento',
    value = 'estudante de doutoramento',
    wikidata = {property = 'P185', sorttype= 'chronological', showdate = true, precision = 'year', numval = 5},
},
{
    type = 'row',
    label = 'Pessoa relacionada',
    plurallabel = 'Pessoas relacionadas',
    value = 'pessoa relacionada',
    wikidata = {property = 'P3342', numval = 5, showqualifiers = 'P794'},
},
    }}
end

-- Mecenato
function p.patron()
    return {
    type = 'row',
    label = '[[Mecenato|Mecena]]',
    singularlabel = '[[Mecenato|Mecena]]',
    plurallabel = '[[Mecenato|Mecenas]]',
    value = 'mecenas',
    wikidata = {property = 'P1962', showdate = true, sorttype = 'chronological', conjtype = 'comma'},
    }
end

-- Música
function p.music()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Alcance',
    value = 'alcance',
    property = 'P412',
},
{
    type = 'row',
    label = 'Fach',
    value = 'fach',
    property = 'P1731',
},
{
    type = 'row',
    label = 'Instrumento',
    plurallabel = 'Instrumentos',
    value = 'instrumento',
    wikidata = {property = 'P1303', sorttype= 'chronological'},
},
{
    type = 'row',
    label = 'Editora discográfica',
    plurallabel = 'Editoras discográficas',
    value = {'editora discografica', 'label'},
    wikidata = {property = 'P264', sorttype= 'chronological', showdate = true, precision = 'year'},
},
    }}
end

-- Vitímas
function p.victims()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Vitímas',
    value = {'vitímas', 'vitimas'},
    wikidata = {property = 'P1345'},
},
    }}
end

-- Condenações
function p.penalties()
    return {type = 'multi', rows = {
{
    type = 'row',
    label =
    function(localdata, item)
        if gender == 'f' then
              return 'Condenada por'
        elseif gender == 'm' then
           return 'Condenado por'
        else
       return 'Condenado por'
        end
    end,
    value = 'condenado por',
    wikidata = {property = 'P1399', showdate = true, sorttype = 'chronological', precision = 'year', conjtype = 'comma'},
},
{
    type = 'row',
    label = 'Condenação',
    plurallabel = 'Condenações',
    value = {'condenacao', 'condenação'},
    wikidata = {property = 'P1596', showdate = true, sorttype = 'chronological', precision = 'year', conjtype = 'comma'},
},
{
    type = 'row',
    label = 'Ordem de detenção',
    plurallabel = 'Ordem de detenção',
    value = {'ordem de detenção', 'ordem de detencao'},
    wikidata = {property = 'P2632', showdate = true, sorttype = 'chronological', precision = 'year', conjtype = 'comma'},
},
    }}
end

-- Físico
function p.appearance()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Altura',
    value = {'tamanho', 'altura'},
    wikidata = {property = 'P2048', targetunit = 'm', rounding = '2'},
},
--[[
{
    type = 'row',
    label = 'Peso',
    value = 'peso',
    wikidata = {property = 'P2067', targetunit = 'kg', rounding = '1'},
},
]]--
{
    type = 'row',
    label = 'Cabelo',
    value = 'cabelo',
    wikidata = {property = 'P1884'},
},
{
    type = 'row',
    label = 'Olhos',
    value = 'olhos',
    wikidata = {property = 'P1340'},
},
    }}
end

-- Família
function p.family()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Família',
    plurallabels = 'Famílias',
    value = {'família', 'familia'},
    property = 'P53',
},
{
    type = 'row',
    label = 'Pai',
    value = 'pai',
    wikidata = {property = 'P22', conjtype = ' ou '},
},
{
    type = 'row',
    label = 'Mãe',
    value = {'mãe', 'mae'},
    wikidata = {property = 'P25', conjtype = ' ou '},
},
{
    type = 'row',
    label = 'Padrastro', --progenitor ?
    plurallabel = 'Padrastros',
    value = {'padrastro', 'madrastra'},
    property = 'P3448',
},
{
    type = 'row',
    label = 'Irmãos',
    value = {'irmãos', 'irmaos'},
    wikidata = {
    property = 'P3373',
    sorttype = 'chronological',
    conjtype = 'new line',
    textformat = 'long',
    precision = 'year',
    stilltrue = not dead,
    }
},
{
    type = 'row',
    label = 'Cônjuge', -- todo : adaptar a redação em genéro ?
    plurallabel = 'Cônjuges',
    value = {'cônjuge', 'conjuge'},
    wikidata = {
    property = 'P26',
    showdate = true,
    sorttype = 'chronological',
    conjtype = 'new line',
    textformat = 'long',
    precision = 'year',
    stilltrue = not dead,
    precision = 'year',
    }
},
{
    type = 'row',
    label = localdata['criança titulada'] or 'Descendentes',-- todo : adaptar a redação em genéro ?
    plurallabel = 'Descendentes',
    value = 'descendentes',
    wikidata = {
    property = 'P40',
    conjtype = 'new line',
    textformat = 'long',
    precision = 'year',
    stilltrue = (not dead),
    precision = 'year',
    }
},
{
    type = 'row',
    label = 'Parentesco',
    value = 'parentesco',
    wikidata = {
    property = 'P1038',
    excludespecial = true,
    conjtype = 'new line',
    statementformat = function(statement)
    local personid = wikidata.getMainId(statement)
    local personlabel = wikidata.formatEntity(personid)
    local persongender = getgender(personid)
    local kintype = wikidata.getFormattedQualifiers(
    statement,
    "P1039",
    {
    labelformat = function(id) return genderedlabel(id, persongender) end,
    link = "-"
    }
    )
    if kintype then
    return personlabel .. " " .. linguistic.inparentheses(kintype)
    end
    return personlabel
    end,
    }
},
    }}
end

-- Escravos
function p.slavery()
    return {type = 'multi', rows = {
{
    type = 'row',
    label = 'Estatuto',
    value = 'estatuto',
    wikidata = {property = 'P3716', defaultlinkquery = 'P425'},
},
{
    type = 'row',
    label = 'Proprietário',
    plurallabels = 'Proprietários',
    value = {'proprietário', 'proprietario'},
    property = 'P127',
},
    }}
end

-- Obras
function p.works(params)
    params = params or {}
    local title = params.title or "''''[[Magnum opus]]''''"

    local wikidata = {
          excludespecial = true,
          numval = 5,
          property = 'P800',
          defaultlink = 'image',
          showdate= true,
          labelformat = function(id) local label =  wikidata.getLabel(id) if label then return '<i>' .. label .. '</i>' end end,
    }
 
    for i, j in pairs(params) do
        wikidata[i] = j
    end
 
    return
    {type = 'table', title = title, rows = -- singulartitle = singulartitle dava erro
    {
    {type = 'row',
    value = {'obras principais', 'obras', 'magnum_opus', 'obrasdestacadas'},
    wikidata = wikidata
    }
    }
    }
end

function p.filmography()
    local title = 'Filmes notáveis'
    return
    {
    type = 'row',
    label = 'Filmes notáveis',
    value = {'filmes notáveis', 'filmes'},
    property = 'P1283'
    }
end

function p.discography()
    local title = 'Discografia'
    return
    {
    type = 'row',
    label = 'Discografia',
    value = 'discografia',
    property = 'P358'
    }
end

-- causa da morte
function p.causamorte(default)
    return {
    type = 'row',
    label = 'Causa da morte',
    value = 'causa morte',
    property = 'P509'
    }
end

-- Assinatura
function p.assinatura(default)
    local nome = localdata.nome or mw.title.getCurrentTitle().text
    local alt = 'assinatura de ' .. nome
    if mw.ustring.match( nome, '^[AEÈÉIOUY]' )        then
       alt = "assinatura de" .. nome
    end
    return {
    type = 'images',
    imageparameters =  {'assinatura'},
    defaultimage = default,
    captionparameter = 'legenda assinatura',
    defaultcaption = 'assinatura',
    uprightparameter = 'upright assinatura',
    defaultupright = 0.5,
    defaultalt = alt,
    property = 'P109',
    numval = 1
    }
end

-- Registos vocais
function p.voice()

    local function selectsound()
          -- prioridade em português
          if wikidata.getClaims{entity = item, property =  'P990', qualifier = {'P407'}, qualifiervalue  = {'Q5146'} } then
                return {property =      'P990', qualifier = {'P407'}, qualifiervalue    = {'Q5146'} }
             end
      return {property =        'P990'}
    end
    return {
       type     = 'images',
       style      = {['padding-top'] = '25px'},--{['border-width'] = '10px', ['border-style'] = 'solid'},
       label    = 'Registo vocal',
       captionparameter = 'legenda voz',
       value    = 'voz',
       wikidata      = selectsound (),
       numval     = 1,
    }
end

--== Web site
function p.website()
    return general.website()
end

return p