Modul:Wikidata utilities: Unterschied zwischen den Versionen

KKeine Bearbeitungszusammenfassung
(umgestellt)
Zeile 1: Zeile 1:
local fw = {}
local fw = {}
local propertiesArray = {}


function fw.checkId( id ) -- only syntax check
function fw.checkId( id ) -- only syntax check
Zeile 64: Zeile 66:


return ar
return ar
end
function fw.getBestStatements( entity, p )
local statements
if type( entity ) == 'string' then
statements = mw.wikibase.getBestStatements( entity, p )
else
statements = entity:getBestStatements( p )
end
if #statements > 0 then
propertiesArray[ p ] = ''
end
return statements
end
end


Zeile 72: Zeile 87:
end
end


local statements
local statements = fw.getBestStatements( entity, p )
if type( entity ) == 'string' then
statements = mw.wikibase.getBestStatements( entity, p )
else
statements = entity:getBestStatements( p )
end


count = count or #statements
count = count or #statements
Zeile 101: Zeile 111:
end
end


local value
local value = getFirstValue( fw.getBestStatements( entity, p ) )
if type( entity ) == 'string' then
value = getFirstValue( mw.wikibase.getBestStatements( entity, p ) )
else
value = getFirstValue( entity:getBestStatements( p ) )
end
if value then
if value then
return value
return value
Zeile 119: Zeile 124:
end
end
local value
local value = getFirstValue( fw.getBestStatements( entity, p ) )
if type( entity ) == 'string' then
value = getFirstValue( mw.wikibase.getBestStatements( entity, p ) )
else
value = getFirstValue( entity:getBestStatements( p ) )
end
if value then
if value then
return value.id
return value.id
Zeile 137: Zeile 137:
end
end


local statements
local statements = fw.getBestStatements( entity, p )
if type( entity ) == 'string' then
statements = mw.wikibase.getBestStatements( entity, p )
else
statements = entity:getBestStatements( p )
end


return getNValues( statements, count or #statements )
return getNValues( statements, count or #statements )
Zeile 152: Zeile 147:
end
end


local statements
local statements = fw.getBestStatements( entity, p )
if type( entity ) == 'string' then
statements = mw.wikibase.getBestStatements( entity, p )
else
statements = entity:getBestStatements( p )
end


local ar = {}
local ar = {}
Zeile 312: Zeile 302:
end
end
return 'error'
return 'error'
end
function fw.getCategories( formatStr )
formatStr = formatStr or '%s'
result = ''
for key, value in pairs( propertiesArray ) do
result = result .. string.format( formatStr, key )
end
return result
end
end


return fw
return fw