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 = | 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 | 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( | 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 | 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 = | opciones.entityId = entidad.id | ||
opciones.propiedad = idPropiedad | opciones.propiedad = idPropiedad | ||
valorPropiedad = p.getPropiedad(opciones, | valorPropiedad = p.getPropiedad(opciones, entidad.claims[idPropiedad]) | ||
return valorPropiedad | return valorPropiedad | ||
end | end | ||