Module:User:Erutuon/zh

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Lua error in package.lua at line 80: module 'Module:User:Suzukaze-c/zh/data/skeys' not found


export = {}

function export.show(frame)
	local m_sortkeys = mw.loadData("Module:User:Suzukaze-c/zh/data/skeys").skeys
	
	local blocks = {}
	
	for char, sortkey in pairs(m_sortkeys) do
		local radical = mw.ustring.sub(sortkey, 1, 1)
		local codepoint = mw.ustring.codepoint(radical)
		local block = require("Module:Unicode data").lookup_block(codepoint)
		if not blocks[block] then
			blocks[block] = {}
		end
		blocks[block][codepoint] = radical
	end
	
	local dump = {}
	table.insert(dump, "{")
	for block, codepoints in pairs(blocks) do
		table.insert(dump, "\t[\"" .. block .. "\"] = {")
		local i = 0x2F00
		for codepoint, char in require("Module:table").sparseIpairs(codepoints) do
			local radical = mw.ustring.char(i)
			table.insert(dump, "\t\t[" .. codepoint .. "] = \"" .. char .. "\", -- " .. radical)
			i = i + 1
		end
		table.insert(dump, "\t}")
	end
	table.insert(dump, "}")
	
	dump = table.concat(dump, "\n")
	
	return frame:extensionTag{ name = "syntaxhighlight", content = dump, args = { lang = "lua" } }
end

function export.old_show(frame)
	local out = {}
	
	for k, v in pairs(mw.loadData('Module:User:Suzukaze-c/zh/data/skeys').skeys) do
		out[mw.ustring.codepoint(k)] = v
	end
	
	table.sort(out)
	
	--[[
		Number of key-value pairs as determined by this function: 87870.
		Divided into tables of 100 or less: 879 modules.
		500 or less: 176 modules.
		1000 or less: 88 modules.
		2000 or less: 44.
		5000 or less: 18.
	]]
--	mw.log(#require("Module:table").numKeys(out))
	
	-- lowest key in first batch: 13312
	-- in second batch: 131072
	local lowestCodepoint = 135572
	local numberInSubmodule = 500
	
	local printing = {}
	local previousTotal = 0
	local previousKey = lowestCodepoint
	local startingPoint = 66
	local moduleNumber = startingPoint
	
	local ret = "return {"
	table.insert(printing, string.format("\n\nModule:zh-sortkey/data/%03i:\n\n" .. ret, moduleNumber))
	
	local i = 1
	for k, v in require("Module:table").sparseIpairs(out) do
		if k >= lowestCodepoint then
			i = i + 1
			
			if k - previousKey >= numberInSubmodule then
				moduleNumber = moduleNumber + 1
				-- Modules left: 122 (!); 176 total?
				table.insert(printing, string.format("}\n\nNumber of codepoints in previous module: %d\n\nModule:zh-sortkey/data/%03i:\n\n" .. ret, i - previousTotal, moduleNumber))
				previousTotal = i
				previousKey = k
			end
			
			table.insert(printing, '[' .. k .. ']="' .. v .. '",')
		end
	end
	
	table.insert(printing, "}\n\nNumber of codepoints in previous module: " .. i - previousTotal)
	table.insert(printing, "\n\nNumber of modules: " .. moduleNumber - startingPoint )
	
	return table.concat(printing)
end

return export