Pergi ke kandungan

Modul:sandbox

Daripada Wikikamus

Module sandbox for tests. The main function is show.

If you want to keep your test module as private, please create page in format: Module:User:(username)/(module_name).


Invocation section

[sunting]

[ "aus-wdj", "paa-tkw", "nai-ckn", "sai-mur", "paa-mai", "sai-tyu", "aus-jar", "qfa-adm", "aav", "qfa-dny", "sai-car", "sai-hrp", "sai-crn", "nai-ttn", "nai-wtq", "paa-yam", "khi-tuu", "sai-chc", "nai-mdu", "paa-ram", "nai-xin", "nai-ker", "sai-ctc", "paa-eng", "map", "paa-asa", "paa-nim", "chi", "sai-wic", "awd", "sai-ara", "nic", "nai-tot", "aus-wor", "aql", "sai-cah", "sai-jir", "paa-nbo", "dra", "paa-spk", "khi-kxa", "sai-guh", "nai-ykn", "ssa", "nai-len", "aus-pam", "aqa", "nai-miz", "sai-zam", "qfa-kor", "sai-jiv", "qfa-kad", "nai-chu", "wak", "nai-klp", "paa-lkp", "paa-pau", "paa-sbo", "azc", "sai-bor", "qfa-ain", "paa-kiw", "aus-nyu", "euq", "qfa-yuk", "nai-you", "paa-yua", "sai-zap", "cau-nec", "cdd", "sai-tuc", "qfa-tyn", "tuw", "qfa-hur", "aus-arn", "sai-pat", "nai-kta", "esx", "sai-nad", "sai-aym", "trk", "sai-mje", "qwe", "ccs", "myn", "paa-arf", "paa-kwm", "sai-mgc", "nai-yuc", "sai-otm", "aus-tnk", "hmx", "nai-sca", "sai-cpc", "cau-nwc", "auf", "sai-wit", "iro", "sai-nmk", "paa-egb", "paa-brd", "urj", "nai-plp", "qfa-cka", "tup", "nai-mus", "ine", "qfa-mch", "sai-hkt", "nai-coo", "qfa-tak", "nai-tsi", "sai-mas", "khi-kkw", "afa", "sai-ucp", "aus-yng", "aus-dal", "aus-bub", "paa-bng", "aus-mir", "ngf", "sit", "sai-cho", "omq", "sal", "jpx", "sai-ynm", "aus-gar", "qfa-tor", "sai-bar", "qfa-tap", "qfa-ong", "nai-pal", "hok", "paa-pag", "paa-msk", "paa-lsp", "paa-wpa", "paa-iwm", "qfa-xgs" ]

local export = {}

--[==[function flattenHelp(list, chain)
	table.insert(list, chain["lang"])
	if not chain["ancestors"] then
		return
	end
	flattenHelp(list, chain["ancestors"][1])
end

function flattenChain(chain)
	local list = {}
	flattenHelp(list, chain)
	return list
end

function export.show(frame)
	local m_families = require("Module:families")
	local m_langs = require("Module:languages")
	local fam = m_families.getByCode("inc")
	local kids = fam:getDescendants()
	local chains = {}
	for _,desc in ipairs(kids) do
		--local ch = desc.getAncestorChain and desc:getAncestorChain() or desc.getParentChain and desc:getParentChain() or {desc:getFamily()}
		--local ch = {(desc.getAncestorChain and 1 or 0) .. (next(desc:getParentChain()) and 1 or 0) .. (desc.getFamily and 1 or 0)}
		
		--local ch = next(desc:getParentChain()) and desc:getParentChain() or false
		local ch = desc.getAncestorChain and flattenChain(desc:getAncestorChain()) or false
		ch = ch or {false, desc:getFamily():getCode(), desc:getFamily():getProtoLanguageCode() or false}
		chains[desc:getCode()] = ch
	end
	
	local to_json = require("Module:JSON").toJSON
	return to_json(chains)
end

function export.show(frame)
	local m_families = require("Module:families")
	local m_langs = require("Module:languages")
	local fam = m_families.getByCode("inc")
	local kids = fam:getDescendants()
	local edges = {}
	local chains = {}
	for _,desc in ipairs(kids) do
		if desc.getAncestorChain then
			local ch = desc:getAncestorChain()
			for _,anc in ipairs(ch["ancestors"]) do
				table.insert(edges, {ch["lang"], anc["lang"]})
			end
		else
			chains[desc:getCode()] = {false, desc:getFamily():getCode(), desc:getFamily():getProtoLanguageCode() or false}
		end
	end
	
	local to_json = require("Module:JSON").toJSON
	return to_json(edges)
end


function simplify(chain)
	local parents = {}
	if chain["ancestors"] then
		for _, anc in ipairs(chain["ancestors"]) do
			table.insert(parents, (simplify(anc)))
		end
	else parents = false end
	return {[chain["lang"]] = parents}, chain["lang"]
end

function append(cumuluendTable, addendTable)
	for k,v in ipairs(addendTable) do
		cumuluendTable[k]=v
	end
	return cumuluendTable
end

function keyAppend(cumuluendTable, addendTable, key)
	cumuluendTable[key] = addendTable[key]
end

function export.show(frame)
	local m_families = require("Module:families")
	local m_langs = require("Module:languages")
	local fam = m_families.getByCode("inc")
	local kids = fam:getDescendants()
	local chains = {}
	for _,desc in ipairs(kids) do
		if desc.getAncestorChain then
			keyAppend(chains, simplify(desc:getAncestorChain()))
		end
	end
	
	local to_json = require("Module:JSON").toJSON
	return to_json(chains)
end]==]


function familyCodes()
	local data = mw.loadData("Module:families/data")
	local codes = {}
	for key, _ in pairs(data) do
		table.insert(codes, key)
	end
	return codes
end

function export.show(frame)
	local m_families = require("Module:families")
	local m_langs = require("Module:languages")
	local fams = familyCodes()
	
	local supers = {}
	for _,fam in ipairs(fams) do
		if not m_families.getByCode(fam):getFamily() then table.insert(supers, fam) end
	end
	
	local to_json = require("Module:JSON").toJSON
	return to_json(supers)
end

return export