« 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)
Aucun résumé des modifications
Ligne 41 : Ligne 41 :


-- concaténation des différentes tables de valeur
-- concaténation des différentes tables de valeur
local function formatVals(ids, args)
local t = {}
for i, id in pairs(ids) do
table.insert(t, wikidata.formatEntity(id, args))
end
return linguistic.conj(t)
end
--- valeurs sans qualificatifs
--- valeurs sans qualificatifs
Ligne 48 : Ligne 55 :
local supportstr
local supportstr
if withP518['Q861259'] then
if withP518['Q861259'] then
local v = withP518['Q861259']
supportstr = ' sur ' .. formatVals(withP518['Q861259'])
supportstr = ' sur ' .. linguistic.conj(v)
withP518['Q861259'] = nil
withP518['Q861259'] = nil
end
end
if mainstr or supportstr then
if mainstr or supportstr then
mainstr = (mainstr or '').. (supportstr or '')
mainstr = (mainstr or '').. (supportstr or '')
Ligne 61 : Ligne 68 :
for part, materials in pairs(withP518) do
for part, materials in pairs(withP518) do
local str = wikidata.formatEntity(part, {link = '-'})
local str = wikidata.formatEntity(part, {link = '-'})
local v = {}
str = str .. ' en ' .. formatVals(materials)
for i, j in pairs(materials) do
table.insert(v, wikidata.formatEntity(j))
end
str = str .. ' en ' .. linguistic.conj(v)
table.insert(strtable, str)
table.insert(strtable, str)
end
end

Version du 27 août 2015 à 07:25

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 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 local function formatVals(ids, args) local t = {} for i, id in pairs(ids) do table.insert(t, wikidata.formatEntity(id, args)) end return linguistic.conj(t) end

--- valeurs sans qualificatifs local mainstr = linguistic.conj(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')

return mainstr end return p