Module:nn-verb-irreg

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:nn-verb-irreg/documentation. [edit]

{{documentation needed}]


local export = {}
local m_headword = require('Module:headword')
 
local lang = require("Module:languages").getByCode("nn")
 
local function link(word, form)
	local link
	if word == form then
		link = word
	else
		link = "[[" .. form .. "#Norwegian Nynorsk|" .. form .. "]]"
	end
	return "'''" .. link .. "'''"
end
 
function export.main(frame)
	local args = frame:getParent().args
	local PAGENAME = mw.title.getCurrentTitle().text
	local NAMESPACE = mw.title.getCurrentTitle().nsText
 
	local length = PAGENAME:len()
	local cons1 = PAGENAME:sub(1, 1):find('[bcdfghjklmnpqrstvxz]')
	local cons2 = PAGENAME:sub(2, 2):find('[bcdfghjklmnpqrstvxz]')
	if length == 3 and cons1 and cons2 then
		root = PAGENAME
	elseif PAGENAME:find('[ae]$') and length > 2 then
		root = PAGENAME:sub(1, length-1)
	else
		root = PAGENAME
	end
 
	if root:sub(length-1, length-1) == 'j' and length > 3 then
		root2 = root:sub(1, length-2)
	else
		root2 = root
	end
 
	if args['second_root'] then
		second_root = args['second_root']
	else
		second_root = root
	end
 
	if args['no_present_part'] then
		no_present_part = 1
	else
		no_present_part = nil
	end
 
	if args['no_passive_inf'] then
		no_passive_inf = 1
	else
		no_passive_inf = nil
	end
 
	if args['no_imp'] then
		no_imp = 1
	else
		no_imp = nil
	end
 
	if PAGENAME:find('ast$') or PAGENAME:find('as$') then
		no_present_part = 1
		no_passive_inf = 1
	end
 
	present_tense = link(PAGENAME, args[1] or (NAMESPACE == "Template" and "word") or error("Unhelpful error"))
	past_tense = link(PAGENAME, args[2] or (NAMESPACE == "Template" and "word") or error("Unhelpful error"))
	past_participle = link(PAGENAME, args[3] or (NAMESPACE == "Template" and "word") or error("Unhelpful error"))
	if args[4] and args[4]:find('st$') then
		passive_infinitive = link(PAGENAME, args[4])
	else
		passive_infinitive = link(PAGENAME, second_root .. 'ast')
	end
 
	if args[5] then
		 present_participle = link(PAGENAME, args[5])
	else
		present_participle = link(PAGENAME, second_root .. 'ande')
	end
 
	if args[6] or args['imp'] then
		 imperative = link(PAGENAME, args[6] or args['imp'])
	else
		if root:sub(length-2, length-1) == 'mm' then
			imperative = link(PAGENAME, root:sub(1, length-2))
		else
			imperative = link(PAGENAME, root2)
		end
	end
 
	-- extra arguments
 
	if args['pres_tense2'] then
		present_tense = present_tense  .. '/' .. link(PAGENAME, args['pres_tense2'])
	end
	if args['past_tense2'] then
		past_tense = past_tense  .. '/' .. link(PAGENAME, args['past_tense2'])
	end
	if args['past_part2'] then
		past_participle = past_participle  .. '/' .. link(PAGENAME, args['past_part2'])
	end
	if args['imp2'] then
		imperative = imperative .. '/' .. link(PAGENAME, args['imp2'])
	end
 
	--
 
	local infls = {}
 
	table.insert(infls, { label = 'present tense', present_tense })
	table.insert(infls, { label = 'past tense', past_tense })
	table.insert(infls, { label = 'past participle', past_participle })
 
	if not (no_passive_inf or args['first_four']) then
		table.insert(infls, { label = 'passive infinitive', passive_infinitive })
	end
 
	if not (no_present_part or args['first_four']) then
		table.insert(infls, { label = 'present participle', present_participle })
	end
 
	if not (no_imp or args['first_four']) then
		table.insert(infls, { label = 'imperative', imperative })
	end
 
	return
		m_headword.format_headword(PAGENAME, lang, nil) ..
		m_headword.format_inflections(infls, lang, nil)
end
 
return export