Modulo:Check bibcode

Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Check bibcode/man (modifica · cronologia)
Sandbox: Modulo:Check bibcode/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Check bibcode/test (modifica · cronologia · Esegui)
Modulo di supporto al template {{Bibcode}} per la determinazione degli errori del codice id inserito. [1] Quando il valore assegnato non ha il formato corretto, il template restituisce un messaggio di errore insieme al tipo (<type>) di errore riscontrato:
- Analisi bibcode: <type>
Si prevede che i valori del template Bibcode corrispondano a questi requisiti:
- lunghezza = 19 caratteri alfanumerici (<type> = 'lunghezza')
- posizioni dei caratteri (tranne delle eccezioni, le violazioni producono <type> = 'valore')
- 1–4 sono numeri, indicano l'anno della pubblicazione nel campo: 1000 – attuale (<type> = 'anno')
- 5 è un carattere
- 6–8 sono caratteri, e-commerciale (&), o un punto (.) e non può verificarsi &. (<type> = 'pubblicazione')
- 9 è un carattere o un punto
- 10–18 sono caratteri, numeri o punti
- 19 è un carattere o un punto
Per risolvere questo errore, assicurarsi che il valore bibcode assegnato sia corretto.
Note
- ^ 1.2.3 - Bibliographic Identifiers, su The SAO/NASA Astrophysics Data System.
require('strict')
local p = {}
--[[--------------------------< B I B C O D E >--------------------------------------------------------------------
Validates (sort of) a bibcode id.
Format for bibcodes is specified here: http://adsabs.harvard.edu/abs_doc/help_pages/data.html#bibcodes
But, this: 2015arXiv151206696F is apparently valid so apparently, the only things that really matter are length, 19 characters
and first four digits must be a year. This function makes these tests:
length must be 19 characters
characters in position
1–4 must be digits and must represent a year in the range of 1000 – next year
5 must be a letter
6 must be letter, ampersand, or dot (ampersand cannot directly precede a dot; &. )
7–8 must be letter, digit, ampersand, or dot (ampersand cannot directly precede a dot; &. )
9–18 must be letter, digit, or dot
19 must be a letter or dot
]]
local function bibcode (id)
local err_type;
local year;
if 19 ~= id:len() then
err_type = 'lunghezza';
else
year = id:match ("^(%d%d%d%d)[%a][%a&%.][%a&%.%d][%a&%.%d][%a%d%.]+[%a%.]$") --
if not year then -- if nil then no pattern match
err_type = 'valore'; -- so value error
else
local next_year = tonumber(os.date ('%Y'))+1; --get the current year as a number and add one for next year
year = tonumber (year); -- convert year portion of bibcode to a number
if (1000 > year) or (year > next_year) then
err_type = 'anno'; -- year out of bounds
end
if id:find('&%.') then
err_type = 'pubblicazione'; -- journal abbreviation must not have '&.' (if it does its missing a letter)
end
end
end
return err_type;
end
--[=[-------------------------< E N T R Y P O I N T S >------------------------------------------------------
This module is mostly a copy of the bibcode validation used in [[Module:Citation/CS1]]
call this module with:
{{#invoke:check bibcode|check_bibcode|{{{1|}}}}}
where {{{1|}}} is the bibcode
]=]
function p.check_bibcode (frame)
local err_type = bibcode (frame.args[1]);
if err_type then
return '<span style="font-size:100%" class="error citation-comment">Analisi del bibcode: ' .. err_type .. ' ([[Template:Bibcode#Messaggi di errore|aiuto]])</span>';
end
return '';
end
return p;