Hopp til innhald

Modul:irregulært nynorsk gjerningsord

Frå Wiktionary - den frie ordboka

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

local p = {}

function p.link(word, form)
    if word == form then
        link = word
    else
        link = "[[" .. form .. "#Nynorsk|" .. form .. "]]"
    end
    link = "'''" .. link .. "'''"
    return link
end
 
function p.main(frame)
    args = frame:getParent().args
    PAGENAME = mw.title.getCurrentTitle().text
    NAMESPACE = mw.title.getCurrentTitle().nsText
    
    length = PAGENAME:len()
    cons1 = PAGENAME:sub(1, 1):find('[bcdfghjklmnpqrstvxz]')
    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['anna_rot'] or args['second_root'] then
        second_root = args['anna_rot'] or 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['inga_st-form'] or args['ingen_st'] then
        no_passive_inf = 1
    else
       no_passive_inf = nil
    end
    
    if args['inga_bydeform'] or 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 = p.link(PAGENAME, args[1] or (NAMESPACE == "Mal" and "ord") or error("Unhelpful error"))
    past_tense = p.link(PAGENAME, args[2] or (NAMESPACE == "Mal" and "ord") or error("Unhelpful error"))
    past_participle = p.link(PAGENAME, args[3] or (NAMESPACE == "Mal" and "ord") or error("Unhelpful error"))
    if args[4] and args[4]:find('st$') then
        passive_infinitive = p.link(PAGENAME, args[4])
    else
        passive_infinitive = p.link(PAGENAME, second_root .. 'ast')
    end
    
    if args[5] then
         present_participle = p.link(PAGENAME, args[5])
    else
        present_participle = p.link(PAGENAME, second_root .. 'ande')
    end
    
    if args[6] or args['byd'] or args['imp'] then
         imperative = p.link(PAGENAME, args[6] or args['byd'] or args['imp'])
    else
        if root:sub(length-2, length-1) == 'mm' then
            imperative = p.link(PAGENAME, root:sub(1, length-2))
        else
            imperative = p.link(PAGENAME, root2)
        end
    end
    
    -- extra arguments
    
    if args['notid2'] then
        present_tense = present_tense  .. '/' .. p.link(PAGENAME, args['notid2'])
    end
    if args['fortid2'] then
        past_tense = past_tense  .. '/' .. p.link(PAGENAME, args['fortid2'])
    end
    if args['perf_part2'] then
        past_participle = past_participle  .. '/' .. p.link(PAGENAME, args['perf_part2'])
    end
     if args['perf_part3'] then
        past_participle = past_participle  .. '/' .. p.link(PAGENAME, args['perf_part3'])
    end
    if args['byd2'] then
        imperative = imperative .. '/' .. p.link(PAGENAME, args['byd2'])
    end
    if args['imp2'] then
        imperative = imperative .. '/' .. p.link(PAGENAME, args['imp2'])
    end
    
    --
    
    if no_passive_inf or args['fyrste fire'] or args['første fire'] then
        passive = ''
    else
        passive =  "; ''st-form'' " .. passive_infinitive
    end
    
    if no_present_part or args['fyrste fire'] or args['første fire'] then
        present_part = ''
    else
        present_part = "; ''notidspartisipp'' " .. present_participle
    end
    
    if no_imp or args['fyrste fire'] or args['første fire'] then
        imp = ''
    else
        imp = "; ''bydeform'' " .. imperative
    end
    
    text = string.format("'''%s''' (''notid'' %s; ''fortid'' %s; ''perfektum partisipp'' %s%s%s%s)",
       PAGENAME, present_tense,  past_tense, past_participle, passive, present_part, imp)
    return text
end

return p