Module:Infobox getal
Uit Wiki Raamsdonks Erfgoed
Module voor sjabloon:Infobox getal.
-- Module voor [[Sjabloon:Infobox getal]]
local p = {}
local function link(number, label)
if not label then
label = number
end
return '[[' .. number .. ' (getal)|' .. label .. ']] '
end
local function breed(number)
local decade = math.floor(number / 10)
local ten = decade * 10
local digit = number - math.floor(number/10)*10 -- math.mod is inaccurate!
local r = ''
if decade ~= 0 then
r = link(ten - 1, '<')
end
for i = 0, 9 do
if i == digit then
r = r .. "'''" .. number .. "''' "
else
r = r .. link(ten + i)
end
end
r = r .. link(ten + 10, '>')
return r
end
local function baseConvert(number, base, digits)
if number < 0 then
return '' -- error
end
if base <= 0 or base > #digits then
return '' -- error
end
if number < base then
return mw.ustring.sub(digits, number + 1, number + 1)
end
-- there is no mw.ustring.reverse() so we use a table
local t = {}
local i = 1
while number > 0 do
local q = math.floor(number / base)
local r = number % base + 1
t[i] = mw.ustring.sub(digits, r, r)
number = q
i = i + 1
end
local s = ''
for j = #t, 1, -1 do
s = s .. t[j]
end
return s
end
local WESTERN = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local function binary(i)
return baseConvert(i, 2, WESTERN)
end
local function octal(i)
return baseConvert(i, 8, WESTERN)
end
local function duodecimal(i)
return baseConvert(i, 12, WESTERN)
end
local function hexadecimal(i)
return string.format("%X", i)
end
-- for Roman and Armenian numerals
local function nonPositionalDigit(tab, number, div)
if number < div then
return ''
end
return tab[math.floor(number / div) % (#tab + 1)] or ''
end
local ro4 = {'M', 'MM', 'MMM', 'MMMM'} -- thousands
local ro3 = {'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'} -- hundreds
local ro2 = {'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'} -- tens
local ro1 = {'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'} -- ones
local function roman(i)
if i > 0 and i < 5000 then
local ro =
nonPositionalDigit(ro4, i, 1000) ..
nonPositionalDigit(ro3, i, 100) ..
nonPositionalDigit(ro2, i, 10) ..
nonPositionalDigit(ro1, i, 1)
return ro
else
return ''
end
end
local INDIC = "٠١٢٣٤٥٦٧٨٩"
local function indic(i)
return baseConvert(i, 10, INDIC)
end
local ar5 = {'Օ', 'Ֆ'} -- ten-thousands
local ar4 = {'Ռ', 'Ս', 'Վ', 'Տ', 'Ր', 'Ց', 'Ւ', 'Փ', 'Ք'} -- thousands
local ar3 = {'Ճ', 'Մ', 'Յ', 'Ն', 'Շ', 'Ո', 'Չ', 'Պ', 'Ջ'} -- hundreds
local ar2 = {'Ժ', 'Ի', 'Լ', 'Խ', 'Ծ', 'Կ', 'Հ', 'Ձ', 'Ղ'} -- tens
local ar1 = {'Ա', 'Բ', 'Գ', 'Դ', 'Ե', 'Զ', 'Է', 'Ը', 'Թ'} -- ones
local function armenian(i)
if i > 0 and i < 30000 then
local ar =
nonPositionalDigit(ar5, i, 10000) ..
nonPositionalDigit(ar4, i, 1000) ..
nonPositionalDigit(ar3, i, 100) ..
nonPositionalDigit(ar2, i, 10) ..
nonPositionalDigit(ar1, i, 1)
return ar
else
return ''
end
end
local CHINESE = "一二三四五六七八九" -- 1..9
local CHINESE_FORMAL = "壹貳参肆伍陸柒捌玖" -- 1..9
local function chinese(i)
local r
if i == 141 then
r = "一百四十一"
elseif i == 10 then
r = "十,拾"
elseif i >= 1 and i <= 9 then
r = mw.ustring.sub(CHINESE, i, i) .. "<br />" ..
mw.ustring.sub(CHINESE_FORMAL, i, i) .. " (formeel schrift)"
else
r = ''
end
return r
end
local GREEK = "αβγδε_ζηθ" -- numbers 1..9 except 6
local function greek(i)
local r
if i == 6 then
r = "Ϝʹ of ςʹ of στʹ"
elseif i >= 1 and i <= 9 then
r = mw.ustring.sub(GREEK, i, i) .. 'ʹ'
else
r = ''
end
return r
end
local HEBREW = "אבגדהוזחט" -- numbers 1..9
local function hebrew(i)
local r
if i == 300 then
r = 'ש'
elseif i == 10 then
r = 'י (jod)'
elseif i >= 1 and i <= 9 then
r = mw.ustring.sub(HEBREW, i, i)
else
r = ''
end
return r;
end
local DEVANAGARI = "०१२३४५६७८९" -- digits 0..9
local function devanagari(i)
return baseConvert(i, 10, DEVANAGARI)
end
local TAMIL = "௧௨௩௪௫௬௭௮௯" -- 1..9
local function tamil(i)
local r
if i >= 1 and i <= 9 then
r = mw.ustring.sub(TAMIL, i, i)
else
r = ''
end
return r
end
local THAI = "๑๒๓๔๕๖๗๘๙" -- 1..9
local function thai(i)
local r
if i == 10 then
r = '๑๐'
elseif i >= 1 and i <= 9 then
r = mw.ustring.sub(THAI, i, i)
else
r = ''
end
return r
end
function p.main(frame)
frame = frame:getParent() -- intended to be called via a template
-- Voor welk getal?
local numberStr = frame.args.getal or frame.args[1]
if not numberStr or numberStr == '' then
numberStr = mw.title.getCurrentTitle().subpageText
end
numberStr = string.gsub(numberStr, "^([%d%.]+).*$", "%1")
local number = tonumber(numberStr)
if not number then
return ''
end
if number > 9999 then
numberStr = '{{formatnum:' .. number .. '}}'
end
local r = '{{Infobox generiek' ..
'| kop = ' .. numberStr ..
'| breed = ' .. breed(number) ..
'| main1 = [[Natuurlijk getal|Natuurlijke getallen]] — [[Geheel getal|Gehele getallen]]' ..
'| kop1 = Informatie' ..
'| head1_1 = [[Hoofdtelwoord]] | item1_1 = {{{kardinaal|}}}' ..
'| head1_2 = [[Rangtelwoord]] | item1_2 = {{{ordinaal|}}}' ..
'| head1_3 = [[Priemfactor]]en | item1_3 = {{{priemfactor|}}}' ..
'| head1_4 = [[Deler]]s | item1_4 = {{{deler|}}}' ..
'| head1_5 = [[Binair talstelsel|Binair]] | item1_5 = ' .. binary(number) ..
'| head1_6 = [[Octaal talstelsel|Octaal]] | item1_6 = ' .. octal(number) ..
'| head1_7 = [[Twaalftallig stelsel|Twaalftallig]] | item1_7 = ' .. duodecimal(number) ..
'| head1_8 = [[Hexadecimaal talstelsel|Hexadecimaal]] | item1_8 = ' .. hexadecimal(number) ..
'| head2_1 = In [[Romeinse cijfers]] | item2_1 = ' .. roman(number) ..
'| head2_2 = [[Arabisch-Indische cijfers|Arabisch-Indisch]] | item2_2 = ' .. indic(number) ..
'| head2_3 = [[Armeense cijfers|Armeens]] | item2_3 = ' .. armenian(number) ..
'| head2_4 = [[Chinese cijfers|Chinees]] | item2_4 = ' .. chinese(number) ..
'| head2_5 = [[Griekse cijfers|Grieks]] | item2_5 = ' .. greek(number) ..
'| head2_6 = [[Hebreeuwse cijfers|Hebreeuws]] | item2_6 = ' .. hebrew(number) ..
'| head2_7 = [[Indiase cijfers|Devanagari (Indiaas)]] | item2_7 = ' .. devanagari(number) ..
'| head2_8 = [[Tamil (taal)|Tamil]] | item2_8 = ' .. tamil(number) ..
'| head2_9 = [[Thaise cijfers|Thais]] | item2_9 = ' .. thai(number) ..
'| portaal = Wiskunde' ..
'}}'
r = frame:preprocess(r)
return r
end
return p