Module:nn-noun

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
Text-x-generic with pencil.svg This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

-- TODO: avoid duplicates with 'multi' with e.g. f1 and f2

local lang = require("Module:languages").getByCode("nn")

local export = {}

function export.regular(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local args = frame:getParent().args
	local classType = frame.args[1]
	
	local class = ''
	local genders = {}
	
	-- Gather parameters
	local root = PAGENAME:gsub("e$", "")
	local root_sg = nil
	local root_pl = nil
	if classType ~= 'multi' then
		if args[1] and args[1] ~= '' and not args[2] then
			root_sg = args[1]
			root_pl = args[1]
		elseif args[2] and args[2] ~= '' then
			root_pl = args[2]
			if args[1] and args[1] ~= '' then
				root_sg = args[1]
			end
		end
	end
	local gen_dsg = args['gen_dsg']; if gen_dsg == "" then gen_dsg = nil end

	if args['stem'] then
		root_sg = args['stem']
		root_pl = root_sg
	end
	
	if not classType:find('multi') then -- the word has only one possible inflection (normal)
		class = classType
		genders = {class:sub(1, 1)} -- extracts e.g. "m" from "m1"
	else
		local i = 1
		local j = 1
		local _genders = {}
		while (true) do
			if args[i] == nil then
				break
			end
			class = class .. '-' .. args[i]
			local g = args[i]:sub(1, 1)
			_genders[g] = true
			
			i = i + 1
		end
		if _genders['f'] then
			genders[j] = 'f'
			j = j + 1
		end
		if _genders['m'] then
			genders[j] = 'm'
			j = j + 1
		end
		if _genders['n'] then
			genders[j] = 'n'
			j = j + 1
		end
	end
	
	if not root_pl then
		if PAGENAME:find("kel$") then
			root_pl = PAGENAME:gsub("k?kel$", "kl")
		elseif PAGENAME:find("tel$") and not PAGENAME:find('mittel$') and not PAGENAME:find('pitel$')then
			root_pl = PAGENAME:gsub("t?tel$", "tl")
		else
			root_pl = root
		end
	end
	
	if not root_sg then
		root_sg = root
	end
	
	-- Generate inflected forms
	local definite_singular = {label = "definite singular"}
	local indefinite_plural = {label = "indefinite plural"}
	local definite_plural = {label = "definite plural"}

	if class:find('m1') then
		table.insert(definite_singular, root_sg .. 'en')
		table.insert(indefinite_plural, root_pl .. 'ar')
		table.insert(definite_plural, root_pl .. 'ane')
	end
	if class:find('m2') then
		table.insert(definite_singular, root_sg .. 'en')
		table.insert(indefinite_plural, root_pl .. 'er')
		table.insert(indefinite_plural, root_pl .. 'ar')
		table.insert(definite_plural, root_pl .. 'ene')
		table.insert(definite_plural, root_pl .. 'ane')
	end
	if class:find('m3') then
		table.insert(definite_singular, root_sg .. 'en')
		table.insert(indefinite_plural, root_sg)
		table.insert(definite_plural, root_pl .. 'a')
	end
	if class:find('f1') or class == 'f2' then
		table.insert(definite_singular, root_sg .. 'a')
		table.insert(indefinite_plural, root_pl .. 'er')
		table.insert(definite_plural, root_pl .. 'ene')
	end
	if class:find('f3') then
		table.insert(definite_singular, root_sg .. 'a')
		table.insert(indefinite_plural, root_pl .. 'ar')
		table.insert(definite_plural, root_pl .. 'ane')
	end
	if class:find('n1') then
		table.insert(definite_singular, root_sg .. 'et')
		table.insert(indefinite_plural, PAGENAME)
		table.insert(definite_plural, root_pl .. 'a')
	end
	if class:find('-ium') then
		genders = {'n'}
		root = PAGENAME:gsub('um$', '')
		table.insert(definite_singular, root .. 'et')
		table.insert(indefinite_plural, PAGENAME)
		table.insert(definite_plural, root .. 'a')
	end
	
	-- Add inflections
	local inflections = {definite_singular}
	
	if #indefinite_plural > 0 then
		table.insert(inflections, indefinite_plural)
	end
	
	if #definite_plural > 0 then
		table.insert(inflections, definite_plural)
	end
	
	if gen_dsg then
		table.insert(inflections, {label = "genitive definite singular", gen_dsg})
	end
	
	return require("Module:headword").full_headword(lang, nil, nil, nil, genders, inflections, {lang:getCanonicalName() .. " nouns"}, nil)
end

function export.irregular(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local args = frame:getParent().args
	local uncountable = false
	
	local genders = {args[1]}
	local inflections = {}
	
	local categories = {lang:getCanonicalName() .. " nouns"}
	
	-- Gather parameters
	local gen_dsg = args['gen_dsg']; if gen_dsg == "" then gen_dsg = nil end
	
	if args['uncountable'] or args['unc'] then
		uncountable = true
	end
	
	if args['g2'] then
		table.insert(genders, args['g2'])
	end
	if args['g3'] then
		table.insert(genders, args['g3'])
	end
	
	-- Insert inflected forms
	local definite_singular = {label = "definite singular"}
	local indefinite_plural = {label = "indefinite plural"}
	local definite_plural = {label = "definite plural"}
	

	table.insert(definite_singular, args[2])
	if args['ds2'] then
		table.insert(definite_singular, args['ds2'])
	end
	table.insert(inflections, definite_singular)
	
	if not uncountable then
		table.insert(indefinite_plural, args[3])
		if args['ip2'] then
			table.insert(indefinite_plural, args['ip2'])
		end
		table.insert(inflections, indefinite_plural)
		
		table.insert(definite_plural, args[4])
		if args['dp2'] then
			table.insert(definite_plural, args['dp2'])
		end
		table.insert(inflections, definite_plural)
	else
		table.insert(inflections, {label = '[[Appendix:Glossary#uncountable|uncountable]]'})
		table.insert(categories, lang:getCanonicalName() .. " uncountable nouns")
	end
	
	if gen_dsg then
		table.insert(inflections, {label = "genitive definite singular", gen_dsg})
	end
	
	return require("Module:headword").full_headword(lang, nil, nil, nil, genders, inflections, categories, nil)
end

return export