Modulo:Wikidata: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
rimossa mw.wikibase.getEntity per l'utilizzo di mw.wikibase.getBestStatements e mw.wikibase.getAllStatements
m aggiunti geo-shape e tabular-data, ordine alfabetico datatypes, rinominata property in propertyId come per entityId e nel manuale
Riga 10:
 
-- =============================================================================
-- Non utilizzare mai mw.wikibase.getEntity, per esempio un solo utilizzo di:
-- mw.wikibase.getEntity('Q183') fa aumentare di 7 MB l'utilizzo di memoria
-- fa aumentare di 7 MB l'utilizzo di memoria per Lua ed è estremamentemolto lenta se ripetuta.
-- Gli unici due utilizzi nel modulo sono in getLabel quando si deve specificare
-- una lingua diversa dall'italiano (non usata nelle voci)
-- e in getDatatype (solo per proprietà), non essendoci alternative;.
-- entrambe le funzioni non sono comunque mai usate nelle voci.
-- =============================================================================
 
Riga 44:
datatypes = {
['commonsMedia'] = 'file multimediale su Commons',
['external-id'] = 'identificativo esterno',
['geo-shape'] = 'forma geografica',
['globe-coordinate'] = 'coordinate geografiche',
['math'] = 'espressione matematica',
['monolingualtext'] = 'testo monolingua',
['quantity'] = 'quantità',
['string'] = 'stringa',
['tabular-data'] = 'tabular data',
['time'] = 'data e ora',
['url'] = 'URL',
['external-id'] = 'identificativo esterno',
['wikibase-item'] = 'elemento',
['wikibase-property'] = 'proprietà',
['math'] = 'espressione matematica'
}
}
Riga 422 ⟶ 424:
-- Gli statement restituiti sono eventualmente filtrati in base ai parametri:
-- "rank", "qualifier", "qualifiertype" e "n"
local function getClaims(propertypropertyId, args)
local entityId, claims, filteredClaims
Riga 433 ⟶ 435:
args.rank = args.rank or 'best'
if args.rank == 'best' then
claims = mw.wikibase.getBestStatements(entityId, propertypropertyId)
else
-- statements filtrati per rank
claims = mw.wikibase.getAllStatements(entityId, propertypropertyId)
claims = filterRankValue(claims, args.rank)
end
Riga 514 ⟶ 516:
-------------------------------------------------------------------------------
 
function p._getClaims(propertypropertyId, args)
return getClaims(propertypropertyId, args or {})
end
 
Riga 529 ⟶ 531:
-- la proprietà non esistono, o se per parametri di selezione gli statement sono zero.
function p._getProperty(args, rawTable)
local propertypropertyId, value, claims, ret
 
-- parametri posizionali
propertypropertyId = args[1] and string.upper(args[1])
if not propertypropertyId then
error(i18n.errors['property-param-not-provided'], 2)
end
Riga 543 ⟶ 545:
ret = formatUserValue(value, args)
elseif args.wd ~= 'no' then
claims = getClaims(propertypropertyId, args)
ret = (claims and #claims > 0) and formatStatements(claims, args, rawTable) or nil
end
Riga 553 ⟶ 555:
-- o nil se l'entity o la proprietà non esistono, o se per parametri di selezione non ci sono risultati.
function p._getQualifier(args)
local propertypropertyId, qualifier, value, claims, ret
 
-- parametri posizionali
propertypropertyId = args[1] and string.upper(args[1])
if not propertypropertyId then
error(i18n.errors['property-param-not-provided'], 2)
end
Riga 569 ⟶ 571:
ret = formatUserValue(value, args)
elseif args.wd ~= 'no' then
claims = getClaims(propertypropertyId, args)
if claims and #claims > 0 then
local formattedQualifiers = {}
Riga 585 ⟶ 587:
-- Restituisce l'indice dello statement con il valore richiesto, o nil se non trovato.
function p._indexOf(args)
local ret, propertypropertyId, value, claims
 
-- parametri posizionali
propertypropertyId = args[1] and string.upper(args[1])
if not propertypropertyId then
error(i18n.errors['property-param-not-provided'], 2)
end
Riga 597 ⟶ 599:
end
 
claims = getClaims(propertypropertyId, args)
if claims and #claims > 0 then
args.formatting = 'raw'
Riga 613 ⟶ 615:
-- Restituisce il numero di statement di una proprietà di Wikidata.
function p._N(args)
local propertypropertyId, claims
 
-- parametri posizionali
propertypropertyId = args[1] and string.upper(args[1])
if not propertypropertyId then
error(i18n.errors['property-param-not-provided'], 2)
end
-- get claims
claims = getClaims(propertypropertyId, args)
 
return claims and #claims or 0
Riga 628 ⟶ 630:
-- Restituisce true se la propriertà specificata ha come valore
-- almeno uno tra gli entityId passati come argomento.
function p._propertyHasEntity(propertypropertyId, args)
local statements = p._getProperty({property propertyId, from = args.from, formatting = 'raw' }, true)
if statements then
for _, statement in ipairs(statements) do
Riga 680 ⟶ 682:
-- Restituisce il datatype di una proprietà Wikidata.
function p._getDatatype(args)
local propertypropertyId, entity
 
-- parametri posizionali
propertypropertyId = args[1] and string.upper(args[1])
if not propertypropertyId then
error(i18n.errors['property-param-not-provided'], 2)
end
 
entity = mw.wikibase.getEntity(propertypropertyId)
if not entity then
error(i18n.errors['entity-not-found'], 2)