Modul:sl-headword
Bu modul uchun Modul:sl-headword/doc nomli hujjat sahifasini yaratishingiz mumkin
local m_params = require("Module:parameters")
local m_str_utils = require("Module:string utilities")
local find = m_str_utils.find
local lower = m_str_utils.lower
local u = m_str_utils.char
local lang = require("Module:languages").getByCode("sl")
local export = {}
local function do_headwords(data)
-- If the first headword given is "-", then skip the check.
if data.heads[1] == "-" then
data.heads[1] = mw.title.getCurrentTitle().subpageText
return false
end
for i, head in ipairs(data.heads) do
if not require("Module:sl-common").has_accents(head) then
table.insert(data.categories, "Requests for accents in Slovene entries")
end
end
return true
end
local function do_genders(data)
local valid_genders = {
["m"] = true,
["m-an"] = true,
["m-in"] = true,
["f"] = true,
["n"] = true,
["m-d"] = true,
["f-d"] = true,
["n-d"] = true,
["m-p"] = true,
["f-p"] = true,
["n-p"] = true,
}
for i, g in ipairs(data.genders) do
data.genders[i] = g
-- Categorize by gender, in addition to what's done already by [[Module:gender and number]]
if g == "m-an" then
table.insert(data.categories, "Slovene masculine animate nouns")
elseif g == "m-in" then
table.insert(data.categories, "Slovene masculine inanimate nouns")
end
end
end
local function do_comparatives(data, comparatives, check_accents)
local SUBPAGENAME = mw.title.getCurrentTitle().subpageText
--local encoded_head = data.heads[1]
--if encoded_head == SUBPAGENAME then
-- encoded_head = nil
--end
local comp_parts = {label = "[[Appendix:Glossary#comparative|comparative]]", request = true} --accel = {form = "comparative", lemma = encoded_head}
local sup_parts = {label = "[[Appendix:Glossary#superlative|superlative]]"} --accel = {form = "superlative", lemma = encoded_head}
for i, comp in ipairs(comparatives) do
if comp == "bolj" then
table.insert(comp_parts, "[[bȍlj]] " .. (data.heads[1] or SUBPAGENAME))
table.insert(sup_parts, "[[nȁjbolj]] " .. (data.heads[1] or SUBPAGENAME))
else
table.insert(comp_parts, comp)
table.insert(sup_parts, "nȁj" .. comp)
if check_accents and not require("Module:sl-common").has_accents(comp) then
table.insert(data.categories, "Requests for accents in Slovene entries")
end
end
end
table.insert(data.inflections, comp_parts)
table.insert(data.inflections, sup_parts)
end
function export.default(frame)
local params = {
[1] = {list = "head"},
}
local args = m_params.process(frame:getParent().args, params, nil, "sl-headword", "default")
local data = {lang = lang, pos_category = frame.args[1], categories = {}, heads = args[1], inflections = {}}
local check_accents = do_headwords(data)
return require("Module:headword").full_headword(data)
end
function export.adjectives(frame)
local params = {
[1] = {list = "head"},
[2] = {list = true},
}
local args = m_params.process(frame:getParent().args, params, nil, "sl-headword", "adjectives")
local data = {lang = lang, pos_category = "adjectives", categories = {}, heads = args[1], inflections = {}}
local check_accents = do_headwords(data)
-- Decide what to do next...
if args[2][1] == "-" then
table.insert(data.inflections, {label = "not [[Appendix:Glossary#comparable|comparable]]"})
else
do_comparatives(data, args[2], check_accents)
end
return require("Module:headword").full_headword(data)
end
function export.adverbs(frame)
local params = {
[1] = {list = "head"},
[2] = {list = true},
}
local args = m_params.process(frame:getParent().args, params, nil, "sl-headword", "adverbs")
local data = {lang = lang, pos_category = "adverbs", categories = {}, heads = args[1], inflections = {}}
local check_accents = do_headwords(data)
-- Decide what to do next...
if args[2][1] and args[2][1] ~= "-" then
do_comparatives(data, args[2], check_accents)
end
return require("Module:headword").full_headword(data)
end
function export.nouns(frame)
local params = {
[1] = {list = "head"},
[2] = {list = "g", default = "?"},
["f"] = {list = true},
["m"] = {list = true},
}
local args = m_params.process(frame:getParent().args, params, nil, "sl-headword", "nouns")
local data = {lang = lang, pos_category = "nouns", categories = {}, heads = args[1], genders = args[2], inflections = {}}
local check_accents = do_headwords(data)
do_genders(data)
-- Female equivalent
if #args["f"] > 0 then
args["f"].label = "female equivalent"
if check_accents then
for i, form in ipairs(args["f"]) do
if not require("Module:sl-common").has_accents(form) then
table.insert(data.categories, "Requests for accents in Slovene noun entries")
end
end
end
-- Tone check
for i, form in ipairs(args["f"]) do
local found_tonal = false
local found_stress = false
local found_ambiguous = false
form = lower(form)
if find(form, "[ȃȇȋȏȗȓāēīōūȁȅȉȍȕẹọ" .. u(0x0304) .. "]") then
found_tonal = true
end
if find(form, "[êô]") then
found_stress = true
end
if find(form, "[áéíóúŕàèìòù]") then
found_ambiguous = true
end
if found_stress then
require("Module:debug").track("sl-headword/stress")
elseif found_ambiguous then
require("Module:debug").track("sl-headword/ambiguous")
elseif found_tonal then
require("Module:debug").track("sl-headword/tonal")
end
end
table.insert(data.inflections, args["f"])
end
-- Male equivalent
if #args["m"] > 0 then
args["m"].label = "male equivalent"
if check_accents then
for i, form in ipairs(args["m"]) do
if not require("Module:sl-common").has_accents(form) then
table.insert(data.categories, "Requests for accents in Slovene noun entries")
end
end
end
-- Tone check
for i, form in ipairs(args["m"]) do
local found_tonal = false
local found_stress = false
local found_ambiguous = false
form = lower(form)
if find(form, "[ȃȇȋȏȗȓāēīōūȁȅȉȍȕẹọ" .. u(0x0304) .. "]") then
found_tonal = true
end
if find(form, "[êô]") then
found_stress = true
end
if find(form, "[áéíóúŕàèìòù]") then
found_ambiguous = true
end
if found_stress then
require("Module:debug").track("sl-headword/stress")
elseif found_ambiguous then
require("Module:debug").track("sl-headword/ambiguous")
elseif found_tonal then
require("Module:debug").track("sl-headword/tonal")
end
end
table.insert(data.inflections, args["m"])
end
return require("Module:headword").full_headword(data)
end
function export.proper_nouns(frame)
local params = {
[1] = {list = "head"},
[2] = {list = "g", default = "?"},
["f"] = {list = true},
}
local args = m_params.process(frame:getParent().args, params, nil, "sl-headword", "proper_nouns")
local data = {lang = lang, pos_category = "proper nouns", categories = {}, heads = args[1], genders = args[2], inflections = {}}
local check_accents = do_headwords(data)
do_genders(data)
-- Female equivalent
if #args["f"] > 0 then
args["f"].label = "female equivalent"
if check_accents then
for i, form in ipairs(args["f"]) do
if not require("Module:sl-common").has_accents(form) then
table.insert(data.categories, "Requests for accents in Slovene noun entries")
end
end
end
table.insert(data.inflections, args["f"])
end
return require("Module:headword").full_headword(data)
end
function export.verbs(frame)
local params = {
[1] = {list = "head"},
[2] = {default = "?"},
["impf"] = {list = true},
["pf"] = {list = true},
}
local args = m_params.process(frame:getParent().args, params, nil, "sl-headword", "verbs")
local data = {lang = lang, pos_category = "verbs", categories = {}, heads = args[1], genders = {args[2]}, inflections = {}}
local check_accents = do_headwords(data)
-- Check aspect
if data.genders[1] == "impf" then
table.insert(data.categories, "Slovene imperfective verbs")
if #args["impf"] > 0 then
error("Imperfective verbs cannot have an imperfective equivalent")
end
-- Perfective equivalents
if #args["pf"] > 0 then
if check_accents then
for _, form in ipairs(args["pf"]) do
if require("Module:sl-common").has_accents(form) then
table.insert(data.categories, "Requests for accents in Slovene verb entries")
end
end
end
args["pf"].label = "perfective"
table.insert(data.inflections, args["pf"])
end
elseif data.genders[1] == "pf" then
table.insert(data.categories, "Slovene perfective verbs")
if #args["pf"] > 0 then
error("Perfective verbs cannot have a perfective equivalent")
end
-- Imperfective equivalents
if #args["impf"] > 0 then
if check_accents then
for _, form in ipairs(args["impf"]) do
if require("Module:sl-common").has_accents(form) then
table.insert(data.categories, "Requests for accents in Slovene verb entries")
end
end
end
args["impf"].label = "imperfective"
table.insert(data.inflections, args["impf"])
end
elseif data.genders[1] == "both" then
data.genders = {"impf", "pf"}
table.insert(data.categories, "Slovene biaspectual verbs")
if #args["impf"] > 0 or #args["pf"] > 0 then
error("Bispectual verbs cannot have an imperfective or perfective equivalent")
end
else
data.genders = {"?"}
table.insert(data.categories, "Requests for aspect in Slovene entries")
end
return require("Module:headword").full_headword(data)
end
return export