Modulo:Codice statistico: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
+LAU
m modulo no globals obsoleto
 
(23 versioni intermedie di un altro utente non mostrate)
Riga 3:
]]--
 
require('Modulo:No globalsstrict')
 
local getArgs = require('Modulo:Arguments').getArgs
local mWikidata = require('Modulo:Wikidata')
 
-- Funzione di formattazione del codice municipale austriaco (Statistik Austria).
local p = {}
--
 
-- @param {string} id
-- Funzione di formattazione del codice municipale austriaco (Statistik Austria)
-- @return {string}
local function formatP964(id)
local formatted_id = string.gsub(id, "'(%d)(%d%d)(%d%d)"', "'%1 %2 %3"')
return string.format('[http://www.statistik.at/blickgem/gemDetail.do?gemnr=%s %s]', id, formatted_id)
end
 
-- Funzione di formattazione del codice municipale tedesco (Statistisches Bundesamt).
--
-- @param {string} id
-- @return {string}
local function formatP439(id)
local formatted_id = string.gsub(id, "'(%d%d)(%d)(%d%d)(%d%d%d)"', "'%1 %2 %3 %4"')
return string.format('[http://www.statistik-portal.de/Statistik-Portal/gemeindeverz.asp?G=%s %s]', id, formatted_id)
end
 
-- Funzione di formattazione del codice dei distretti tedesco (Statistisches Bundesamt).
--
-- @param {string} id
-- @return {string}
local function formatP440(id)
return string.gsub(id, "'(%d%d)(%d)(%d%d)"', "'%1 %2 %3"')
end
 
-- Funzione di formattazione del codice INSEE
-- (Institut national de la statistique et des études économiques).
--
-- @param {string} id
-- @return {string}
local function formatP374(id)
return string.format('[http://www.insee.fr/fr/themes/dossier_complet.asp?codgeo=COM-%s %s]', id, id)
end
 
-- Funzione di formattazione del codice municipale IBGE
-- (Instituto Brasileiro de Geografia e Estatística).
--
-- @param {string} id
-- @return {string}
local function formatP1585(id)
return string.format('[http://cidades.ibge.gov.br/xtras/perfil.php?codmun=%s %s]', id, id)
end
 
-- Funzione di formattazione del codice KSH (Központi Statisztikai Hivatal).
--
-- @param {string} id
-- @return {string}
local function formatP939(id)
return string.format('[http://www.ksh.hu/apps/hntr.telepules?p_id=%s %s]', id, id)
end
 
-- Funzione di confronto predefinita per le categorie Wikidata.
--
-- @param {string} wdval
-- @param {string} userval
-- @return {boolean}
local function compareDefault(wdval, userval)
return string.gsub(wdval, ' ', '') == string.gsub(userval, ' ', '')
end
 
-- Funzione di confronto del codice OFS per le categorie Wikidata.
--
-- @param {string} wdval
-- @param {string} userval
-- @return {boolean}
local function compareP771(wdval, userval)
wdval = string.gsub(wdval, ' ', '')
userval = string.gsub(userval, ' ', '')
return wdval == userval or (tonumber(userval) and wdval == string.format('%04d', userval))
end
 
Line 35 ⟶ 83:
local statCodes = {
AUT = {
default = { prop = 'P964', catprefix = 'Codice municipale austriaco', format = formatP964 }
},
BEL = {
default = { prop = 'P1567' }
},
BRA = {
default = { prop = 'P1585', format = formatP1585 }
},
CHE = {
default = { prop = 'P771', catprefixcompare = 'Codice OFS'compareP771 }
},
CHN = {
default = { prop = 'P442' }
},
CZE = {
default = { prop = 'P782', catprefix = 'Codice LAU' }
},
DEU = {
["'1"'] = {}, -- disabilitato
["'3"'] = { prop = 'P440', catprefix = 'Codice dei distretti tedesco', format = formatP440 },
default = { prop = 'P439', catprefix = 'Codice municipale tedesco', format = formatP439 }
},
DNK = {
default = { prop = 'P1168' }
},
ESP = {
default = { prop = 'P772', catprefix = 'Codice INE' }
},
FRA = {
["'1"'] = { prop = 'P2585', catprefix = 'Codice regione INSEE' },
["'2"'] = { prop = 'P2586', catprefix = 'Codice dipartimento INSEE' },
["4"'3'] = { prop = 'P2506', catprefix = 'Codice cantone INSEEP3423' },
default['4'] = { prop = 'P374P2506', catprefix = 'Codice INSEE'}, format = formatP374 }
default = { prop = 'P374', format = formatP374 }
},
HUN = {
default = { prop = 'P939', format = formatP939 }
},
ITA = {
default = { prop = 'P635', catprefix = 'Codice ISTAT' }
},
NLD = {
default = { prop = 'P382' }
},
NOR = {
default = { prop = 'P2504' }
},
UKR = {
default = { prop = 'P1077' }
}
}
 
-- Restituisce la categoria Wikidata appropriata in base
-- al valore utente, a quello su Wikidata e al tipo di codice.
--
-- @param {string} userval
-- @param {string} wdval
-- @param {table} code
-- @return {string}
local function getWikidataCategory(userval, wdval, code)
local cat
-- consente di definire funzioni di confronto per proprietà specifiche
local comparefunc = code.compare or compareDefault
 
if userval then
if not wdval then
cat = string.format('%s assente su Wikidata', code.catprefixprop)
elseif string.gsubcomparefunc(wdval, ' ', '') == string.gsub(userval, ' ', '') then
cat = code.catuguali and string.format('%s uguale asu Wikidata', code.catprefixprop)
else
cat = string.format('%s differente dasu Wikidata', code.catprefixprop)
end
elseif wdval then
cat = string.format('%s lettoletta da Wikidata', code.catprefixprop)
end
 
return cat and string.format('[[Categoria:%s]]', cat) or ''
end
 
-- =============================================================================
-- Restituisce una tabella HTML con i codici statistici configurati
-- Funzioni esportate
-- =============================================================================
 
local p = {}
 
-- Funzione di utilità per il manuale, restituisce una tabella HTML
-- con i codici statistici configurati.
function p.report()
local tableNode
Line 104 ⟶ 195:
:tag('th')
:wikitext('Proprietà Wikidata')
:done()
:tag('th')
:wikitext('Dati letti')
:done()
 
Line 110 ⟶ 204:
for key, value in pairs(codes) do
if value.prop then
local catLetto = value.prop .. ' letta da Wikidata'
local pagesInCat = mw.site.stats.pagesInCategory(catLetto, 'pages')
tableNode
:tag('tr')
:tag('td')
:wikitext(mw.wikibase.getLabel(value.catprefixprop))
:done()
:tag('td')
Line 122 ⟶ 218:
:done()
:tag('td')
:wikitext(string.format('[[d:p:%s|%s (%s)]]',
value.prop, mWikidata._getLabel( { value.prop } ), value.prop))
:done()
:tag('td')
:css('text-align', 'right')
:wikitext(string.format('[[:Categoria:%s|%s]]', catLetto, pagesInCat))
:done()
end
Line 131 ⟶ 232:
end
 
-- PerFunzione per l'utilizzo da un altro modulo.
function p._main(args)
local code, userval, wdval, formatted_userval, formatted_wdval
Line 155 ⟶ 256:
-- codice presente e abilitato
if code and code.prop then
-- valore letto da Wikidata
wdval = mWikidata._getProperty({ code.prop, from = args.from, n = 1 })
formatted_wdval = (wdval and code.format) and code.format(wdval) or wdval
Line 169 ⟶ 270:
end
 
-- Entry-pointFunzione per il template {{Codice statistico}}.
function p.main(frame)
return p._main(getArgs(frame, { parentOnly = true }))
end