„Modul:gender and number” változatai közötti eltérés

Tartalom törölve Tartalom hozzáadva
LinguisticMystic (vitalap | szerkesztései)
+Animal (for Ukrainian)
Voltaigne (vitalap | szerkesztései)
Nemi kategóriákhoz irányuló linkek létrehozása (teszt)
Címke: Visszaállítva
86. sor:
end
 
-- Format one or more gender/number specifications. Each spec is either a string, e.g. "f-p", or
-- Format the sub-parts of a single gender specification.
-- a table of the form {spec = "SPEC", qualifiers = {"QUALIFIER", "QUALIFIER", ...}} where `.spec`
function export.format_specification(spec, lang)
-- is a gender/number spec such as "f-p" and `.qualifiers` is a list of qualifiers to display before
local categories = ""
-- the formatted gender/number spec. `.spec` must be present but `.qualifiers` may be omitted.
local ret = ""
-- The function returns two values:
local is_nounclass = false
-- (a) the formatted text;
-- (b) a list of the categories to add.
-- If the specification starts with cX, then it is a noun class specification.
-- If `lang` and `pos_for_cat` are given, gender categories such as "German masculine nouns" or
if spec:find("^[1-9]") or spec:find("^c[^-]") then
-- "Russian imperfective verbs" are added to the categories. Otherwise, if only `lang` is given,
is_nounclass = true
-- the only category that may be returned is "Requests for gender in LANG entries". If both are
code = spec:gsub("^c", "")
-- omitted, the returned list is empty.
function export.format_genders(specs, lang, pos_for_cat)
if code == "?" then
local formatted_specs = {}
ret = "<abbr class=\"noun-class\" title=\"noun class missing\">?</abbr>"
local categories = {}
else
local seen_types = {}
ret = "<abbr class=\"noun-class\" title=\"noun class " .. code .. "\">" .. code .. "</abbr>"
local category_text = ""
end
local all_is_nounclass = nil
else
 
local function do_gender_spec(spec, parts)
local types = {}
 
