Module:ca-headword

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

This module is used for Catalan headword-line templates.

The module is always invoked the same way, by passing a single parameter to the "show" function. This parameter is the name of the part of speech, but in plural (examples given are for nouns, and for adjective forms respectively):

{{#invoke:ca-headword|show|nouns}}
{{#invoke:ca-headword|show|adjective forms}}

The template will, by default, accept the following parameters (specific parts of speech may accept or require others):

  • head= - Override the headword display, used to add links to individual words in a multi-word term.
  • cat= - Override the default category, which is the same as the provided parameter. This may sometimes be useful if you have a word that is really, say, an interjection, but you want it to show inflection as if it were an adjective. (for example, benvingut).

There is no parameter for the sort key, because this is not necessary. The sort key is automatically generated according to the normal alphabetical ordering in Catalan.


local m_com = require("Module:ca-common")
local m_headword = require("Module:headword")
local m_utilities = require("Module:utilities")
 
local export = {}
local pos_functions = {}
 
local lang = require("Module:languages").getByCode("ca")
 
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
    local args = frame:getParent().args
    PAGENAME = mw.title.getCurrentTitle().text
    NAMESPACE = mw.title.getCurrentTitle().nsText
 
    local head = args["head"]; if head == "" then head = nil end
 
    -- The part of speech. This is also the name of the category that
    -- entries go in. However, the two are separate (the "cat" parameter)
    -- because you sometimes want something to behave as an adjective without
    -- putting it in the adjectives category.
    local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
    local cat = args["cat"]; if cat == "" then cat = nil end
 
    local genders = {}
    local inflections = {}
    local categories = {"Catalan " .. (cat or poscat)}
 
    if pos_functions[poscat] then
        pos_functions[poscat](args, genders, inflections, categories)
    end
 
    return
        m_headword.full_headword(lang, nil, head, nil, genders, inflections) ..
        m_utilities.format_categories(categories, lang)
end
 
-- Display information for a noun's gender
-- This is separate so that it can also be used for proper nouns
function noun_gender(args, genders, inflections, categories)
    local gender = args[1]; if gender == "" then gender = nil end
 
    if gender == "m-p" or gender == "f-p" then
        table.insert(categories, "Catalan pluralia tantum")
    end
 
    if gender == "mf" then
        table.insert(genders, "m")
        table.insert(genders, "f")
    else
        table.insert(genders, gender)
    end
 
    if #genders == 0 then
    	table.insert(genders, "?")
    end
 
    -- Is this a noun with an unexpected ending (for its gender)?
    -- Only check if the term is one word (there are no spaces in the term).
    if not PAGENAME:find(" ") then
        if PAGENAME:find("a$") and (gender[1] == "m") then
            table.insert(categories, "Catalan masculine nouns ending in -a")
        elseif not (PAGENAME:find("a$") or PAGENAME:find("ió$") or PAGENAME:find("tat$") or PAGENAME:find("tud$") or PAGENAME:find("[dt]riu$")) and genders[1] == "f" then
            table.insert(categories, "Catalan feminine nouns with no feminine ending")
        end
    end
end
 
pos_functions["proper nouns"] = function(args, genders, inflections, categories)
	noun_gender(args, genders, inflections, categories)
end
 
-- Display additional inflection information for a noun
pos_functions["nouns"] = function(args, genders, inflections, categories)
	noun_gender(args, genders, inflections, categories)
 
    -- Plural
    if genders[1] == "m-p" or genders[1] == "f-p" then
        table.insert(inflections, {label = "[[Appendix:Glossary#plurale tantum|plurale tantum]]"})
    else
        local plural = args[2]; if plural == "" then plural = nil end
 
        if plural == "-" then
            table.insert(inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
            table.insert(categories, "Catalan uncountable nouns")
        else
            local infl_parts = {label = "plural", accel = "plural-form-of"}
            local plural2 = args["pl2"]; if plural2 == "" then plural2 = nil end
 
            local p, p2 = make_plural(PAGENAME, genders[1])
            plural = plural or p
            plural2 = plural2 or p2
 
            table.insert(infl_parts, plural)
 
            if plural2 then
                table.insert(infl_parts, plural2)
            end
 
            table.insert(inflections, infl_parts)
        end
    end
 
    -- Gendered forms
    local feminine = args["f"]; if feminine == "" then feminine = nil end
    local masculine = args["m"]; if masculine == "" then masculine = nil end
 
    if feminine then
        table.insert(inflections, {label = "feminine", feminine})
    end
 
    if masculine then
        table.insert(inflections, {label = "masculine", masculine})
    end
end
 
-- Display additional inflection information for an adjective
pos_functions["adjectives"] = function(args, genders, inflections, categories)
    local feminine = args[1]; if feminine == "" then feminine = nil end
    local masculine_plural
    local masculine_plural2
    local feminine_plural
 
    -- Invariable adjectives
    if feminine == "inv" then
        table.insert(categories, "Catalan invariable adjectives")
        table.insert(genders, "m")
        table.insert(genders, "f")
        table.insert(inflections, {label = "invariable"})
    else
        -- Adjectives with identical forms in the masculine and feminine singular
        if feminine == "mf" then
            feminine = PAGENAME
            table.insert(categories, "Catalan epicene adjectives")
 
            -- Adjectives ending in -ç behave as mf-type in the singular, but
            -- regular type in the plural.
            if PAGENAME:find("ç$") then
                masculine_plural = make_plural(PAGENAME, "m")
                feminine_plural = make_plural(PAGENAME .. "a", "f")
            else
                masculine_plural = make_plural(PAGENAME, "m")
                feminine_plural = masculine_plural
            end
 
            -- Has anyone provided forms to override the defaults?
            masculine_plural = args["pl"] or masculine_plural
            feminine_plural = args["pl"] or feminine_plural
            masculine_plural2 = args["pl2"] or masculine_plural2
        -- Adjectives with distinct masculine and feminine singular forms
        -- (the majority)
        else
            feminine = feminine or make_feminine(PAGENAME)
            feminine_plural = make_plural(feminine, "f")
 
            -- If the feminine ends in -ssa, assume that the -ss- is also in the
            -- masculine plural form
            if feminine:find("ssa$") then
                masculine_plural = feminine:gsub("a$", "os")
            elseif feminine == PAGENAME .. "na" then
                masculine_plural = PAGENAME .. "ns"
            -- Adjectives in -ig have two masculine plural forms, one derived from
            -- the m.sg. and the other derived from the f.sg.
            elseif PAGENAME:find("ig$") then
                masculine_plural = PAGENAME .. "s"
                masculine_plural2 = feminine:gsub("ja$", "jos")
            else
                masculine_plural, masculine_plural2 = make_plural(PAGENAME, "m")
            end
        end
 
        -- Display the forms.
        -- If masculine and feminine are identical, show m,f as the gender and
        -- leave out the feminine.
        if feminine == PAGENAME then
            table.insert(genders, "m")
        	table.insert(genders, "f")
        else
            table.insert(genders, "m")
            table.insert(inflections, {label = "feminine", accel = "feminine-form-of", feminine})
        end
 
        -- If the plurals are identical, show only one form as well.
        if masculine_plural == feminine_plural then
            local infl_parts = {label = "masculine and feminine plural", accel = "plural-form-of"}
            table.insert(infl_parts, masculine_plural)
 
            if masculine_plural2 then
                table.insert(infl_parts, masculine_plural2)
            end
 
            table.insert(inflections, infl_parts)
        else
            local infl_parts = {label = "masculine plural", accel = "masculine-plural-form-of"}
            table.insert(infl_parts, masculine_plural)
 
            if masculine_plural2 then
                table.insert(infl_parts, masculine_plural2)
            end
 
            table.insert(inflections, infl_parts)
            table.insert(inflections, {label = "feminine plural", accel = "feminine-plural-form-of", feminine_plural})
        end
    end
end
 
-- Display additional inflection information for a verb
pos_functions["verbs"] = function(args, genders, inflections, categories)
    -- Does this verb end in a recognised verb ending (possibly reflexive)?
    if not PAGENAME:find(" ") and (PAGENAME:find("re?$") or PAGENAME:find("r%-se$") or PAGENAME:find("re's$")) then
        local base = PAGENAME:gsub("r%-se$", "r"):gsub("re's$", "re")
        local pres_1_sg
        local past_part
 
        -- Generate inflected forms.
        -- The 2nd conjugation is generally irregular
        -- so generate nothing for that, explicit parameters are required.
 
        -- 1st conjugation
        if base:find("ar$") then
            local stem = base:gsub("ar$", "")
            pres_1_sg = stem .. "o"
            past_part = stem .. "at"
        -- 3rd conjugation (except -tenir/-venir)
        elseif base:find("ir$") and not base:find("[tv]enir$") then
            local stem = base:gsub("ir$", "")
            pres_1_sg = stem .. "eixo"
 
            if stem:find("[aeiou]$") and not stem:find("[gq]u$") then
                past_part = stem .. "ït"
            else
                past_part = stem .. "it"
            end
        end
 
        -- Overridden forms
        pres_1_sg = args["pres_1_sg"] or pres_1_sg
        past_part = args["past_part"] or past_part
 
        -- Display the forms
        if pres_1_sg then
            table.insert(inflections, {label = "first-person singular present", pres_1_sg})
        else
            table.insert(inflections, "<small><sup>???</sup> please provide the first-person singular present form!</small>")
            table.insert(categories, "Catalan verbs needing inflection")
        end
 
        if past_part then
            table.insert(inflections, {label = "past participle", past_part})
        else
            table.insert(inflections, "<small><sup>???</sup> please provide the past participle!</small>")
            table.insert(categories, "Catalan verbs needing inflection")
        end
    end
end
 
-- Display additional inflection information for a numeral
pos_functions["numerals"] = function(args)
    local genders = {}
    local inflections = {}
    local categories = {}
 
    local feminine = args[1]; if feminine == "" then feminine = nil end
    local noun_form = args[2]; if noun_form == "" then noun_form = nil end
 
    if feminine then
        genders = {"m"}
        table.insert(inflections, {label = "feminine", feminine})
 
        if noun_form then
            table.insert(inflections, {label = "noun form", noun_form})
        end
    else
        genders = {"m", "f"}
    end
 
    return genders, inflections, categories
end
 
function make_feminine(base)
    -- final vowel -> -a
    if base:find("a$") then return base end
    if base:find("o$") then return (base:gsub("o$", "a")) end    
    if base:find("e$") then return m_com.front_to_back(base:gsub("e$", "")) .. "a" end
 
    -- -u -> -va
    if base:find("[aeiou]u$") then return (base:gsub("u$", "v") .. "a") end
 
    -- accented vowel -> -na
    if mw.ustring.find(base, "[àèéíòóú]$") then return m_com.remove_accents(base) .. "na" end
 
    -- accented vowel + -s -> -sa
    if mw.ustring.find(base, "[àèéíòóú]s$") then return m_com.remove_accents(base) .. "a" end
 
    return base .. "a"
end
 
function make_plural(base, gender)
    -- a -> es
    if base:find("a$") then return m_com.back_to_front(base:gsub("a$", "")) .. "es", nil end
 
    -- accented vowel -> -ns
    if mw.ustring.find(base, "[àèéíòóú]$") then return m_com.remove_accents(base) .. "ns", nil end
 
    if gender == "m" then
        if mw.ustring.find(base, "[àèéíòóú]s$") then return m_com.remove_accents(base) .. "os", nil end
        if base:find("s$") or base:find("ç$") or base:find("x$") or base:find("z$") then return base .. "os", nil end
        if base:find("sc$") or base:find("st$") or base:find("xt$") then return base .. "s", base .. "os" end
    end
 
    if gender == "f" then
        if base:find("s$") then return base end
        if base:find("sc$") or base:find("st$") or base:find("xt$") then return base .. "s", base .. "es" end
    end
 
    return base .. "s", nil
end
 
return export