Module:User:kc kennylau/zh-dial-syn
Jump to navigation
Jump to search
- This module lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of kc kennylau, for his own experimentation. Items in this module may be added and removed at kc kennylau's discretion; do not rely on this module's stability.
local export = {}
local order = {
"Classical", "Formal", "Taxonomic",
"Northeastern Mandarin", "Jilu Mandarin", "Jiaoliao Mandarin",
"Central Plains Mandarin", "Lanyin Mandarin",
"Southwestern Mandarin", "Jianghuai Mandarin",
"Mandarin", "Jin", "Wu", "Xiang", "Gan", "Hakka", "Huizhou",
"Cantonese", "Southern Pinghua", "Northern Pinghua",
"Southern Min", "Puxian Min", "Zhongshan Min", "Eastern Min", "Northern Min", "Central Min", "Shaojiang Min",
"Shehua", "Waxiang", "Jiuxing Yumin", "Xiangnan Tuhua", "Yuebei Tuhua"
}
local ignore = {
}
local ignore_set = {}
for _,lect in ipairs(ignore) do ignore_set[lect] = 1 end
function export.generate()
local d = mw.loadData("Module:zh/data/dial")
local max_len = 0
for _,lect in ipairs(d) do
max_len = math.max(max_len, mw.ustring.len(lect.key))
end
if max_len%4 > 0 then
max_len = max_len+4-max_len%4 -- make it a multiple of 4
end
local function make_line(key,val)
return '\t["'..key..'"]'..string.rep('\t',math.ceil((max_len-mw.ustring.len(key))/4))..'= '..val..',\n'
end
local res = '<div class="NavFrame" style="border:0px; max-width: 100%; text-align:left;">'..
'<div class="NavHead" style="font-size:105%; border:1px solid #aaaaaa; margin-left:-1px; background-color:#CCCCFF; text-align:center;" cellpadding="3">'..
'Auto-generated template for [[Module:zh/data/dial-syn]]</div><div class="NavContent"><pre>\n'..
'local export = {}\n\n'..
'export.list = {\n'..
make_line('title','""')..
make_line('meaning','""')..
make_line('note','""')..
'\t\n'
local groups = {}
for _,branch in ipairs(order) do
groups[branch] = ""
end
for _,lect in ipairs(d) do
if not groups[lect.group] then error("Wrong group for "..lect.key) end
if not ignore_set[lect.key] then
groups[lect.group] = groups[lect.group] .. make_line(lect.key,'{ "" }')
end
end
for i,branch in ipairs(order) do
if i>3 then res = res .. '\t\n' end
res = res .. groups[branch]
end
res = res .. '}\n\nreturn export</pre></div></div>'
return res
end
function export.show()
local d = mw.loadData("Module:zh/data/dial")
local ds = mw.loadData("Module:zh/data/dial-syn").list
local ignore_list = {title=1, meaning=1, note=1}
local r1 = ""
local d_keys = {}
local count1 = 0
local max_len = 0
local longest = ""
for _,lect in ipairs(d) do
count1 = count1 + 1
local curr_len = mw.ustring.len(lect.key)
if curr_len > max_len then
max_len = curr_len
longest = "* <code>"..lect.key.."</code>\n"
elseif curr_len == max_len then
longest = longest.."* <code>"..lect.key.."</code>\n"
end
if not ds[lect.key] and not ignore_set[lect.key] then
r1 = r1 .. "* <code>"..lect.key.."</code>\n"
end
d_keys[lect.key] = true
end
local r2 = ""
local count2 = 0
for key,_ in pairs(ds) do
if not ignore_list[key] then
count2 = count2 + 1
if not d_keys[key] then
r2 = r2 .. "* <code>"..key.."</code>\n"
end
end
end
return "This page checks [[Module:zh/data/dial-syn]] against [[Module:zh/data/dial]].\n\n"..
"Generated by [[Module:User:kc kennylau/zh-dial-syn]].\n\n"..
"Also see [[User:Wpi/zh-dial-list]].\n"..
"=== Missing keys ===\n"..
r1..
"=== Extra keys ===\n"..
r2..
"=== Number of lects in [[Module:zh/data/dial]] ===\n"..
count1.."\n"..
"=== Number of lects in [[Module:zh/data/dial-syn]] ===\n"..
count2.."\n"..
"=== Longest lects (length = "..max_len..") ===\n"..
longest..
"=== Current order (Hardcoded) ===\n"..
table.concat(order," > ").."\n"..
"=== Currently ignoring (Hardcoded) ===\n"..
table.concat(ignore,", ").."\n"..
"=== Correct version ===\n"..
export.generate()
end
return export