Modul:regulært nynorsk gjerningsord

Frå Wiktionary - den frie ordboka

Dokumentasjon for modulen kan opprettast på Modul:regulært nynorsk gjerningsord/dok

local export = {}

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

local function link(word, form)
	return "[[" .. form .. "]]"
end

local function make_root2(root)
	root = root:gsub("j$", "")
	return root:gsub("(.)%1$", "%1"), root
end
 
function export.main(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local args = frame:getParent().args
	local class = frame.args[1]  
	local length = PAGENAME:len()
	local root = PAGENAME:gsub("[ae]$", "")
	
	local data = {lang = lang, pos_category = 'gjerningsord', categories = {}, inflections = {}}
	local root2, root2_imp
	
	if class == '1' then
		present_tense = root .. 'ar'
		past_tense = root .. 'a'
		past_participle = root .. 'a'
		passive_infinitive = root .. 'ast'
		present_participle =  root .. 'ande'
		imperativ = '[[' .. root .. ']]/' .. PAGENAME
	end    
	if class == '2' then
		root2, root2_imp = make_root2(root)

		present_tense = root .. 'er'
		past_tense = root2 .. 'te'
		past_participle = root2 .. 't'
		passive_infinitive = root .. 'ast'
		present_participle = root .. 'ande'
		imperativ = root2_imp
	end
	if class == '12' or class == '21' then
		root2, root2_imp = make_root2(root)
		
		present_tense = link(PAGENAME, root .. 'ar') .. '/' .. link(PAGENAME, root .. 'er')
		past_tense = link(PAGENAME, root .. 'a') .. '/' .. link(PAGENAME, root2 .. 'te')
		past_participle = link(PAGENAME, root .. 'a') .. '/' .. link(PAGENAME, root2 .. 't')
		passive_infinitive = link(PAGENAME, root .. 'ast') 
		present_participle = link(PAGENAME, root .. 'ande') 
		imperativ = link(PAGENAME, PAGENAME) .. '/' .. link(PAGENAME, root) 
	end
	if class == '3' then
		root2, root2_imp = make_root2(root)
		length2 = root2:len()
		if root2:sub(length2, length2) == root2:sub(length2-1, length2-1) then
			root3 = root2:sub(1, length2-1)
		else
			root3 = root2
		end
		if PAGENAME:find('[iouyæøå]$') then
			present_tense = PAGENAME .. 'r'
		else
			present_tense = root .. 'er'
		end
		if not root3:find('ng$') and not root3:find('r$') and not root:find('øym') then
			if root3:find('[aeiouyæøå]$') then
				past_tense = root3 .. 'dde'
				past_participle = link(PAGENAME, root3 .. 'dd') .. '/' .. link(PAGENAME, root3 .. 'tt')
			else
				past_tense = root3 .. 'de'
				past_participle = link(PAGENAME, root3 .. 'd') .. '/' .. link(PAGENAME, root3 .. 't')
			end
		else
			past_tense = root3 .. 'de'
			past_participle = root3 .. 't'
		end
		
		passive_infinitive = root .. 'ast'
		present_participle = root .. 'ande'
		imperativ = root2_imp
	end
	
	if class == '4' then
		if root:sub(length-1, length-1) == root:sub(length-2, length-2) then
			root2 = root:sub(1, length-2)
			if root:sub(length-1, length-1) == 'n' then -- døm!, but kjenn!
				imperativ = link(PAGENAME, root) 
			else
				imperativ = link(PAGENAME, root2)
			end
		else
			root2 = root
			imperativ = link(PAGENAME, root) 
		end
		present_tense = root .. 'er'
		past_tense = link(PAGENAME, root2 .. 'de') .. '/' .. link(PAGENAME, root2 .. 'te')
		past_participle = root2 .. 't'
		passive_infinitive = root .. 'ast'
		present_participle = root .. 'ande'
	end
	
	table.insert(data.inflections, {label = 'notid', present_tense})
	table.insert(data.inflections, {label = 'fortid', past_tense})
	table.insert(data.inflections, {label = 'perfektum partisipp', past_participle})
	if not args['no_st'] then
		table.insert(data.inflections, {label = 'st-form', passive_infinitive})
	end
	if not args['no_prespart'] then
		table.insert(data.inflections, {label = 'notidspartisipp', present_participle})
	end
	if not args['no_imp'] then
		table.insert(data.inflections, {label = 'bydeform', imperativ})
	end
	
	return require("Module:headword").full_headword(data)
end
 
return export