Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Check bibcode
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
require('strict'); --[[--------------------------< 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β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 = 'length'; else year = id:match ("^(%d%d%d%d)[%a][%w&%.][%w&%.][%w&%.][%w.]+[%a%.]$") -- if not year then -- if nil then no pattern match err_type = 'value'; -- 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 = 'year'; -- year out of bounds end if id:find('&%.') then err_type = 'journal'; -- 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 ]=] local function check_bibcode (frame) local err_type = bibcode (mw.text.trim (frame.args[1])); -- trim leading and trailing white space before evaluation if err_type then return '<span style="font-size:100%" class="error citation-comment">Check bibcode: ' .. err_type .. ' ([[Template:Bibcode#Error_messages|help]])</span>'; end return ''; -- return empty string when bibcode appears to be valid end --[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------ ]] return { check_bibcode = check_bibcode, }
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Check bibcode/doc
(
edit
)