Modulo:Wikidata: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
così il rank funziona anche in combinazione del parametro n=
aggiunta funzione getStatementByRank, semplificata gestione rank
Riga 32:
end
return prefix .. value['numeric-id']
end
 
-- Ritorna l'n-esimo statement con il rank richiesto, oppure nil se non trovato
function getStatementByRank(claims, n, rank)
iflocal statement then
local currPos = 1
 
for i = 0, #claims do
if statementclaims[i].rank == options.rank then
if currPos == n then
local statement = entity.claims[property][n - 1i]
end break
else end
currPos = currPos + 1
end
elseend
 
return statement
end
Riga 38 ⟶ 56:
end
function formatStatements( options )
function formatStatements( options )
if not options.property then
return formatError( 'property-param-not-provided' )
end
forlocal i,property statement= in pairs( entity.claims[string.lower( options.property)] ) do
--Get entity
Riga 50 ⟶ 69:
end
if (entity.claims == nil) or (not entity.claims[string.lower(options.property)]) then
return '' --TODO error?
end
Riga 71 ⟶ 90:
if options.n then
local n = tonumber( options.n )
localif propertyn and n <= string.lower( options#entity.claims[property] )then
local statement = options.rank and
if n then
getStatementByRank( entity.claims[property], n, options.rank ) or
if options.rank then
entity.claims[property][n - 1]
local i=0
if statement then
local k=0
table.insert( formattedStatements, formatStatement( statement, options ) )
local statement = ""
while i ~= n do
statement = entity.claims[property][k]
if statement then
if statement.rank == options.rank then
i=i+1
k=k+1
else
k=k+1
end
else
i=n
end
end
if statement then
table.insert( formattedStatements, formatStatement( statement, options ) )
end
else
local statement = entity.claims[property][n - 1]
if statement then
table.insert( formattedStatements, formatStatement( statement, options ) )
end
end
end
else
elseif options.rank then
for i, statement in pairs( entity.claims[string.lower(options.property)] ) do
if not options.rank or statement.rank == options.rank then
table.insert( formattedStatements, formatStatement( statement, options ) )
end
end
else
for i, statement in pairs( entity.claims[string.lower(options.property)] ) do
table.insert( formattedStatements, formatStatement( statement, options ) )
end
end
if list_end then table.insert( formattedStatements, list_end ) end
return mw.text.listToText( formattedStatements, options.separator, options.conjunction )
end