-- Split the parts and iterate over each part, converting it into its display form
local parts = mw.text.split(spec, "-")
for key, code in ipairs(parts) do
-- Is this code valid?
if not codes[code] then
error("'The tag "' .. code .. '" in the gender specification \""' .. spec.spec .. "\'" is not valid."')
end
-- Check for multiple genders/numbers/animacies in a single spec.
if codes[code].type ~= "other" and types[codes[code].type] then
local typ = codes[code].type
if typ ~= "other" and types[typ] then
--require("Module:debug").track("gender and number/multiple")
--require("Module:debug").track("gender and number/multiple/" .. spec)
error("'The gender specification \""' .. spec.spec .. "\'" contains multiple tags of type \""' .. codes[code].typetyp .. "\'"."')
end
types[typ] = true
if spec.qualifiers and #spec.qualifiers > 0 then
parts[key] = codes[code].display
parts[key] = require("Module:qualifier").format_qualifier(spec.qualifiers) .. " " .. codes[code].display
types[codes[code].type] = true
else
parts[key] = codes[code].display
end
-- Generate categories if called for.
if lang and pos_for_cat then
local cat = codes[code].cat
if cat then
table.insert(categories, lang:getCanonicalName() .. " " .. cat)
end
if seen_types[typ] and seen_types[typ] ~= code then
cat = codetype_cats[typ]
if cat then
table.insert(categories, lang:getCanonicalName() .. " " .. cat)
end
end
seen_types[typ] = code
end
end
-- Add the processed codes together with non-breaking spaces
if #parts == 1 then
ret = table.concat(parts, "&nbsp;")
return parts[1]
end
return table.concat(parts, "&nbsp;")
end
 
for _, spec in ipairs(specs) do
-- Do some additional checks if a language was given
if langtype(spec) ~= "table" then
spec = {spec = spec}
-- Is this an incomplete gender?
if spec:find("?") then
local m_utilities = require("Module:utilities")
--categories = m_utilities.format_categories({"Requests for gender in " .. lang:getCanonicalName() .. " entries"}, nil)
end
local is_nounclass
-- Check ifIf the specification starts with cX, then it is valida noun class specification.
if spec.spec:find("^[1-9]") or spec.spec:find("^c[^-]") then
--elseif langinfo.genders then
is_nounclass = true
-- local valid_genders = {}
code = spec.spec:gsub("^c", "")
-- for _, g in ipairs(langinfo.genders) do valid_genders[g] = true end
--
local text
-- if not valid_genders[spec] then
if code == "?" then
-- local valid_string = {}
text = '<abbr class="noun-class" title="noun class missing">?</abbr>'
-- for i, g in ipairs(langinfo.genders) do valid_string[i] = g end
else
-- error("The gender specification \"" .. spec .. "\" is not valid for " .. langinfo.names[1] .. ". Valid are: " .. table.concat(valid_string, ", "))
text = '<abbr class="noun-class" title="noun class ' .. code .. '">' .. code .. "</abbr>"
-- end
if lang and pos_for_cat then
--end
table.insert(categories, lang:getCanonicalName() .. " class " .. code .. " POS")
end
end
local text_with_qual
if spec.qualifiers and #spec.qualifiers > 0 then
text_with_qual = require("Module:qualifier").format_qualifier(spec.qualifiers) .. " " .. text
else
text_with_qual = text
end
table.insert(formatted_specs, text_with_qual)
else
-- Split the parts and iterate over each part, converting it into its display form
local parts = mw.text.split(spec.spec, "%-")
local extra_cats = {}
 
local has_combined = false
for _, code in ipairs(parts) do
if combined_codes[code] then
has_combined = true
break
end
end
 
if not has_combined then
table.insert(formatted_specs, do_gender_spec(spec, parts))
else
local all_parts = {{}}
 
for i, code in ipairs(parts) do
if combined_codes[code] then
local new_all_parts = {}
for _, one_parts in ipairs(all_parts) do
for _, one_code in ipairs(combined_codes[code].codes) do
local new_combined_parts = mw.clone(one_parts)
table.insert(new_combined_parts, one_code)
table.insert(new_all_parts, new_combined_parts)
end
end
all_parts = new_all_parts
if lang and pos_for_cat then
local extra_cat = combined_codes[code].cat
if extra_cat then
table.insert(extra_cats, lang:getCanonicalName() .. " " .. extra_cat)
end
end
else
for _, one_parts in ipairs(all_parts) do
table.insert(one_parts, code)
end
end
end
 
for _, parts in ipairs(all_parts) do
table.insert(formatted_specs, do_gender_spec(spec, parts))
end
end
 
if #extra_cats > 0 then
for _, cat in ipairs(extra_cats) do
table.insert(categories, cat)
end
end
 
if lang then
-- Do some additional gender checks if a language was given
-- Is this an incomplete gender?
if spec.spec:find("?") then
table.insert(categories, "Requests for gender in " .. lang:getCanonicalName() .. " entries")
end
-- Check if the specification is valid
--elseif langinfo.genders then
-- local valid_genders = {}
-- for _, g in ipairs(langinfo.genders) do valid_genders[g] = true end
--
-- if not valid_genders[spec.spec] then
-- local valid_string = {}
-- for i, g in ipairs(langinfo.genders) do valid_string[i] = g end
-- error('The gender specification "' .. spec.spec .. '" is not valid for ' .. langinfo.names[1] .. ". Valid are: " .. table.concat(valid_string, ", "))
-- end
--end
end
 
is_nounclass = false
end
 
-- Ensure that the specifications are either all noun classes, or none are.
if all_is_nounclass == nil then
all_is_nounclass = is_nounclass
elseif all_is_nounclass ~= is_nounclass then
error("Noun classes and genders cannot be mixed. Please use either one or the other.")
end
end
 
if lang and pos_for_cat then
for i, cat in ipairs(categories) do
categories[i] = cat:gsub("POS", pos_for_cat)
end
end
 
if is_nounclass then
-- Add the processed codes together with slashes
return '<span class="gender">class ' .. table.concat(formatted_specs, "/") .. "</span>", categories
else
-- Add the processed codes together with " or "
return '<span class="gender">' .. table.concat(formatted_specs, " or ") .. "</span>", categories
end
return ret .. categories, is_nounclass
end