Module:kne-xnn-synonyms

Hello, you have come here looking for the meaning of the word Module:kne-xnn-synonyms. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:kne-xnn-synonyms, but we will also tell you about its etymology, its characteristics and you will know how to say Module:kne-xnn-synonyms in singular and plural. Everything you need to know about the word Module:kne-xnn-synonyms you have here. The definition of the word Module:kne-xnn-synonyms will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:kne-xnn-synonyms, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local rsubn = mw.ustring.gsub

-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
	local retval = rsubn(term, foo, bar)
	return retval
end

local function link(text)
	return "]"
end

---------------------------------------------
-- DATA
---------------------------------------------

local lang = "kne"

local data = {
	
	-- supercategories
	
	northern = {
		name = "Northern / Applai",
		short = "n",
		color = "var(--wikt-palette-lime-1)",
		categories = {
			
			--categories
			
			mtprovince = {
				name = "Mt. Province", 
				
				--subcategories
				sagada = {
					name = "Sagada",
					spelling = function(text)
						local output = link(text)
						
						if (text:find("^man")) then
							output = output .. " / " ..link(rsub(text, "^man", "men"))
						end
						if (text:find("")) then
							output = output .. ",<br/><small>(''elderly'')</small> " .. link(rsub(text, "r", "l")) .. " / " .. link(rsub(text, "l", "r"))
						end
						if (text:find("d") or text:find("g") or text:find("G")) then 
							-- Pidlisan: "d" → "ch", "g" → "kh"
							local _pidlisan = rsub(rsub(rsub(rsub(rsub(text, "()g", "%1kh"), "(%fg)", "kh"), "G", "Kh"), "d", "ch"), "D", "Ch")
							
							output = output .. ",<br/><small>(''Pidlisan'')</small> " .. link(_pidlisan)
							
							if (text:find("^man")) then  -- add "men" variant if it has "man"
								output = output .. " / " ..link(rsub(_pidlisan, "^man", "men"))
							end
							if (text:find("")) then -- and r~l alliphony, also sometimes "r" becomes "ch"
								output = output .. " / " .. link(rsub(_pidlisan, "r", "l")) .. " / " .. link(rsub(_pidlisan, "l", "r")) .. " / " .. link(rsub(_pidlisan, "r", "ch"))
							end
						end
						if (text:find("b")) then
							output = output .. ",<br/><small>(''Tanulong'')</small> " .. link(rsub(rsub(text, "b", "gh"), "B", "Gh"))
						end
						
						if (output == link(text)) then
							return nil
						else 
							return output
						end
					end,
				},
				besao = {
					name = "Besao",
				},
			},
		},
	},
	
	southern = {
		name = "Southern / Central",
		short = "s",
		color = "var(--wikt-palette-cyan-1)",
		categories = {
			
			--categories
			
			mtprovince = {
				name = "Mt. Province",
				
				--subcategories
				bauko = {
					name = "Bauko",
					spelling = function(text)
						local output = link(text)
						
						if (text:find("^man")) then
							output = output .. " / " .. link(rsub(text, "^man", "men"))
						end
						if (text:find("nm")) then
							output = output .. ",<br/>" .. link(rsub(text, "nm", "mm"))
						end
						if (text:find("")) then
							output = output .. ",<br/><small>(''Banao'', ''Bila'', ''Otucan'')</small> " .. link(rsub(rsub(text, "s", "h"), "S", "H"))
						end
						
						if (output == link(text)) then
							return nil
						else 
							return output
						end
					end,
				},
				sabangan = {
					name = "Sabangan",
					spelling = function(text)
						local output = link(text)
						
						if (text:find("^man")) then
							output = output .. " / " .. link(rsub(text, "^man", "men"))
						end
						if (text:find("")) then
							output = output .. ",<br/><small>(''elderly'')</small> " .. link(rsub(text, "r", "l")) .. " / " .. link(rsub(text, "l", "r"))
						end
						if (text:find("")) then
							output = output .. ",<br/><small>(''Tambingan'', ''Supang'', ''Data'', ''Lagan'', ''Losad'', ''Poblacion'')</small> " .. link(text)
								.. ",<br/><small>(''Bun-ayan'', ''Pingad'', ''Bao-angan'', ''Camatagan'', ''Napua'', ''Gayang'', ''Capinitan'', ''Busa'', ''Namatec'')</small> " .. link(rsub(rsub(text, "s", "h"), "S", "H"))
						end
						
						if (output == link(text)) then
							return nil
						else 
							return output
						end
					end,
				},
				tadian = {
					name = "Tadian",
					spelling = function(text)
						local output = link(text)
						
						if (text:find("^man")) then
							output = output .. ", <br/><small>(''Batney'', ''Batayan'', ''Duagan'', ''Lubon'', ''Mabalite'', ''Masla'', ''Sumadel'')</small> " .. link(rsub(text, "^man", "men"))
						end
						if (text:find("")) then
							output = output .. ",<br/><small>(''Lubon'')</small> " .. link(rsub(rsub(text, "s", "h"), "S", "H"))
						end
						if (text:find("")) then
							output = output .. ",<br/><small>(''Banaao'', ''Cadad-anan'', ''Cagubatan'', ''Dacudac'', ''Lenga'', ''Pandayan'')</small> " .. link(rsub(rsub(text, "s", "h"), "", "o"))
						end
						
						if (output == link(text)) then
							return nil
						else 
							return output
						end
					end,
				},
			},
			benguet = {
				name = "Benguet", 
				
				--subcategories
				bakun = {
					name = "Bakun",
				},
				buguias = {
					name = "Buguias",
				},
				kapangan = {
					name = "Kapangan",
				},
				kibungan = {
					name = "Kibungan",
				},
				mankayan = {
					name = "Mankayan",
				},
			}
		},
		
	},
	
	
	others = {
		name = "Others",
		short = "o",
		color = "#f7f0f6",
		categories = {
			
			--categories
			
			benguet = {
				name = "Benguet",
				
				--subcategories
				
				atok = {
					name = "Atok",
				},
				tuba = {
					name = "Tuba",
				},
				latrinidad = {
					name = "La Trinidad",
				},
				baguio = {
					name = "Baguio",
				},
			},
			ilocos = {
				name = "Ilocos Sur", 
				cervantes = {
					name = "Cervantes",
				},
				quirino = {
					name = "Quirino",
				},
				suyo = {
					name = "Suyo",
				},
				
			},
			launion = {
				name = "La Union", 
				bagulin = {
					name = "Bagulin",
				},
				santol = {
					name = "Santol",
				},
				sudipen = {
					name = "Sudipen",
				},
				sangabriel = {
					name = "San Gabriel",
				},
				sugpon = {
					name = "Sugpon",
				},
				
			},
		}
		
	}
	
	
}

