« Module:Matériau » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Aucun résumé des modifications
0x010D (discussion | contributions)
mAucun résumé des modifications
Ligne 22 : Ligne 22 :
local function addStatement(statement) -- ajout d'un chaîne à la table des valeurs
local function addStatement(statement) -- ajout d'un chaîne à la table des valeurs
-- valeur de base
-- 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
if (not statement.qualifiers) or (not statement.qualifiers.P518) then
table.insert(withoutP518, str)
table.insert(withoutP518, statement)
return
return
end
end
Ligne 33 : Ligne 30 :
local key = wikidata.getid(qualif)
local key = wikidata.getid(qualif)
withP518[key] = withP518[key] or {}
withP518[key] = withP518[key] or {}
table.insert(withP518[key], mainid)
table.insert(withP518[key], statement)
end
end
end
end
Ligne 41 : Ligne 38 :


-- concaténation des différentes tables de valeur
-- concaténation des différentes tables de valeur
local function formatVals(ids, args)
local function formatVals(statements)
local t = {}
local t = {}
for i, id in pairs(ids) do
local args = {speciallabels = speciallabels}
table.insert(t, wikidata.formatEntity(id, args))
for i, statement in pairs(statements) do
table.insert(t, wikidata.formatStatement(statement, args))
end
end
return linguistic.conj(t)
return linguistic.conj(t)
Ligne 50 : Ligne 48 :
--- valeurs sans qualificatifs
--- valeurs sans qualificatifs
local mainstr = linguistic.conj(withoutP518)
local mainstr = formatVals(withoutP518)


--- valeurs avec P518 utilisant la préposition "sur"
--- valeurs avec P518 utilisant la préposition "sur"
Ligne 75 : Ligne 73 :
-- concaténation finale
-- concaténation finale
mainstr = linguistic.conj({mainstr, withpartstr}, 'comma')
mainstr = linguistic.conj({mainstr, withpartstr}, 'comma')
 
if (args.linkback ~= '-') then
return mainstr
mainstr = wikidata.addLinkback(mainstr, item, 'P186')
end
return mainstr .. wikidata.addtrackingcat('P186')
end
end
return p
return p

Version du 27 août 2015 à 08:55

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 = 'huile', Q22731 = 'pierre', Q4259259 = '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 if (not statement.qualifiers) or (not statement.qualifiers.P518) then table.insert(withoutP518, statement) return end

for _, qualif in pairs(statement.qualifiers.P518) do local key = wikidata.getid(qualif) withP518[key] = withP518[key] or {} table.insert(withP518[key], statement) end end for i, j in pairs(materials) do addStatement(j) end

-- concaténation des différentes tables de valeur local function formatVals(statements) local t = {} local args = {speciallabels = speciallabels} for i, statement in pairs(statements) do table.insert(t, wikidata.formatStatement(statement, args)) end return linguistic.conj(t) end

--- valeurs sans qualificatifs local mainstr = formatVals(withoutP518)

--- valeurs avec P518 utilisant la préposition "sur" local supportstr if withP518['Q861259'] then supportstr = ' sur ' .. formatVals(withP518['Q861259']) withP518['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 str = wikidata.formatEntity(part, {link = '-'}) str = str .. ' en ' .. formatVals(materials) table.insert(strtable, str) end withpartstr = linguistic.conj(strtable, 'comma')

-- concaténation finale mainstr = linguistic.conj({mainstr, withpartstr}, 'comma') if (args.linkback ~= '-') then mainstr = wikidata.addLinkback(mainstr, item, 'P186') end return mainstr .. wikidata.addtrackingcat('P186') end return p