Diferencia entre revisiones de «Módulo:Wikidata»
Sin resumen de edición |
mSin resumen de edición |
||
| Línea 929: | Línea 929: | ||
return mw.text.listToText( tabla, separador, conjuncion ) .. lapiz | return mw.text.listToText( tabla, separador, conjuncion ) .. lapiz | ||
end | end | ||
end | |||
-- Funciones existentes en otros módulos | |||
function p.obtenerEtiquetaWikidata(entidad) | |||
if not entidad then entidad = Entidad end | |||
if entidad and entidad.labels and entidad.labels.es then | |||
return entidad.labels.es.value | |||
end | |||
end | |||
function p.obtenerImagenWikidata(propiedad) | |||
local imagen, valorImagen, piesDeImagen, k, pieDeImagen | |||
if not Entidad then | |||
return | |||
end | |||
-- Obtener la primera imagen en Wikidata de la persona | |||
local imagen = elementoTabla(Entidad, 'claims', propiedad,1) | |||
if not imagen then | |||
return | |||
end | |||
valorImagen = elementoTabla(imagen, 'mainsnak','datavalue','value') | |||
piesDeImagen = elementoTabla(imagen, 'qualifiers','P2096') | |||
-- Encontrar el pie en español | |||
if piesDeImagen then | |||
for k,pieDeImagen in pairs(piesDeImagen) do | |||
if pieDeImagen.datavalue.value.language == 'es' then | |||
return valorImagen, pieDeImagen.datavalue.value.text | |||
end | |||
end | |||
end | |||
-- Si no hay pie de imagen en español comprueba si hay fecha especificada para la imagen | |||
piesDeImagen = elementoTabla(imagen, 'qualifiers', 'P585') | |||
if piesDeImagen and piesDeImagen[1] then | |||
return valorImagen, nombre .. ' en ' .. require('Módulo:Wikidata/Fecha').FormateaFechaHora(piesDeImagen[1].datavalue.value, {['formatoFecha']='año',['enlace']='no'}) | |||
end | |||
-- Sin pie de imagen en español | |||
return valorImagen | |||
end | |||
function p.propiedad(idPropiedad,opciones) | |||
if Entidad and Entidad.claims and Entidad.claims[idPropiedad] then | |||
if not opciones then | |||
opciones = {['linkback']='sí'} | |||
end | |||
opciones.entityId = Entidad.id | |||
opciones.propiedad = idPropiedad | |||
valorPropiedad = ModuloWikidata.getPropiedad(opciones,Entidad.claims[idPropiedad]) | |||
return valorPropiedad | |||
end | |||
end | |||
function p.esUnValor(entidad, idPropiedad, idaBuscar) | |||
if not entidad or not idPropiedad then | |||
return false | |||
end | |||
local declaracion = elementoTabla(entidad, 'claims', idPropiedad) | |||
local idBuscado | |||
if not declaracion then | |||
return false | |||
end | |||
for k,v in pairs(declaracion) do | |||
idBuscado = elementoTabla(v,'mainsnak','datavalue','value','id') | |||
if idBuscado == idaBuscar then | |||
return true | |||
end | |||
end | |||
return false | |||
end | end | ||
return p | return p | ||