Modul:ro-headword
Bu modul uchun Modul:ro-headword/doc nomli hujjat sahifasini yaratishingiz mumkin
local export = {}
local pos_functions = {}
local tili = require("Module:tili").getByCode("ro")
-- 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
NAMESPACE = mw.title.getCurrentTitle().nsText
PAGENAME = mw.title.getCurrentTitle().text
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local params = {
["bosh"] = {},
["suff"] = {type = "boolean"},
["cat"] = {list = true},
}
if pos_functions[poscat] then
for key, val in pairs(pos_functions[poscat].params) do
params[key] = val
end
end
args = require("Module:parameters").process(args, params)
local genders = {}
local inflections = {}
local categories = args["suff"] and {"Romanian suffixes"} or {"Ruminchada " .. poscat}
local sort_key = {}
local appendix = {}
for key, val in ipairs(args.cat) do
table.insert(categories, "Ruminchada " .. val)
end
if pos_functions[poscat] then
local head2 = pos_functions[poscat].func(class, args, genders, inflections, categories, poscat, appendix)
head = head or head2
end
if #appendix == 0 then
appendix[1] = ""
end
return
require("Module:headword").full_headword(tili, sc, head, nil, genders, inflections, categories, nil) .. appendix[1]
end
local function is_equal(a1, a2)
if a1 == a2 then
return true
end
if #a1 == #a2 then
for i = 1, #a1 do
if a1[i] ~= a2[i] then
return false
end
end
return true
else
return false
end
end
pos_functions["adjectives"] = {
params = {
[1] = {},
["f"] = {list = true, allow_holes = true},
["mp"] = {list = true, allow_holes = true},
["fp"] = {list = true, allow_holes = true},
},
func = function(class, args, genders, inflections, categories, poscat, appendix)
local old = true
if poscat == "determiners" then
old = false
end
if old then
args[1] = tonumber(args[1])
if args[1] then
appendix[1] = " <sup>[[Appendix:Rumin " .. args[1] .. "-form adjective declension|" .. args[1] .." nom/acc form" .. (args[1] == 1 and "" or "s") .. "]]</sup>"
end
else
local mode = args[1]
if mode == "inv" then
table.insert(inflections, {label = "invariable"})
table.insert(categories, "Romanian invariable adjectives")
else
table.insert(genders, "m")
table.insert(genders, "n")
local f, mp, fp = args["f"], args["mp"], args["fp"]
if not f[1] then
table.insert(f, require("Module:ro-adjective").make_feminine(PAGENAME))
end
if not mp[1] then
table.insert(mp, require("Module:ro-adjective").make_plural(PAGENAME, "m"))
end
if not fp[1] then
if mode == "i" then
fp = mp
else
for key, form in ipairs(f) do
table.insert(fp, require("Module:ro-adjective").make_plural(form, "f"))
end
end
end
if #f == 1 and f[1] == PAGENAME then
table.insert(genders, 2, "f")
else
f.label = "feminine singular"
table.insert(inflections, f)
end
if is_equal(mp, fp) then
mp.label = "plural"
table.insert(inflections, mp)
else
mp.label = "masculine plural"
table.insert(inflections, mp)
fp.label = "feminine and neuter plural"
table.insert(inflections, fp)
end
end
end
return args["head"]
end
}
pos_functions["determiners"] = pos_functions["adjectives"]
pos_functions["nouns"] = {
params = {
[1] = {list = "g", default = "?"},
[2] = {list = "pl"},
["f"] = {list = true},
["m"] = {list = true},
["sg"] = {},
["pl=_qual"] = {list = true, allow_holes = true},
["f=_qual"] = {list = true, allow_holes = true},
["m=_qual"] = {list = true, allow_holes = true},
["sort"] = {}
},
func = function(class, args, genders, inflections, categories, poscat, appendix)
local type
for _, val in ipairs(args[1]) do
table.insert(genders, val)
if val:match("p") then
type = "plural"
break
end
end
if args["suff"] then
poscat = "suffixes"
table.insert(categories, "Romanian noun-forming suffixes")
type = "suffix"
end
if type == "plural" then
while #args[2] > 0 do
table.remove(args[2])
end
if args["sg"] then
args[2].label = "normally plural"
else
args[2].label = "plural only"
end
table.insert(categories, "Romanian pluralia tantum")
else
if args[2][1] == "-" then
while #args[2] > 0 do
table.remove(args[2])
end
args[2].label = "[[Appendix:Glossary#uncountable|uncountable]]"
if type ~= "suffix" then
table.insert(categories, "Romanian uncountable nouns")
end
elseif args[2][1] == "?" then
while #args[2] > 0 do
table.remove(args[2])
end
if type ~= "suffix" then
table.insert(categories, "Romanian nouns with unknown or uncertain plurals")
end
else
args[2].label = "plural"
args[2].accel = "plural-form-of"
if #args[2] > 0 then
for key, val in ipairs(args[2]) do
if ((val == "e" or val == "uri") and args[1][1] == "n") or (val == "i" and args[1][1] == "m") then
args[2][key] = PAGENAME .. val
end
end
for key, val in ipairs(args[2]) do
if not mw.title.new(val).exists then
table.insert(categories, "Missing Romanian plurals")
end
if args.pl_qual[key] then
args[2][key] = {term = args[2][key], qualifiers = {args.pl_qual[key]}}
end
end
if type ~= "suffix" then
table.insert(categories, "Romanian countable nouns")
end
else
if type ~= "suffix" then
args[2].request = true
end
end
end
end
if args[2].label then
table.insert(inflections, args[2])
end
if args["sg"] then
if type == "plural" then
table.insert(inflections, {label = "singular", args["sg"]})
else
error("Parameter \"sg\" can only be used for pluralia tantum")
end
end
if #args["f"] > 0 then
args["f"].label = "feminine equivalent"
if args.f_qual.maxindex > 0 then
for key, val in ipairs(args["f"]) do
if args.f_qual[key] then
args["f"][key] = {term = args["f"][key], qualifiers = {args.f_qual[key]}}
end
end
end
table.insert(inflections, args["f"])
end
if #args["m"] > 0 then
args["m"].label = "feminine equivalent"
if args.m_qual.maxindex > 0 then
for key, val in ipairs(args["m"]) do
if args.m_qual[key] then
args["m"][key] = {term = args["m"][key], qualifiers = {args.m_qual[key]}}
end
end
end
table.insert(inflections, args["m"])
end
return args["head"]
end
}
function format_conj(conj)
if not conj then
return ''
else
if conj == 1 then
return ' <small>[[Appendix:Romanian first conjugation|1st conj.]]</small>'
elseif conj == 2 then
return ' <small>[[Appendix:Romanian second conjugation|2nd conj.]]</small>'
elseif conj == 3 then
return ' <small>[[Appendix:Romanian third conjugation|3rd conj.]]</small>'
elseif conj == 4 then
return ' <small>[[Appendix:Romanian fourth conjugation|4th conj.]]</small>'
else
return ' <small>[please provide conjugation]</small>'
end
end
end
function detect_conj(head, ind)
local inf, conj = mw.ustring.match(require("Module:links").remove_links(head), '^a (.+)') or error('Head must begin with "a"')
inf = mw.ustring.gsub(inf, 'á', 'a')
inf = mw.ustring.gsub(inf, 'í', 'i')
inf = mw.ustring.gsub(inf, 'î́', 'î')
if mw.ustring.match(inf, '[iî]$') then
conj = 4
elseif mw.ustring.match(inf, 'e$') then
conj = 3
elseif mw.ustring.match(inf, 'ea$') then
if mw.ustring.match(inf, '[cg]hea$') then
conj = 1
elseif ind then
if mw.ustring.match(ind, 'ează$') then
conj = 1
else
conj = 2
end
end
elseif mw.ustring.match(inf, 'a$') then
conj = 1
else
error('Unrecognized verb ending')
end
return conj
end
pos_functions["verbs"] = {
params = {
[1] = {list = "pres_3sg"},
[2] = {list = "past"},
["inf"] = {},
["conj"] = {type = "number"},
["pres_3sg_qual"] = {list = "pres_3sg=_qual", allow_holes = true},
["past_qual"] = {list = "past=_qual", allow_holes = true}
},
func = function(class, args, genders, inflections, categories, poscat, appendix)
local multi = false
if mw.ustring.match(PAGENAME, ' ') then
multi = true
end
if #args[1] > 0 and args.pres_3sg_qual.maxindex > 0 then
for key, val in ipairs(args[1]) do
if args.pres_3sg_qual[key] then
args[1][key] = {term = args[1][key], qualifiers = {args.pres_3sg_qual[key]}}
end
end
end
if #args[2] > 0 and args.past_qual.maxindex > 0 then
for key, val in ipairs(args[2]) do
if args.past_qual[key] then
args[2][key] = {term = args[2][key], qualifiers = {args.past_qual[key]}}
end
end
end
args[1].label = 'third-person singular present'
args[1].request = true
table.insert(inflections, args[1])
args[2].label = 'past participle'
args[2].request = true
table.insert(inflections, args[2])
local sc = require("Module:scripts").findBestScript(args.head or args.inf or PAGENAME, tili):getCode()
if not args.bosh then
if not args.inf then
if multi then
args.inf = mw.text.split(PAGENAME, ' ')
args.inf = '[[' .. table.concat(args.inf, ']] [[') .. ']]'
else
args.inf = PAGENAME
end
end
if sc == 'Cyrl' then
args.bosh = 'а ' .. args.inf --Cyrillic 'а'
else
args.bosh = 'a ' .. args.inf
end
end
local conj
if multi or NAMESPACE ~= '' or sc == 'Cyrl' then
conj = args.conj or 0
else
conj = detect_conj(args.bosh, args[1][1])
if args.conj and args.conj ~= conj then
require("Module:debug").track('ro-verb with wrong conjugation')
end
end
if conj and NAMESPACE == '' then
if conj == 1 then
table.insert(categories, 'Romanian verbs in 1st conjugation')
elseif conj == 2 then
table.insert(categories, 'Romanian verbs in 2nd conjugation')
elseif conj == 3 then
table.insert(categories, 'Romanian verbs in 3rd conjugation')
elseif conj == 4 then
table.insert(categories, 'Romanian verbs in 4th conjugation')
else
table.insert(categories, 'Romanian entries needing inflection')
end
end
appendix[1] = format_conj(conj)
return args.bosh
end
}
return export