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 | local function generate_gen_sg(word) | ||
local genitive = {} | |||
local | for alt in gmatch(word, "[^,]+") do | ||
table.insert(genitive, alt) | |||
end | |||
return genitive | |||
end | |||
local function generate_nom_pl(word) | |||
local plural = {} | |||
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 | ||
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)}, | ||
[ | ["gen"] = {}, | ||
[ | ["pl"] = {}, | ||
["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"]} | ||
-- 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) | |||
else | else | ||
table.insert(data.genders, "?") | table.insert(data.genders, "?") | ||
end | end | ||
end | end | ||
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][ | if not args[3][2] and data.pos_category == "nouns" then | ||
table.insert(args[3], PAGENAME | table.insert(args[3], table.concat(generate_nom_pl(PAGENAME))) | ||
end | end | ||
if | if #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].label = "plural" | args[3].label = "plural" | ||
table.insert(data.inflections, args[3]) | table.insert(data.inflections, args[3]) | ||
end | end | ||
end | end | ||
end | end | ||