Module:qhv-headword: Difference between revisions

No edit summary
No edit summary
Line 5: Line 5:
local find = mw.ustring.find
local find = mw.ustring.find
local match = mw.ustring.match
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local u = mw.ustring.char
local split = mw.text.split
local split = mw.text.split
local gsplit = mw.text.gsplit
local gsplit = mw.text.gsplit
local PAGENAME = mw.title.getCurrentTitle().text


local legal_gender = {
local legal_gender = {
Line 50: Line 53:
end
end


local function generate_genitive(word, args, pass, decl_type)
local function generate_gen_sg(word)
word = PAGENAME
local genitive = {}
local pass = {forms = {}, categories = {}}
for alt in gmatch(word, "[^,]+") do
pass.head = args["head"] or nil
table.insert(genitive, alt)
if not m_data[word] then
end
local decl_args = require("Module:parameters").process(args, m_data[decl_type].params, true)
return genitive
m_data[decl_type](decl_args, pass)
end
return pass.forms["gen_sg"]
 
else
local function generate_nom_pl(word)
m_data[word](args, pass)
local plural = {}
return pass.forms["gen_sg"]
for alt in gmatch(word, "[^,]+") do
table.insert(plural, alt)
end
end
return plural
end
end


Line 68: Line 73:
function export.show(frame)
function export.show(frame)
local parent_args = frame:getParent().args
local parent_args = frame:getParent().args
PAGENAME = mw.title.getCurrentTitle().text
local head = parent_args["head"]; if head == "" then head = nil end
local head = parent_args["head"]; if head == "" then head = nil end
Line 87: Line 91:
local params = {
local params = {
[1] = {list = "g", default = detect_gender(PAGENAME)},
[1] = {list = "g", default = detect_gender(PAGENAME)},
[2] = {list = "gen"},
["gen"] = {},
[3] = {list = "pl"},
["pl"] = {},
[4] = {list = "dim"},
["head"] = {},
["head"] = {},
["m"] = {list = true},
["m"] = {list = true},
Line 97: Line 100:
local args = require("Module:parameters").process(args, params)
local args = require("Module:parameters").process(args, params)
data.heads = {args["head"]}
data.heads = {args["head"]}
local decl_type = require("Module:qhv-noun").detect_decl(table.concat(data.heads))
local pass = {forms = {}, categories = {}}
pass.head = args["head"] or nil
-- Gender
-- Gender
Line 105: Line 105:
if legal_gender[g] then
if legal_gender[g] then
table.insert(data.genders, g)
table.insert(data.genders, g)
table.insert(data.categories, "High Valyrian " .. gender_names[g] .. " " .. data.pos_category)
if g == "p" then
table.insert(data.categories, "High Valyrian pluralia tantum")
end
else
else
table.insert(data.genders, "?")
table.insert(data.genders, "?")
end
end
end
end
-- Genitive
if not args[2][1] then
table.insert(args[2], generate_genitive(data.heads, args, data))
end
for i, form in ipairs(args[2]) do
args[2][i] = {term = form}
end
args[2].accel = {form = "gen|s"}
args[2].label = "genitive"
table.insert(data.inflections, args[2])
if args[1][1] ~= "p" then
if args[1][1] ~= "p" then
-- Genitive
if not args[2][2] then
table.insert(args[2], table.concat(generate_gen_sg(PAGENAME)))
end
for i, form in ipairs(args[2]) do
args[2][i] = {term = form}
end
args[2].label = "genitive"
table.insert(data.inflections, args[2])
-- Plural
-- Plural
if not args[3][1] and data.pos_category == "nouns" then
if not args[3][2] and data.pos_category == "nouns" then
table.insert(args[3], PAGENAME .. "en")
table.insert(args[3], table.concat(generate_nom_pl(PAGENAME)))
end
end
if args[3][1] == "-" then
if #args[3] > 0 then
table.insert(data.inflections, {label = "no plural"})
table.insert(data.categories, "German uncountable nouns")
elseif #args[3] > 0 then
for i, form in ipairs(args[3]) do
for i, form in ipairs(args[3]) do
args[3][i] = {term = form}
args[3][i] = {term = form}
end
end
args[3].accel = {form = "p"}
args[3].label = "plural"
args[3].label = "plural"
table.insert(data.inflections, args[3])
table.insert(data.inflections, args[3])
end
end
end
-- Diminutive
if #args[4] > 0 then
for i, form in ipairs(args[4]) do
args[4][i] = {term = form, genders = {"n"}}
end
args[4].accel = {form = "diminutive", gender = "n"}
args[4].label = "diminutive"
table.insert(data.inflections, args[4])
end
-- Other gender
if #args.f > 0 then
args.f.label = "female"
table.insert(data.inflections, args.f)
end
if #args.m > 0 then
args.m.label = "male"
table.insert(data.inflections, args.m)
end
end
end
end