Diferencia entre revisiones de «Módulo:Wikidata»

mSin resumen de edición
Parametrizando variables externas
Línea 932: Línea 932:


-- Funciones existentes en otros módulos
-- Funciones existentes en otros módulos
function p.obtenerEtiquetaWikidata(entidad)
function p.obtenerEtiquetaWikidata(entidad, fallback)
if not entidad then entidad = Entidad end
if not entidad then entidad = fallback end
if entidad and entidad.labels and entidad.labels.es then
if entidad and entidad.labels and entidad.labels.es then
return entidad.labels.es.value
return entidad.labels.es.value
Línea 939: Línea 939:
end
end


function p.obtenerImagenWikidata(propiedad)
function p.obtenerImagenWikidata(entidad, propiedad)
local imagen, valorImagen, piesDeImagen, k, pieDeImagen
local imagen, valorImagen, piesDeImagen, k, pieDeImagen
if not Entidad then
if not entidad then
return
return
end
end
--  Obtener la primera imagen en Wikidata de la persona
--  Obtener la primera imagen en Wikidata de la persona
local imagen = elementoTabla(Entidad, 'claims', propiedad,1)
local imagen = elementoTabla(entidad, 'claims', propiedad, 1)
if not imagen then
if not imagen then
return
return
end
end
valorImagen =  elementoTabla(imagen, 'mainsnak','datavalue','value')
valorImagen =  elementoTabla(imagen, 'mainsnak', 'datavalue', 'value')
piesDeImagen =  elementoTabla(imagen, 'qualifiers','P2096')
piesDeImagen =  elementoTabla(imagen, 'qualifiers', 'P2096')
-- Encontrar el pie en español
-- Encontrar el pie en español
if piesDeImagen then
if piesDeImagen then
Línea 968: Línea 968:
end
end


function p.propiedad(idPropiedad,opciones)
function p.propiedad(entidad, idPropiedad, opciones)
if Entidad and Entidad.claims and Entidad.claims[idPropiedad] then
if entidad and entidad.claims and entidad.claims[idPropiedad] then
if not opciones then
if not opciones then
opciones = {['linkback']='sí'}
opciones = {['linkback']='sí'}
end
end
opciones.entityId  = Entidad.id
opciones.entityId  = entidad.id
opciones.propiedad = idPropiedad
opciones.propiedad = idPropiedad
valorPropiedad = p.getPropiedad(opciones,Entidad.claims[idPropiedad])
valorPropiedad = p.getPropiedad(opciones, entidad.claims[idPropiedad])
return valorPropiedad
return valorPropiedad
end
end