« Module:Utilitaire Wikidata » : 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 5 : Ligne 5 :
local function keydate (event)
local function keydate (event)
if type(event) ~= 'string' then
if type(event) ~= 'string' then
return error('event should be string starting with P or S')
return error('event should be a string starting with a P or S, datatype is ' .. type(event))
end
end
if string.sub(event, 1, 1) == 'Q' then -- on demande un élément utilisé dans P:P793 (événement clé)
if string.sub(event, 1, 1) == 'Q' then -- on demande un élément utilisé dans P:P793 (événement clé)
Ligne 12 : Ligne 12 :
return wikidata.formatAndCat{property = event, item = item}
return wikidata.formatAndCat{property = event, item = item}
else
else
return error('event should be string starting with P or S')
return error('event string should start with P or S, is "' .. event .. '"')
end
end
end
end


function p.keydate(events)
function p.keydate(events)
if type(event) == nil then
if type(events) == 'nil' then
return nil
return nil
end
end
if type(events) == 'string' then
if type(events) == 'string' then
return keydate(event)
return keydate(events)
elseif type(events) == 'table' then
elseif type(events) == 'table' then
for i, j in pairs(events) do
for i, j in pairs(events) do

Version du 19 avril 2015 à 07:13

-- Module de requêtes Wikidata de plus haut niveau que Module:Wikidata local p = {} local wikidata = require "Module:Wikidata"

local function keydate (event) 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 wikidata.getTheDate{property = 'P793', targetvalue = event, addcat = true, item = item} elseif string.sub(event, 1, 1) == 'P' then -- on demande une propriété return wikidata.formatAndCat{property = event, item = item} else return error('event string should start with P or S, is "' .. event .. '"') end 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

function p.formatAndCat(args) return wikidata.formatAndCat(args) end

return p