Jump to content

Module:nb-noun-reg

ពីWiktionary

Documentation for this module may be created at Module:nb-noun-reg/doc

local m_links = require("Module:links")
local m_gender = require("Module:gender and number")

local lang = require("Module:languages").getLanguageByCode("nb")

local p = {}

local function link(word, form)
    return m_links.full_link((form ~= word) and form or "", (form == word) and form or nil, lang, "Latn", "bold", nil, {})
end

local function link_list(word, list)
	local links = {}
    for _, item in ipairs(list) do
		table.insert(links, link(word, item))
    end
    return table.concat(links, "/")
end

function p.main(frame)
    word = frame:preprocess('{{PAGENAME}}')
    class = frame.args[1]
    args = frame:getParent().args
    length = word:len()
    if word:find('e$') then
        root = word:sub(1, length-1)
    else
        root = word
    end
 
    if args[1] and args[1] ~= '' then
        root_pl = args[1]
    elseif word:find('kkel$') then
        root_pl = word:sub(1, length-4) .. 'kl'
    elseif word:find('kel$') then
        root_pl = word:sub(1, length-3) .. 'kl'
    elseif word:find('ttel$') and not word:find('mittel$') then
        root_pl = word:sub(1, length-4) .. 'tl'
    elseif word:find('tel$') and not word:find('pitel$') then
        root_pl = word:sub(1, length-3) .. 'tl'
    else
        root_pl = root
    end
    
    if args[2] and args[2] ~= '' then
        root_sg = args[2]
    else
        root_sg = root
    end
 
    gender = class:sub(1, 1) -- extracts e.g. "m" from "m1"
 
    if class == 'm1' then
        definite_singular = link(word, root_sg .. 'en')
        indefinite_plural = link(word, root_pl .. 'er')
        definite_plural = link(word, root_pl .. 'ene')
    end    
    if class == 'm2' then
        definite_singular = link(word, root_sg .. 'en')
        indefinite_plural = link(word, root_pl .. 'e')
        definite_plural = link(word, root_pl .. 'ne')
    end
    if class == 'c' then
        gender = {'f', 'm'}
        definite_singular = link_list(word, {root_sg .. 'a', root_sg .. 'en'})
        indefinite_plural = link(word, root_pl .. 'er')
        definite_plural = link(word, root_pl .. 'ene')
    end
    if class == 'n1' then
        definite_singular = link(word, root_sg .. 'et')
        indefinite_plural = link(word, root_pl)
        definite_plural = link_list(word, {root_pl .. 'a', root_pl.. 'ene'})
    end
    if class == 'n2' then
        definite_singular = link(word, root_sg .. 'et')
        indefinite_plural = link(word, root_pl .. 'er')
        definite_plural = link_list(word, {root_pl .. 'a', root_pl .. 'ene'})
    end
    if class == 'n3' then
        definite_singular = link(word, root_sg .. 'et')
        indefinite_plural = link_list(word, {word, root_pl .. 'er'})
        definite_plural = link_list(word, {root_pl .. 'a', root_pl .. 'ene'})
    end
    
    if class ~= 'c' then
        gender_txt = m_gender.format_list({gender}) -- the standard text for gender information
    else
        gender_txt = m_gender.format_list(gender) 
    end
 
    text = "'''" .. word .. "''' "  .. gender_txt .. " (''ឯកវចនៈច្បាស់លាស់'' " .. definite_singular
    if indefinite_plural then
        text = text .. "; ''ពហុវចនៈមិនច្បាស់លាស់'' " .. indefinite_plural
    end
    if definite_plural then
        text = text .. "; ''ពហុវចនៈច្បាស់លាស់'' " .. definite_plural
    end
 
    if args['gen_dsg'] then
        gen_dsg = link(word, args['gen_dsg'])
        text = text .. "; ''genitive definite singular'' " .. gen_dsg
    end
 
    text = text .. ')'
    return text
end
 
 
return p