Module:fro-headword

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.

local m_fro_utilities = require("Module:fro-utilities")
 
local export = {}
 
local lang = require("Module:languages").getByCode("fro")
 
function export.noun(frame)
    local args = frame:getParent().args
    PAGENAME = mw.title.getCurrentTitle().text
 
    local head = args["head"]; if head == "" then head = nil end
 
    local op = args["op"] or args[2]; if op == "" then op = nil end
    local ns = args["ns"] or args[3]; if ns == "" then ns = nil end
    local np = args["np"] or args[4]; if np == "" then np = nil end
 
    local genders = {}
    local inflections = {}
    local categories = {"Old French nouns"}
 
    -- Process the genders
    local valid_genders = {
        ["m"] = true,
        ["f"] = true,
        ["m-p"] = true,
        ["f-p"] = true}
 
    local g = args[1]
 
    if valid_genders[g] then
        genders = {g}
        if g == "m" or g == "m-p" then
            table.insert(categories, "Old French masculine nouns")
        else
            table.insert(categories, "Old French feminine nouns")
        end
    elseif g == "mf" then
        genders = {"m", "f"}
        table.insert(categories, "Old French masculine nouns")
        table.insert(categories, "Old French feminine nouns")
    else
        genders = {"?"}
        table.insert(categories, "Old French terms with incomplete gender")
    end
 
    -- Generate default plural forms by adding -s.
    -- Note that these are also used for the nominative singular of masculine nouns.
    local plurals = m_fro_utilities.pluralize(PAGENAME)
 
    -- Insert PART, either a string or array, into TAB. If PART is a string,
    -- split on commas.
    local function insert_part(tab, part)
        if type(part) == "table" then
            for _, form in ipairs(part) do
                table.insert(tab, form)
            end
        else
            local forms = mw.text.split(part, ",")
            for _, form in ipairs(forms) do
                table.insert(tab, form)
            end
        end
    end
 
    -- Oblique plurals are the same for both genders
    local op_parts = {label = "oblique plural"}
 
    insert_part(op_parts, op or plurals)    
 
    -- Nominative forms differ between the genders
    -- If masculine, the singular gets the -s
    -- If feminine, the plural gets the -s
    local ns_parts = {label = "nominative singular"}
    local np_parts = {label = "nominative plural"}
 
    if genders[1] == "m" or genders[1] == "m-p" then
        insert_part(np_parts, np or PAGENAME)
        insert_part(ns_parts, ns or plurals)
    else
        insert_part(ns_parts, ns or PAGENAME)
        insert_part(np_parts, np or plurals)
    end
 
    -- Add the inflections
    if op == "-" or genders[1] == "m-p" or genders[1] == "f-p" then
        table.insert(inflections, ns_parts)
        table.insert(categories, "Old French uncountable nouns")
    else
        table.insert(inflections, op_parts)
        table.insert(inflections, ns_parts)
        table.insert(inflections, np_parts)
    end
 
    if op and op ~= "-" or np and np ~= "-" or ns then
        table.insert(categories, "Old French irregular nouns")
    end
    return require("Module:headword").full_headword(lang, nil, head, nil, genders, inflections, categories, nil)
end
 
return export