Skilnad mellom versjonar av «Modul:kyn og tal»

Frå Mållekken
Hopp til navigering Hopp til søk
(Teke frå Wikipedia)
 
s (Tek burt)
Merke: Tømming
 
Line 1: Line 1:
local export = {}
local codes = {}
codes["?"] = {type = "anna", display = '<abbr title="ukjent kyn">?</abbr>'}
-- Kyn
codes["m"] = {type = "kyn", cat = "hannkyn POS", display = '<abbr title="hannkyn">ha</abbr>'}
codes["ha"] = {type = "kyn", cat = "hannkyn POS", display = '<abbr title="hannkyn">ha</abbr>'}
codes["f"] = {type = "kyn", cat = "hokyn POS", display = '<abbr title="hokyn">ho</abbr>'}
codes["ho"] = {type = "kyn", cat = "hokyn POS", display = '<abbr title="hokyn">ho</abbr>'}
codes["n"] = {type = "kyn", cat = "neuter POS", display = '<abbr title="inkjekyn">in</abbr>'}
codes["in"] = {type = "kyn", cat = "neuter POS", display = '<abbr title="inkjekyn">in</abbr>'}
-- Tal
codes["s"] = {type = "tal", display = '<abbr title="eintal">et</abbr>'}
codes["et"] = {type = "tal", display = '<abbr title="eintal">et</abbr>'}
codes["d"] = {type = "tal", cat = "dualia tantum", display = '<abbr title="tvotal">tt</abbr>'}
codes["tt"] = {type = "tal", cat = "dualia tantum", display = '<abbr title="tvotal">tt</abbr>'}
codes["p"] = {type = "tal", cat = "pluralia tantum", display = '<abbr title="mangtal">mt</abbr>'}
codes["mt"] = {type = "tal", cat = "pluralia tantum", display = '<abbr title="mangtal">mt</abbr>'}


local combined_codes = {}
combined_codes["mf"] = {codes = {"m", "f"}}
combined_codes["haho"] = {codes = {"m", "f"}}
combined_codes["mfbysense"] = {codes = {"m", "f"}, cat = "hannkyn og hokyn POS etter kjensla"}
local codetype_cats = {}
codetype_cats["kyn"] = "POS med fleire kyn"
function export.show_list(frame)
local args = frame.args
local lang = args["lang"]; if lang == "" then lang = nil end
local list = {}
local i = 1
while args[i] and args[i] ~= "" do
table.insert(list, args[i])
i = i + 1
end
return export.format_list(list, lang)
end
function export.format_list(specs, lang, pos_for_cat, sort_key)
local text, cats = export.format_kyns(specs, lang, pos_for_cat)
if #cats == 0 then
return text
end
return text .. require("Module:utilities").format_categories(cats, lang, sort_key)
end
function export.format_kyns(specs, lang, pos_for_cat)
local formatted_specs = {}
local categories = {}
local seen_types = {}
local category_text = ""
local all_is_nounclass = nil
local function do_kyn_spec(spec, parts)
local types = {}
for key, code in ipairs(parts) do
if not codes[code] then
error('The tag "' .. code .. '" in the gender specification "' .. spec.spec .. '" is not valid.')
end
local typ = codes[code].type
if typ ~= "other" and types[typ] then
error('The gender specification "' .. spec.spec .. '" contains multiple tags of type "' .. typ .. '".')
end
types[typ] = true
if spec.qualifiers and #spec.qualifiers > 0 then
parts[key] = require("Module:qualifier").format_qualifier(spec.qualifiers) .. " " .. codes[code].display
else
parts[key] = codes[code].display
end
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
if #parts == 1 then
return parts[1]
end
return table.concat(parts, "&nbsp;")
end
for _, spec in ipairs(specs) do
if type(spec) ~= "table" then
spec = {spec = spec}
end
local is_nounclass
if spec.spec:find("^[1-9]") or spec.spec:find("^c[^-]") then
is_nounclass = true
code = spec.spec:gsub("^c", "")
local text
if code == "?" then
text = '<abbr class="noun-class" title="noun class missing">?</abbr>'
else
text = '<abbr class="noun-class" title="noun class ' .. code .. '">' .. code .. "</abbr>"
if lang and pos_for_cat then
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
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_kyn_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_kyn_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
if spec.spec:find("?") then
table.insert(categories, "Requests for kyn in " .. lang:getCanonicalName() .. " entries")
end
end
is_nounclass = false
end
if all_is_nounclass == nil then
all_is_nounclass = is_nounclass
elseif all_is_nounclass ~= is_nounclass then
error("Noun classes and kyns 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
return '<i>class ' .. table.concat(formatted_specs, "/") .. "</i>", categories
else
return '<i>' .. table.concat(formatted_specs, " eller ") .. "</i>", categories
end
end
return export

Siste versjonen frå 31. mai 2021 kl. 01:22