« Module:Utilitaire Wikidata » : différence entre les versions
Nouvelle page : -- Module de requêtes Wikidata de plus haut niveau que Module:Wikidata local p = {} local wikidata = require "Module:Wikidata" local function keydate (event) if string.sub(even... |
Aucun résumé des modifications |
||
| Ligne 4 : | Ligne 4 : | ||
local function keydate (event) | local function keydate (event) | ||
if type(event) ~= 'string' then | |||
return error('event should be string starting with P or S') | |||
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é) | ||
return wikidata.getTheDate{property = 'P793', targetvalue = event, addcat = true, item = item} | return wikidata.getTheDate{property = 'P793', targetvalue = event, addcat = true, item = item} | ||
elseif string.sub(event, 1, 1) == 'P' then -- on demande une propriété | elseif string.sub(event, 1, 1) == 'P' then -- on demande une propriété | ||
return wikidata.formatAndCat{property = event, item = item} | return wikidata.formatAndCat{property = event, item = item} | ||
else | |||
return error('event should be string starting with P or S') | |||
end | end | ||
end | end | ||
function p.keydate(events) | function p.keydate(events) | ||
if type(event) == nil then | |||
return nil | |||
end | |||
if type(events) == 'string' then | if type(events) == 'string' then | ||
return keydate(event) | return keydate(event) | ||
Version du 19 avril 2015 à 07:09
-- 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 string starting with P or S') 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 should be string starting with P or S') end end
function p.keydate(events) if type(event) == nil then return nil end if type(events) == 'string' then return keydate(event) 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