Module:siwa-headword: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
local export = {}
local pos_functions = {}
 
local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit
 
local PAGENAME = mw.title.getCurrentTitle().text
local NAMESPACE = mw.title.getCurrentTitle().nsText
local SUBPAGENAME = mw.title.getCurrentTitle().subpageText


local export = {}
local legal_gender = {
["in"] = true,
["an"] = true,
}
 
local gender_names = {
["in"] = "inanimate",
["an"] = "animate",
}
 
local lang = require("Module:languages").getByCode("siwa")
local m_n = require("Module:siwa-noun")


function format_pos(term, poscat)
local function glossary_link(entry, text)
if poscat == "noun" then
return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. (text or entry) .. "]]"
--return "'''" .. term .. "'''"
end
return "'''" .. term .. "'''"
end
end


Line 14: Line 35:
-- This is the only function that can be invoked from a template.
-- This is the only function that can be invoked from a template.
function export.show(frame)
function export.show(frame)
local args = getArgs(frame)
if NAMESPACE == "Template" and SUBPAGENAME ~= "doc" then return end
local parent_args = frame:getParent().args
-- The part of speech. This is also the name of the category that
-- entries go in. However, the two are separate (the "cat" parameter)
-- because you sometimes want something to behave as an adjective without
-- putting it in the adjectives category.
local poscat = args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local PAGENAME = mw.title.getCurrentTitle().text
local head = args[2] or PAGENAME
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
if head == "" then head = nil end
local class = frame.args[2]; if class == "" then class = nil end
--local data = {lang = lang, pos_category = (postype and postype .. " " or "") .. poscat, categories = {}, heads = {head}, genders = {}, inflections = {}}
local data = {
lang = lang,
heads = {},
inflections = {},
genders = {},
pos_category = poscat,
categories = {"Siwa " .. poscat}
}
if poscat == "adjectives" then
if pos_functions[poscat] then
if PAGENAME:find("^-") then
pos_functions[poscat](class, parent_args, data)
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic adjective-forming suffixes"}
end
adjective(args, data)
elseif poscat == "adverbs" then
if SUBPAGENAME:find("^-") then
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic adverb-forming suffixes"}
end
adverb(args, data)
elseif poscat == "determiners" then
adjective(args, data)
elseif poscat == "nouns" then
if PAGENAME:find("^-") then
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic noun-forming suffixes"}
end
noun_gender(args, data)
elseif poscat == "proper nouns" then
noun_gender(args, data)
elseif poscat == "verbs" then
if PAGENAME:find("^-") then
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic verb-forming suffixes"}
end
end
end
return format_pos(head, poscat)
return require("Module:headword").full_headword(data)
end
end


-- Display information for a noun's gender
pos_functions.nouns = function(class, args, data)
-- This is separate so that it can also be used for proper nouns
local params = {
function noun_gender(args, data)
[1] = {required = true},
local valid_genders = {
[2] = {},
["m"] = true,
["m"] = {list = true},
["f"] = true,
["head"] = {default = PAGENAME},
["n"] = true,
}
["m-p"] = true,
["f-p"] = true,
local args = require("Module:parameters").process(args, params)
["n-p"] = true}
data.heads = {args["head"]}
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
table.insert(data.genders, args[1])
local g = args[1] or ""; if g == "" then g = "?" end
if args[2] then table.insert(data.genders, args[2]) end
local i = 2
while g ~= "" do
table.insert(data.inflections, args.m or m_n.head)
if not valid_genders[g] then
inflections[1].label = "marked"
g = "?"
end
-- If any of the specifications is a "?", add the entry
-- to a cleanup category.
if g == "?" then
table.insert(data.categories, "Requests for gender in Proto-Germanic entries")
elseif g == "m-p" or g == "f-p" or g == "n-p" then
table.insert(data.categories, "Proto-Germanic pluralia tantum")
end
table.insert(data.genders, g)
g = args["g" .. i] or ""
i = i + 1
end
end
end


function adjective(args, data)
pos_functions.adjectives = function(class, args, data)
local adverb = args["adv"]; if adverb == "" then adverb = nil end
local params = {
local comparative = args[1]; if comparative == "" then comparative = nil end
[1] = {list = "eq"},
local superlative = args[2]; if superlative == "" then superlative = nil end
[2] = {list = "comp"},
[3] = {list = "sup"},
["unc"] = {type = "boolean"},
["indecl"] = {type = "boolean"},
["head"] = {},
}
if adverb then
local args = require("Module:parameters").process(args, params)
table.insert(data.inflections, {label = "adverb", adverb})
local isdet = data.pos_category == "determiners"
end
data.heads = {args["head"]}
if comparative then
table.insert(data.categories, "High Valyrian " .. data.pos_category)
table.insert(data.inflections, {label = "comparative", comparative})
if args["unc"] or isdet then
end
table.insert(data.inflections, {label = "not " .. glossary_link("comparable")})
if not isdet then table.insert(data.categories, "High Valyrian uncomparable adjectives") end
if superlative then
elseif args["indecl"] then
table.insert(data.inflections, {label = "superlative", superlative})
table.insert(data.inflections, {label = glossary_link("indeclinable")})
table.insert(data.categories, "High Valyrian indeclinable " .. data.pos_category)
else
args[1] = require("Module:qhv-adj/head").fetch("eq")
args[2] = require("Module:qhv-adj/head").fetch("comp")
args[3] = require("Module:qhv-adj/head").fetch("sup")
args[1].label = glossary_link("equative")
args[2].label = glossary_link("comparative")
args[3].label = glossary_link("superlative")
table.insert(data.inflections, args[1])
table.insert(data.inflections, args[2])
table.insert(data.inflections, args[3])
end
end
end
end


function adverb(args, data)
pos_functions["proper nouns"] = pos_functions.nouns
local adjective = args["adj"]; if adjective == "" then adjective = nil end
pos_functions["determiners"] = pos_functions.adjectives
local comparative = args[1]; if comparative == "" then comparative = nil end
 
local superlative = args[2]; if superlative == "" then superlative = nil end
pos_functions.verbs = function(class, args, data)
local params = {
[1] = {list = "pres"},
[2] = {list = "subj"},
[3] = {list = "pp"},
["head"] = {},
}
if adjective then
local args = require("Module:parameters").process(args, params)
table.insert(data.inflections, {label = "adjective", adjective})
data.heads = {args["head"]}
end
if comparative then
table.insert(data.categories, "High Valyrian " .. data.pos_category)
table.insert(data.inflections, {label = "comparative", comparative})
end
if superlative then
args[1] = require("Module:qhv-verb/head").fetch("act_ind_prs_1sg")
table.insert(data.inflections, {label = "superlative", superlative})
args[2] = require("Module:qhv-verb/head").fetch("act_sub_prs_1sg")
end
args[3] = require("Module:qhv-verb/head").fetch("act_part_prf")
args[1].label = "first-person singular present indicative"
args[2].label = "first-person singular present subjunctive"
args[3].label = "perfect participle"
table.insert(data.inflections, args[1])
table.insert(data.inflections, args[2])
table.insert(data.inflections, args[3])
end
end


return export
return export

Navigation menu