« Module:Matériau » : différence entre les versions
Apparence
Modèle:Infobox>Zolo un peu plus simple |
Modèle:Infobox>Zolo Aucun résumé des modifications |
||
| Ligne 65 : | Ligne 65 : | ||
str = linguistic.conj({str, partsStr}, 'comma') | str = linguistic.conj({str, partsStr}, 'comma') | ||
if not str then | |||
return nil | |||
end | |||
if (params.linkback ~= '-') then | if (params.linkback ~= '-') then | ||
str = wikidata.addLinkback(str, item, 'P186') | str = wikidata.addLinkback(str, item, 'P186') | ||
Version du 27 août 2015 à 16:14
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, params) -- affiche le matériau en fonction de Property:P186, et de son qualificatif P518 ('s'applique à')
params = params or {}
params.speciallabels = speciallabels
local claims = wikidata.getClaims{entity = item, property = 'P186'}
if not claims then
return nil
end
-- crée trois tables : main pour celle sans P518, support pour celle avec qualif "s'applique à "support de peinture" et "parts" pour les autres
local main, support, parts = {}, {}, {}
local function assignClaim(claim) -- met une claims dans la bonne table
local str = wikidata.formatStatement(claim, params)
if (not claim.qualifiers) or (not claim.qualifiers.P518) then
table.insert(main, str)
else
for _, val in pairs(claim.qualifiers.P518) do
local key = wikidata.getid(val)
if key == 'Q861259' then
table.insert(support, str)
else
parts[key] = parts[key] or {}
table.insert(parts[key], str)
end
end
end
end
for i, j in pairs(claims) do
assignClaim(j)
end
local str -- la chaîne à retourner
-- transforme en chaîne la table des valeurs sans qualificatif
local mainstr = linguistic.conj(main)
-- ajoute le support de peinture (sur toile)
local supportstr = linguistic.conj(support)
if (mainstr and supportstr) then
str = mainstr .. ' sur ' .. supportstr
end
-- chaîne des autres valeurs avec qualifs: [piédestal] = {marbre, bronze} => 'piédestal en marbre et bronze'
local formattedparts = {}
for part, materials in pairs(parts) do
local str = wikidata.formatEntity(part, {link = '-'}) .. ' en ' .. linguistic.conj(materials)
table.insert(formattedparts, str)
end
local partsStr = linguistic.conj(formattedparts, 'comma')
str = linguistic.conj({str, partsStr}, 'comma')
if not str then
return nil
end
if (params.linkback ~= '-') then
str = wikidata.addLinkback(str, item, 'P186')
end
return str .. wikidata.addtrackingcat('P186')
end
return p