« Module:Matériau » : différence entre les versions
Apparence
Modèle:Infobox>Zolo mailleur gestion des qualificatifs (voir 1000 De La Gauchetière) |
Modèle:Infobox>Zolo appelle la pierre "pierre" plutôt que pierre naturelle |
||
| Ligne 4 : | Ligne 4 : | ||
local speciallabels = { -- libellés définis localement, qui priment sur ceux de Wikidata | local speciallabels = { -- libellés définis localement, qui priment sur ceux de Wikidata | ||
Q296955 = '[[Peinture à l\'huile|huile]]' | Q296955 = '[[Peinture à l\'huile|huile]]', | ||
Q22731 = '[[Pierre naturelle|pierre]]', | |||
Q4259259 = '[[Toile (peinture)|toile]]', | |||
} | } | ||
Version du 11 mars 2015 à 22:53
La documentation pour ce module peut être créée à Module:Matériau/doc
local p = {}
local wikidata = require('Module:Wikidata')
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)
-- affiche le matériau en fonction de Property:P186, et de son qualificatif P518 ('s'applique à')
local materials = wikidata.getClaims{item = item, property = 'P186'}
if not materials then
return nil
end
local vals = {} -- table des valeurs formatées
vals.main = {} -- valeurs sans qualficatif P518
for i, j in pairs(materials) do
local val = wikidata.formatSnak(j.mainsnak, {speciallabels = speciallabels})
if not j.qualifiers or not j.qualifiers.P518 then
table.insert(vals.main, val)
else for k, qualif in pairs(j.qualifiers.P518) do
local key = wikidata.getid(qualif)
if not vals[key] then
vals[key] = {}
end
table.insert(vals[key], val)
end end
end
local mainstr, supportstr, withpartstr -- supportstr pour le support de peintrue, withpartstr, pour celle avec un autre qualificateur P518
mainstr = linguistic.conj(vals.main)
vals.main = nil
if vals['Q861259'] then
supportstr = ' sur ' .. linguistic.conj(vals['Q861259'])
vals['Q861259'] = nil
end
local withpart = {} -- table des données contenant un qualificatif P518, sauf "support de peinture"
for part, materials in pairs(vals) do
table.insert(withpart, wikidata._getLabel(part) .. ' : ' .. linguistic.conj(materials))
end
withpartstr = linguistic.conj(withpart, 'comma')
if mainstr or supportstr then
mainstr = (mainstr or '').. (supportstr or '')
end
mainstr = linguistic.conj({mainstr, withpartstr}, 'comma')
return wikidata.addLinkback(mainstr, item, 'P186') .. wikidata.addtrackingcat('P186')
end
return p