Module:User:Yug/char-summary
Jump to navigation
Jump to search
Lua
Documentation for this module may be created at Module:User:Yug/char-summary/doc
Code
--[==[
Based on: [[Module:User:Wyang/char-summary]] → [[Module:User:Justinrleung/char-summary]] → [[Module:User:Yug/char-summary]]
Frequency lists: https://raw.githubusercontent.com/hugolpz/font2svg-linguist/master/data/cmn-lists.json
Kangxi radicals : https://jsfiddle.net/rmvw3ocb/1/
Output: [[User:Yug/kangxi-rads]]
See also: [[:Commons:User:Yug/hz2]], [[:Commons:User:Yug/MOOC]], [[:Commons:Template:Hanzigallery]]
--]==]
require ('strict')
local concat = table.concat
local insert = table.insert
local split = mw.text.split
local match = mw.ustring.match
local format = mw.ustring.format
local codepoint = mw.ustring.codepoint
local titleNew = mw.title.new
local export = {}
-- The 214 Kangxi radicals (U+2F00 to U+2FDF), associated with their CJK unified ideographs.
local radicals_list = {
[ 1] = {'⼀', '一'},
[ 2] = {'⼁', '丨'},
[ 3] = {'⼂', '丶'},
[ 4] = {'⼃', '丿'},
[ 5] = {'⼄', '乙'},
[ 6] = {'⼅', '亅'},
[ 7] = {'⼆', '二'},
[ 8] = {'⼇', '亠'},
[ 9] = {'⼈', '人'},
[ 10] = {'⼉', '儿'},
[ 11] = {'⼊', '入'},
[ 12] = {'⼋', '八'},
[ 13] = {'⼌', '冂'},
[ 14] = {'⼍', '冖'},
[ 15] = {'⼎', '冫'},
[ 16] = {'⼏', '几'},
[ 17] = {'⼐', '凵'},
[ 18] = {'⼑', '刀'},
[ 19] = {'⼒', '力'},
[ 20] = {'⼓', '勹'},
[ 21] = {'⼔', '匕'},
[ 22] = {'⼕', '匚'},
[ 23] = {'⼖', '匸'},
[ 24] = {'⼗', '十'},
[ 25] = {'⼘', '卜'},
[ 26] = {'⼙', '卩'},
[ 27] = {'⼚', '厂'},
[ 28] = {'⼛', '厶'},
[ 29] = {'⼜', '又'},
[ 30] = {'⼝', '口'},
[ 31] = {'⼞', '囗'},
[ 32] = {'⼟', '土'},
[ 33] = {'⼠', '士'},
[ 34] = {'⼡', '夂'},
[ 35] = {'⼢', '夊'},
[ 36] = {'⼣', '夕'},
[ 37] = {'⼤', '大'},
[ 38] = {'⼥', '女'},
[ 39] = {'⼦', '子'},
[ 40] = {'⼧', '宀'},
[ 41] = {'⼨', '寸'},
[ 42] = {'⼩', '小'},
[ 43] = {'⼪', '尢'},
[ 44] = {'⼫', '尸'},
[ 45] = {'⼬', '屮'},
[ 46] = {'⼭', '山'},
[ 47] = {'⼮', '巛'},
[ 48] = {'⼯', '工'},
[ 49] = {'⼰', '己'},
[ 50] = {'⼱', '巾'},
[ 51] = {'⼲', '干'},
[ 52] = {'⼳', '幺'},
[ 53] = {'⼴', '广'},
[ 54] = {'⼵', '廴'},
[ 55] = {'⼶', '廾'},
[ 56] = {'⼷', '弋'},
[ 57] = {'⼸', '弓'},
[ 58] = {'⼹', '彐'},
[ 59] = {'⼺', '彡'},
[ 60] = {'⼻', '彳'},
[ 61] = {'⼼', '心'},
[ 62] = {'⼽', '戈'},
[ 63] = {'⼾', '戶'},
[ 64] = {'⼿', '手'},
[ 65] = {'⽀', '支'},
[ 66] = {'⽁', '攴'},
[ 67] = {'⽂', '文'},
[ 68] = {'⽃', '斗'},
[ 69] = {'⽄', '斤'},
[ 70] = {'⽅', '方'},
[ 71] = {'⽆', '无'},
[ 72] = {'⽇', '日'},
[ 73] = {'⽈', '曰'},
[ 74] = {'⽉', '月'},
[ 75] = {'⽊', '木'},
[ 76] = {'⽋', '欠'},
[ 77] = {'⽌', '止'},
[ 78] = {'⽍', '歹'},
[ 79] = {'⽎', '殳'},
[ 80] = {'⽏', '毋'},
[ 81] = {'⽐', '比'},
[ 82] = {'⽑', '毛'},
[ 83] = {'⽒', '氏'},
[ 84] = {'⽓', '气'},
[ 85] = {'⽔', '水'},
[ 86] = {'⽕', '火'},
[ 87] = {'⽖', '爪'},
[ 88] = {'⽗', '父'},
[ 89] = {'⽘', '爻'},
[ 90] = {'⽙', '爿'},
[ 91] = {'⽚', '片'},
[ 92] = {'⽛', '牙'},
[ 93] = {'⽜', '牛'},
[ 94] = {'⽝', '犬'},
[ 95] = {'⽞', '玄'},
[ 96] = {'⽟', '玉'},
[ 97] = {'⽠', '瓜'},
[ 98] = {'⽡', '瓦'},
[ 99] = {'⽢', '甘'},
[100] = {'⽣', '生'},
[101] = {'⽤', '用'},
[102] = {'⽥', '田'},
[103] = {'⽦', '疋'},
[104] = {'⽧', '疒'},
[105] = {'⽨', '癶'},
[106] = {'⽩', '白'},
[107] = {'⽪', '皮'},
[108] = {'⽫', '皿'},
[109] = {'⽬', '目'},
[110] = {'⽭', '矛'},
[111] = {'⽮', '矢'},
[112] = {'⽯', '石'},
[113] = {'⽰', '示'},
[114] = {'⽱', '禸'},
[115] = {'⽲', '禾'},
[116] = {'⽳', '穴'},
[117] = {'⽴', '立'},
[118] = {'⽵', '竹'},
[119] = {'⽶', '米'},
[120] = {'⽷', '糸'},
[121] = {'⽸', '缶'},
[122] = {'⽹', '网'},
[123] = {'⽺', '羊'},
[124] = {'⽻', '羽'},
[125] = {'⽼', '老'},
[126] = {'⽽', '而'},
[127] = {'⽾', '耒'},
[128] = {'⽿', '耳'},
[129] = {'⾀', '聿'},
[130] = {'⾁', '肉'},
[131] = {'⾂', '臣'},
[132] = {'⾃', '自'},
[133] = {'⾄', '至'},
[134] = {'⾅', '臼'},
[135] = {'⾆', '舌'},
[136] = {'⾇', '舛'},
[137] = {'⾈', '舟'},
[138] = {'⾉', '艮'},
[139] = {'⾊', '色'},
[140] = {'⾋', '艸'},
[141] = {'⾌', '虍'},
[142] = {'⾍', '虫'},
[143] = {'⾎', '血'},
[144] = {'⾏', '行'},
[145] = {'⾐', '衣'},
[146] = {'⾑', '襾'},
[147] = {'⾒', '見'},
[148] = {'⾓', '角'},
[149] = {'⾔', '言'},
[150] = {'⾕', '谷'},
[151] = {'⾖', '豆'},
[152] = {'⾗', '豕'},
[153] = {'⾘', '豸'},
[154] = {'⾙', '貝'},
[155] = {'⾚', '赤'},
[156] = {'⾛', '走'},
[157] = {'⾜', '足'},
[158] = {'⾝', '身'},
[159] = {'⾞', '車'},
[160] = {'⾟', '辛'},
[161] = {'⾠', '辰'},
[162] = {'⾡', '辵'},
[163] = {'⾢', '邑'},
[164] = {'⾣', '酉'},
[165] = {'⾤', '釆'},
[166] = {'⾥', '里'},
[167] = {'⾦', '金'},
[168] = {'⾧', '長'},
[169] = {'⾨', '門'},
[170] = {'⾩', '阜'},
[171] = {'⾪', '隶'},
[172] = {'⾫', '隹'},
[173] = {'⾬', '雨'},
[174] = {'⾭', '靑'},
[175] = {'⾮', '非'},
[176] = {'⾯', '面'},
[177] = {'⾰', '革'},
[178] = {'⾱', '韋'},
[179] = {'⾲', '韭'},
[180] = {'⾳', '音'},
[181] = {'⾴', '頁'},
[182] = {'⾵', '風'},
[183] = {'⾶', '飛'},
[184] = {'⾷', '食'},
[185] = {'⾸', '首'},
[186] = {'⾹', '香'},
[187] = {'⾺', '馬'},
[188] = {'⾻', '骨'},
[189] = {'⾼', '高'},
[190] = {'⾽', '髟'},
[191] = {'⾾', '鬥'},
[192] = {'⾿', '鬯'},
[193] = {'⿀', '鬲'},
[194] = {'⿁', '鬼'},
[195] = {'⿂', '魚'},
[196] = {'⿃', '鳥'},
[197] = {'⿄', '鹵'},
[198] = {'⿅', '鹿'},
[199] = {'⿆', '麥'},
[200] = {'⿇', '麻'},
[201] = {'⿈', '黃'},
[202] = {'⿉', '黍'},
[203] = {'⿊', '黑'},
[204] = {'⿋', '黹'},
[205] = {'⿌', '黽'},
[206] = {'⿍', '鼎'},
[207] = {'⿎', '鼓'},
[208] = {'⿏', '鼠'},
[209] = {'⿐', '鼻'},
[210] = {'⿑', '齊'},
[211] = {'⿒', '齒'},
[212] = {'⿓', '龍'},
[213] = {'⿔', '龜'},
[214] = {'⿕', '龠'},
}
local function hexcodepoint(s, i, j)
return 'U+' .. format('%04X', codepoint(s, i, j), 16)
end
function export.main(frame)
local result = {
'{|class="wikitable sortable" style="font-size:80%;line-height:normal;text-align:center"',
'|+ Priority list for ancient Chinese characters <small>(see source code in [[Module:User:Yug/char-summary]])</small>.',
'|-class="sort-top" style="font-size:smaller"',
-- Columns group at start of header row.
--[==[
'!scope="col" rowspan="2" style="width:54px;padding-left:1px;padding-right:16px"| Han<br /> etymology',
--]==]
-- Column group for ancient styles.
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Shang<br/> oracle<br /> bone',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Shang<br/> bronze',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Western<br /> Zhou<br/> bronze',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Spring &<br /> Autumn<br/> bronze',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Warring<br/> States<br/> bronze',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Shu<br /> slip/silk',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Qin<br /> slip',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| <em>Liushutong</em><br /> big seal',
'!scope="col" class="unsortable" style="width:40px"| <em>Shuowen</em><br /> seal',
-- Column group for modern styles.
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Clerical<br /> Han',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Clerical<br /> Qing',
'!scope="col" class="unsortable" style="width:40px"| Mingti<br /> Kangxi',
'!scope="col" style="width:40px;padding-left:1px;padding-right:16px"| Kangxi<br /> radical',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Caoshu<br /> cursive',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Xingshu<br /> semi-cursive',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Kaishu<br /> (SVG)',
'!scope="col" class="unsortable" style="width:40px"| Kaishu<br /> (PNG)',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Red<br /> order',
'!scope="col" class="unsortable" style="width:40px"| Animated<br /> order',
'!scope="col" class="unsortable" style="width:120px;font-weight:normal"| B&W<br /> order',
'!scope="col" style="width:40px;padding-left:1px;padding-right:16px"| CJK<br /> unified',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Songti',
--[==[
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Mandarin',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Sichuanese',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Cantonese',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Taishanese',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Gan',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Sixian',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Meixian',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Jin',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Min<br /> Bei',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Min<br /> Dong',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Hokkien',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Teochew',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Wu',
'!scope="col" class="unsortable" style="width:40px;font-weight:normal"| Xiang',
--]==]
-- Column-group at end of header row.
'!scope="col" class="unsortable" rowspan="2" style="width:54px"| Sources',
'|-class="sort-top" style="font-size:smaller"',
'!scope="col" colspan="11" style="background:#DDF"| (ancient styles)',
'!scope="col" colspan="11" style="background:#CFC"| (modern styles)',
}
local tick = '|style="font-size:30px;background:#C8C"| ✓'
local cross = '|style="font-size:30px;background:#FCC"| ✘'
for n, s in ipairs(radicals_list) do
local krd, ch = s[1], s[2]
insert(result, '|-')
insert(result, '| [[File:' .. ch .. '-oracle' .. '.svg|40x40px|' .. ch .. '-oracle' .. '.svg]]') -- Shang oracle bone
insert(result, '| [[File:' .. ch .. '-bronze-shang' .. '.svg|40x40px|' .. ch .. '-bronze-shang' .. '.svg]]') -- Shang bronze
insert(result, '| [[File:' .. ch .. '-bronze' .. '.svg|40x40px|' .. ch .. '-bronze' .. '.svg]]') -- West Zhou bronze
insert(result, '| [[File:' .. ch .. '-bronze-spring' .. '.svg|40x40px|' .. ch .. '-bronze-spring' .. '.svg]]') -- Spring & Autumn bronze
insert(result, '| [[File:' .. ch .. '-bronze-warring' .. '.svg|40x40px|' .. ch .. '-bronze-warring' .. '.svg]]') -- Warring States. bronze
insert(result, '| [[File:' .. ch .. '-silk' .. '.svg|40x40px|' .. ch .. '-silk' .. '.svg]]') -- Shu slip/silk
insert(result, '| [[File:' .. ch .. '-slip' .. '.svg|40x40px|' .. ch .. '-slip' .. '.svg]]') -- Qin slip
insert(result, '| [[File:' .. ch .. '-bigseal' .. '.svg|40x40px|' .. ch .. '-bigseal' .. '.svg]]') -- Liushutong Big seal
insert(result, '|style="background:#DFD"| [[File:' .. ch .. '-seal' .. '.svg|40x40px|' .. ch .. '-seal' .. '.svg]]') -- Shuowen seal
insert(result, '|style="background:#FEC"| [[File:' .. ch .. '-clerical-han' .. '.svg|40x40px|' .. ch .. '-clerical-han' .. '.svg]]') -- Clerical Han
insert(result, '|style="background:#FEC"| [[File:' .. ch .. '-clerical' .. '.svg|40x40px|' .. ch .. '-clerical' .. '.svg]]') -- Clerical Qing
insert(result, '|style="background:#DFD"| [[File:' .. ch .. '-mingti-kangxi' .. '.svg|40x40px|' .. ch .. '-mingti-kangxi' .. '.svg]]') -- Mingti Kangxi
insert(result, '!scope="row" data-sort-value="' .. format('%03d', n) .. '"| [[:Category:Radical ' .. format('%03d', n) .. '|<kbd style="font-size:87%">' .. format('%03d', n) .. '</kbd><br /> <big style="font-size:150%;font-family:\'Noto Serif TC\',serif">' .. krd .. '</big><br /> <kbd style="font-size:87%">' .. hexcodepoint(krd) .. '</kbd>]]') -- Kangxi radical
insert(result, '| [[File:' .. ch .. '-caoshu' .. '.svg|40x40px|' .. ch .. '-caoshu' .. '.svg]]') -- Caoshu cursive
insert(result, '| [[File:' .. ch .. '-xingshu' .. '.svg|40x40px|' .. ch .. '-xingshu' .. '.svg]]') -- Xingshu semi-cursive
insert(result, '| [[File:' .. ch .. '-kaishu' .. '.svg|40x40px|' .. ch .. '-kaishu' .. '.svg]]') -- Kaishu regular (SVG)
insert(result, '|style="background:#DFD"| [[File:' .. ch .. '-kaishu' .. '.png|40x40px|' .. ch .. '-kaishu' .. '.png]]') -- Kaishu regular (PNG)
insert(result, '| [[File:' .. ch .. '-red' .. '.png|40x40px|' .. ch .. '-red' .. '.png]]') -- Red order
insert(result, '|style="background:#DFD"| [[File:' .. ch .. '-order' .. '.gif|40x40px|' .. ch .. '-order' .. '.gif]]') -- Animated order
insert(result, '| [[File:' .. ch .. '-bw' .. '.png|120x40px|' .. ch .. '-bw' .. '.png]]') -- B&W order
insert(result, '|style="background:#EEE" data-sort-value="' .. hexcodepoint(ch) .. '"| <kbd style="font-size:87%">[[:Category:Radical ' .. format('%03d', n) .. '-0|' .. format('%03d', n) .. '.0]]</kbd><br /> [[:Category:' .. ch .. '|<big style="font-size:150%;font-family:\'Noto Serif TC\',serif">' .. ch .. '</big><br /> <kbd style="font-size:87%">' .. hexcodepoint(ch) .. '</kbd>]]') -- Unified ideograph
insert(result, '| [[File:' .. ch .. '-songti' .. '.svg|40x40px|' .. ch .. '-songti' .. '.svg]]') -- Songti
insert(result, '|style="background:#DFD;font-size:85%;text-align:left"| [https://xiaoxue.iis.sinica.edu.tw/yanbian?char=' .. ch .. ' sinica TW]<br /> [https://hanziyuan.net/#' .. ch .. ' hanziyuan CN]') -- Sources
--[==[ Disabled for now: too many fetched pages (214), or could be slow
local content = titleNew(ch):getContent()
local sections = split(content, '%-%-%-%-')
local found = nil
for _, section in ipairs(sections) do
if match(section, '== *Chinese *==') then
found = section
break
end
end
insert(result, found and match(found, '{{Han ety[lm]}}') and tick or cross) -- Han etym.
insert(result, found and match(found, '|m=[^%s|]' ) and tick or cross) -- Mandarin
insert(result, found and match(found, '|m%-s=[^%s|]' ) and tick or cross) -- Sichuanese
insert(result, found and match(found, '|c=[^%s|]' ) and tick or cross) -- Cantonese
insert(result, found and match(found, '|c%-t=[^%s|]' ) and tick or cross) -- Taishanese
insert(result, found and match(found, '|g=[^%s|]' ) and tick or cross) -- Gan
insert(result, found and match(found, '|pfs=[^%s|]' ) and tick or cross) -- Sixian
insert(result, found and match(found, '|gd=[^%s|]' ) and tick or cross) -- Meixian
insert(result, found and match(found, '|j=[^%s|]' ) and tick or cross) -- Jin
insert(result, found and match(found, '|mb=[^%s|]' ) and tick or cross) -- Min Bei
insert(result, found and match(found, '|md=[^%s|]' ) and tick or cross) -- Min Dong
insert(result, found and match(found, '|mn=[^%s|]' ) and tick or cross) -- Hokkien
insert(result, found and match(found, '|mn%-t=[^%s|]') and tick or cross) -- Teochew
insert(result, found and match(found, '|w=[^%s|]' ) and tick or cross) -- Wu
insert(result, found and match(found, '|x=[^%s|]' ) and tick or cross) -- Xiang
--]==]
end
insert(result, '|}')
return concat(result, '\n')
end
return export