Module:Utilitaire Wikidata : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
m (A changé le niveau de protection pour « Module:Utilitaire Wikidata » ([Modifier=Autoriser uniquement les utilisateurs autopatrolled] (infini) [Renommer=Autoriser uniquement les administrateurs] (infini)))
 
(21 révisions intermédiaires par 3 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
 
-- Module de requêtes Wikidata de plus haut niveau que Module:Wikidata
 
-- Module de requêtes Wikidata de plus haut niveau que Module:Wikidata
 
local p = {}
 
local p = {}
local wikidata = require "Module:Wikidata"
+
local wd = require "Module:Wikidata"
  
local function keydate (event)
+
function p.keydate (event, item)
if type(event) ~= 'string' then
+
if type(event) == 'table' then
return error('event should be a string starting with a P or S, datatype is ' .. type(event))
+
for i, j in pairs(event) do
end
+
local s = p.keydate(j)
if string.sub(event, 1, 1) == 'Q' then -- on demande un élément utilisé dans P:P793 (événement clé)
+
if s then
return  wikidata.getTheDate{property = 'P793', targetvalue = event, addcat = true, item = item}
+
return s
 +
end
 +
end
 +
elseif type(event) ~= 'string' then
 +
return error('event should be a string starting with a P or S, datatype is ' .. type(event))
 +
elseif 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é
 
elseif string.sub(event, 1, 1) == 'P'  then -- on demande une propriété
return wikidata.formatAndCat{property = event, item = item}
+
return wd.formatAndCat{property = event, entity = item}
 
else
 
else
 
return error('event string should start with P or S, is "' .. event .. '"')
 
return error('event string should start with P or S, is "' .. event .. '"')
Ligne 16 : Ligne 22 :
 
end
 
end
  
function p.keydate(events)
+
function p.maindate(entity)
if type(events) == 'nil' then
+
-- essaye P580/P582
return nil
+
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
 
end
if type(events) == 'string' then
+
 
return keydate(events)
+
if str then
elseif type(events) == 'table' then
+
return str
for i, j in pairs(events) do
 
local val = keydate(j)
 
if val then
 
return val
 
end
 
end
 
 
end
 
end
end
+
-- défaut : P585
 
+
return wd.wikidataDate('P585', entity)
function p.formatAndCat(args)
 
return wikidata.formatAndCat(args)
 
 
end
 
end
  
 
return p
 
return p

Version actuelle datée du 17 mai 2017 à 13:46

La documentation pour ce module peut être créée à Module:Utilitaire Wikidata/doc

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

function p.keydate (event, item)
	if type(event) == 'table' then
		for i, j in pairs(event) do
			local s = p.keydate(j)
			if s then
				return s
			end
		end
	elseif type(event) ~= 'string' then
		 return error('event should be a string starting with a P or S, datatype is ' .. type(event))
	elseif 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