« Module:Utilitaire Wikidata » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
mAucun résumé des modifications
0x010D (discussion | contributions)
pas vraiment utile d'avoir deux fonctions différentes en fait
Ligne 2 : Ligne 2 :
local p = {}
local p = {}
local wd = require "Module:Wikidata"
local wd = require "Module:Wikidata"
local linguistic = require "Module:Linguistique"
local formatDate = require "Module:Date complexe"
local formatDate = require "Module:Date complexe"


local function keydate (event)
function p.keydate (event, item)
if type(event) == 'table' then
for i, j in pairs(event) do
local s = keydate(j)
if s then
return s
end
end
end
if type(event) ~= 'string' then
if type(event) ~= 'string' then
return error('event should be a string starting with a P or S, datatype is ' .. type(event))
return error('event should be a string starting with a P or S, datatype is ' .. type(event))
Ligne 33 : Ligne 40 :
-- défaut : P585
-- défaut : P585
return wd.wikidataDate('P585', entity)
return wd.wikidataDate('P585', entity)
end
function p.keydate(events)
if type(events) == 'nil' then
return nil
end
if type(events) == 'string' then
return keydate(events)
elseif type(events) == 'table' then
for i, j in pairs(events) do
local val = keydate(j)
if val then
return val
end
end
end
end
end


return p
return p

Version du 21 mars 2016 à 09:31

-- Module de requêtes Wikidata de plus haut niveau que Module:Wikidata local p = {} local wd = require "Module:Wikidata" local formatDate = require "Module:Date complexe"

function p.keydate (event, item) if type(event) == 'table' then for i, j in pairs(event) do local s = keydate(j) if s then return s end end end if type(event) ~= 'string' then return error('event should be a string starting with a P or S, datatype is ' .. type(event)) end if string.sub(event, 1, 1) == 'Q' then -- on demande un élément utilisé dans P:P793 (événement clé) return wd.getTheDate{property = 'P793', targetvalue = event, addcat = true, entity = item} elseif string.sub(event, 1, 1) == 'P' then -- on demande une propriété return wd.formatAndCat{property = event, entity = item} else return error('event string should start with P or S, is "' .. event .. '"') end end

function p.maindate(entity) -- essaye P580/P582 local startpoint = wd.wikidataDate('P580', entity, {linkback = "-"}) local endpoint = wd.wikidataDate('P582', entity, {linkback = "-"}) local str if startpoint or endpoint then str = (startpoint or ) .. ' - ' .. (endpoint or ) str = wd.addLinkback(str, entity, 'P582') end

if str then return str end -- défaut : P585 return wd.wikidataDate('P585', entity) end

return p