Module:User:Wyang/yue-check-pron

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

This is a private module sandbox of Wyang, for their own experimentation. Items in this module may be added and removed at Wyang's discretion; do not rely on this module's stability.


local export = {}
local md = require("Module:User:Wyang/yue-monosyllabic").data
local pd = require("Module:User:Wyang/yue-polysyllabic").data

local function format_han(text, nolink) return '<span class="Hani" lang="zh" style="font-size:150%">' .. (nolink and text or '[[' .. text .. ']]') .. '</span>' end

function export.make(data)
	local result = {}
	for word, readings in pairs(pd) do
		i = 0
		reading = mw.text.split(readings, " ")
		for ch in mw.text.gsplit(word, "") do
			if not mw.ustring.find(ch, "[…,·%-]") then
				i = i + 1
				if not reading[i] then
					table.insert(result, "* unequal # of characters and Jyutping syllables in " ..
						format_han(word) .. " (''" .. readings .. "'')")
				else
					local ref = md[ch]
					if ref and not ref[reading[i]] then
						local temp = {}
						for chr, _ in pairs(ref) do
							table.insert(temp, chr)
						end
						table.insert(result, "* " .. format_han(ch, true) .. " (''" .. reading[i] .. "'') in " .. 
							format_han(word) .. " (''" .. readings .. "'') not found in " .. 
							format_han(ch) .. " (''" .. table.concat(temp, ", ") .. "'')")
					end
				end
			end
		end
	end
	table.sort(result)
	return table.concat(result, "\n")
end

return export