Module:Chak-nouns

From EMPTY MEDIAWIKI
Jump to navigation Jump to search

Documentation for this module may be created at Module:Chak-nouns/doc

export = {}

require("Module:Chak-nouns/format")
require("Module:Chak-nouns/data")
m_params = require("Module:Parameters")
m_vars = require("Module:Variables")
m_cu = require("Module:Chak-utilities")
m_stru = require("Module:String utilities")

function export.get_forms(root_str,manual)

	local forms = {}
	local prefixes = {}
	local codas = {}
	
	local root = m_cu.parse_root(root_str,true)

	if root == nil or #root == 0 then
		error("No root provided.")
	elseif string.find(root[#root],"["..VOWELS.."]") then
		error ("Invalid root: "..root_str)
	else
			
		if #root == 1 then --Root with no vowels
			local mods = mw.text.split(root[1],"-")
			codas["nom"] = 'i'..mods[2]
			codas["gen"] = mods[2]
			codas["acc.sg"] = mods[2]
			codas["acc.pl"] = mods[2]
			forms["nom.sg"] = mods[1]..((mods[3] and mods[2]) or '').."i"..(mods[3] or mods[2])
			forms["nom.pl"] = mods[1]..'a'..((mods[3] and mods[2]) or '').."i"..(mods[3] or mods[2])
			forms["acc.sg"] = "a"..mods[1]..mods[2].."a"..(mods[3] or '')
			forms["acc.pl"] = mods[1].."a"..mods[2]..(mods[3] or '')..((mods[3] and 'a') or '')
			forms["gen.sg"] = mods[1]..((mods[3] and mods[2]) or '').."a"..(mods[3] or mods[2])
			forms["gen.pl"] = mods[1]..'a'..((mods[3] and mods[2]) or '').."a"..(mods[3] or mods[2])
			forms["loc.sg"] = "un-"..mods[1]..((mods[3] and 'a') or '')..((mods[3] and mods[2]) or '').."i"..(mods[3] or mods[2])
			forms["loc.pl"] = "un-"..mods[1]..((mods[3] and 'aa') or '')..((mods[3] and mods[2]) or '').."i"..(mods[3] or mods[2])
			forms["all.sg"] = "a-"..mods[1]..mods[2].."a"..(mods[3] or '')
			forms["all.pl"] = "a-"..mods[1].."a"..mods[2]..(mods[3] or '')..((mods[3] and 'a') or '')
			forms["abl.sg"] = "is-"..mods[1]..((mods[3] and 'a') or '')..((mods[3] and mods[2]) or '').."a"..(mods[3] or mods[2])
			forms["abl.pl"] = "is-"..mods[1]..((mods[3] and 'aa') or '')..((mods[3] and mods[2]) or '').."a"..(mods[3] or mods[2])
--		elseif #root == 2 then -- Root with V+ then C+
				
		else 
			local tail_str = root[#root]
			local mods = mw.text.split(tail_str,"-")
			table.remove(root,#root)
			prefixes["loc"] = (string.find(root[1],"[aeiou]") and "n") or "un-"
			prefixes["all"] = (string.find(root[1],"[aeiou]") and "h") or "a-"
			prefixes["abl"] = (string.find(root[1],"[aeiou]") and "s") or "is-"
			
			local vowel = root[#root]
			local cond_vowel = m_cu.condense_vowels(vowel)
			local pl_vowel = string.sub("a"..vowel,1,2)
			local cond_pl_vowel = m_cu.condense_vowels(pl_vowel)
			table.remove(root,#root)
			
			codas["nom"] = mods[1]..((mods[3] and mods[2]) or '').."i"..(mods[3] or mods[2] or '')
			codas["gen"] = mods[1]..((mods[3] and mods[2]) or '').."a"..(mods[3] or mods[2] or '')
			codas["acc.sg"] = mods[1]..(mods[2] or '')..((mods[2] and m_cu.degeminate_char(cond_vowel)) or '')..(mods[3] or '')
			codas["acc.pl"] = mods[1]..(mods[2] or '')..((mods[2] and 'a') or '')..(mods[3] or '')
			
			if #root == 1 and m_cu.is_geminate(root[1]) then 
				forms["nom.sg"] = string.sub(cond_vowel,1,1)..root[1]..cond_vowel..codas["nom"]
				forms["nom.pl"] = string.sub(pl_vowel,1,1)..root[1]..pl_vowel..codas["nom"]
				forms["acc.sg"] = string.sub(cond_vowel,1,1)..root[1]..m_cu.degeminate_char(cond_vowel)..codas["acc.sg"]
				forms["acc.pl"] = string.sub(cond_pl_vowel,1,1)..root[1]..cond_pl_vowel..codas["acc.pl"]
				forms["gen.sg"] = string.sub(cond_vowel,1,1)..root[1]..cond_vowel..codas["gen"]
				forms["gen.pl"] = string.sub(pl_vowel,1,1)..root[1]..pl_vowel..codas["gen"]
				root[1] = m_cu.degeminate_char(root[1])
			else
				local concat_root = table.concat(root)
				forms["nom.sg"] = concat_root..vowel..codas["nom"]
				forms["nom.pl"] = concat_root..pl_vowel..codas["nom"]
				forms["acc.sg"] = concat_root..m_cu.degeminate_char(cond_vowel)..codas["acc.sg"]
				forms["acc.pl"] = concat_root..cond_pl_vowel..codas["acc.pl"]
				forms["gen.sg"] = concat_root..vowel..codas["gen"]
				forms["gen.pl"] = concat_root..pl_vowel..codas["gen"]
			end
			local concat_root = table.concat(root) --I am doing some trickery here with concat_root being scoped at two levels. Bad coding practice, but gets the job done for now.
			forms["loc.sg"] = prefixes["loc"]..concat_root..vowel..codas["nom"]
			forms["loc.pl"] = prefixes["loc"]..concat_root..pl_vowel..codas["nom"]
			forms["all.sg"] = prefixes["all"]..concat_root..m_cu.degeminate_char(cond_vowel)..codas["acc.sg"]
			forms["all.pl"] = prefixes["all"]..concat_root..cond_pl_vowel..codas["acc.pl"]
			forms["abl.sg"] = prefixes["abl"]..concat_root..vowel..codas["gen"]
			forms["abl.pl"] = prefixes["abl"]..concat_root..pl_vowel..codas["gen"]
		end
	end

	for k,v in pairs(forms) do
		forms[k] = m_cu.assimilate(v)
	end

	for k,v in pairs(manual) do
		if manual[k] ~= nil then
			forms[k] = v
		end		
	end

	return forms
	
end

function export.show_declension(root,mod,others)
    mod = mod or ''
	local forms = {}

	--forms = export.get_forms(root,mod,stems,others)
	forms = export.get_forms(root..mod,others)

	return m_stru.format(decl_table,forms)
	
end

function export.declension(frame)

	local params = {
		[1] = {alias_of = "root"},
		[2] = {alias_of = "mod"},
		["root"] = { default = m_vars.var('chak-root') },
		["mod"] = { default = m_vars.var('chak-mod') },
	}

	local frame_args = frame:getParent().args
	local args,others = m_params.process(frame_args,params,true)
	
	return export.show_declension(args["root"],args["mod"],others)
	
end

function export.test(root,mod)
	
	return export.show_declension(root,mod,{})

end

function export.headword(frame)

	local params = {
		[1] = {alias_of = "root"},
		[2] = {alias_of = "mod"},
		["root"] = { default = m_vars.var('chak-root')},
		["mod"] = { default = m_vars.var('chak-mod') },
	}

	local frame_args = frame:getParent().args
	local args,others = m_params.process(frame_args,params,true)
	
	local forms = export.get_forms(args["root"]..(args["mod"] or ''),others)

	local output = ""
	output = output.."(''nominative plural'' '''"..m_cu.l(forms["nom.pl"])
	output = output.."''', ''accusative plural'' '''"..m_cu.l(forms["acc.pl"])
    output = output.."''', ''locative singular'' '''"..m_cu.l(forms["loc.sg"])
    output = output.."''', ''allative singular'' '''"..m_cu.l(forms["all.sg"])
	output = output.."''')"
	
	return output
end


return export