Module:Matériau
Apparence
La documentation pour ce module peut être créée à Module:Matériau/doc
local p = {}
local wikidata = require 'Module:Interface Wikidata'.fromLua
local linguistic = require 'Module:Linguistique'
local speciallabels = { -- libellés définis localement, qui priment sur ceux de Wikidata
Q296955 = '[[Peinture à l\'huile|huile]]',
Q22731 = '[[Pierre naturelle|pierre]]',
Q4259259 = '[[Toile (peinture)|toile]]',
}
function p.formatFromItem(item, args)
args = args or {}
-- affiche le matériau en fonction de Property:P186, et de son qualificatif P518 ('s'applique à')
local materials = wikidata.getClaims{entity = item, property = 'P186'}
if not materials then
return nil
end
-- créé une table de chaînes avec les différents matériaux
local withP518, withoutP518 = {}, {}
local function addStatement(statement) -- ajout d'un chaîne à la table des valeurs
-- valeur de base
local mainid = wikidata.getmainid(statement)
local str = wikidata.formatEntity(mainid, {speciallabels = speciallabels})
if (not statement.qualifiers) or (not statement.qualifiers.P518) then
table.insert(withoutP518, str)
return
end
for _, qualif in pairs(statement.qualifiers.P518) do
local key = wikidata.getid(qualif)
withP518[key] = withP518[key] or {}
table.insert(withP518[key], mainid)
end
end
for i, j in pairs(materials) do
addStatement(j)
end
-- concaténation des différentes tables de valeur
--- valeurs sans qualificatifs
local mainstr = linguistic.conj(withoutP518)
--- valeurs avec P518 utilisant la préposition "sur"
local supportstr
if withP518['Q861259'] then
local v = withP518['Q861259']
supportstr = ' sur ' .. linguistic.conj(v)
vals['Q861259'] = nil
end
if mainstr or supportstr then
mainstr = (mainstr or '').. (supportstr or '')
end
--- autres qualificatifs : préposition "en"
local withpartstr
local strtable = {}
for part, materials in pairs(withP518) do
local partstr = wikidata.getLabel(part)
local v = {}
for i, j in pairs(materials) do
table.insert(v, wikidata.formatEntity(j))
end
local str = partstr .. ' en ' .. linguistic.conj(v)
table.insert(strtable, str)
end
withpartstr = linguistic.conj(strtable, 'comma')
-- concaténation finale
mainstr = linguistic.conj({mainstr, withpartstr}, 'comma')
return mainstr
end
return p