-- convert `data` into the parameters understood by ]
function convertDataToParams() 
	
	local output = {}
	
	for k, v in pairs(data) do
		
		-- add the top category
		output = {}
		output = {alias_of = k}
		
		-- add categories
		for kcat, vcat in pairs(v.categories) do
			output = {}
			output = {}
			
			-- add subcategories
			for ksubcat, vsubcat in pairs(vcat) do
				if ksubcat ~= "name" then
					
					output = {}
					
					output = {}
				end
			end
			
		end
	end
	
		
	return output;
	
end


---------------------------------------------
-- ACTUAL CODE
---------------------------------------------

-- https://stackoverflow.com/a/2705804/14021404
function tablelength(T)
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end

local function parseArgs(args)
	
	local output = {}
	
	for k, v in pairs(data) do
		
		local outputcat = {}
		-- categories
		for kcat, vcat in pairs(v.categories) do
			
			
			local outputsubcat = {}
			-- add subcategories
			for ksubcat, vsubcat in pairs(vcat) do
				if ksubcat ~= "name" then
				
				-- if there is a specific parameter that is supplied, use that first before the automated spelling:
				
				-- check for specific subcategory (aka municipality)
				if args then 
					outputsubcat = args
				elseif args then
					outputsubcat = args
				end
				
				
				-- check for category (aka province), if so then add to all subcategories
				if args then
					outputsubcat = outputsubcat or args
				elseif args then
					outputsubcat = outputsubcat or args
				end
				
				-- check for the entire supercategory (nortern or southern or others)
				if args then
					outputsubcat = outputsubcat or args
				end
				
				
				-- if there's no user input AND there is a given spelling function already, use that
				if outputsubcat==nil and vsubcat.spelling ~= nil then
					outputsubcat = vsubcat.spelling(args or mw.title.getCurrentTitle().text)
				end
				
				
				end
			end
			
			-- if not empty then add the subcat to the cat
			if next(outputsubcat)~=nil then
				outputcat = outputsubcat
			end
			
		end
		
		-- if not empty then add the cat to the output
		if next(outputcat)~=nil then
			output = outputcat
		end
		
	end
	return output
	
end

-- creates the actual table
local function createTable(frame, parsedArgs)
	--mw.logObject(parsedArgs)
		
	local output = =] .. "\n"
	
	for k, v in pairs(parsedArgs) do -- each supercategory
		output = output .. =] .. data.color .. =] .. data.name .. "\n|-\n"
		
		for kcat, vcat in pairs(v) do -- each category (province)
			output = output .. =] .. data.color .. =] .. tablelength(vcat) .. =] .. data.categories.name .. =]
			
			for ksubcat, vsubcat in pairs(vcat) do -- each subcategory (municipality)
				output = output .. =] .. data.color .. =] .. data.categories.name .. =] .. data.color .. =] .. frame:expandTemplate{ title = "l-self", args = {lang, vsubcat} } .."\n|-\n"
				
			end
			
			
		end
		
	end
	
	return output .. "|}"
end


-- the main function
function export.show(frame)
	
	local params = convertDataToParams()
	
	-- add parameters from template page
	params = {}
	params = {}

	local parargs = frame:getParent().args
	local args = require("Module:parameters").process(parargs, params)	
	
	local parsedArgs = parseArgs(args)
	
	return createTable(frame, parsedArgs)
end


return export;