Module:qhv-headword: Difference between revisions

From Linguifex
Jump to navigation Jump to search
(Created page with "local export = {} local function link(term) return "" .. term .. "" end local function ncategories(categories) local out_categories = {} fo...")
 
No edit summary
 
(100 intermediate revisions by the same user not shown)
Line 1: Line 1:
local export = {}
local export = {}
local pos_functions = {}


local function link(term)
local sub = mw.ustring.sub
return "[[Contionary:" .. term .. "|" .. term .. "]]"
local find = mw.ustring.find
end
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 function ncategories(categories)
local PAGENAME = mw.title.getCurrentTitle().text
local out_categories = {}
local NAMESPACE = mw.title.getCurrentTitle().nsText
for key, cat in ipairs(categories) do
local SUBPAGENAME = mw.title.getCurrentTitle().subpageText
out_categories[key] = "[[Category:" .. cat .. "]]"
 
local legal_gender = {
["aq"] = true,
["lun"] = true,
["sol"] = true,
["ter"] = true,
["?"] = true,
}
 
local gender_names = {
["aq"] = "aquatic",
["lun"] = "lunar",
["sol"] = "solar",
["ter"] = "terrestrial",
["?"] = "unknown",
}
 
local legal_verb_classes = { -- TBD
["1"] = true,
["2"] = true,
["3"] = true,
["4"] = true,
["5"] = true,
["6"] = true,
["7"] = true,
}
 
local lang = require("Module:languages").getByCode("qhv")
local m_data = require("Module:qhv-noun/data")
 
local function glossary_link(entry, text)
text = text or entry
return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. text .. "]]"
end
 
local function detect_gender(word)
local ending = word:sub(-1)
if word:find("illa$") then
return "aq"
elseif word:find("[aeioy]$") then
return "lun"
elseif ending == "r" then
return "aq"
elseif ending == "s" then
return "sol"
elseif ending == "n" then
return "ter"
else return "?" end
end
 
local function generate_gen_sg(word, rc, rp)
local genitive = {}
local r = rc and "gen_co"
for alt in gmatch(require("Module:qhv-noun/head").pass_to_module((rc and "gen_co" or rp and "gen_pa" or "gen_sg"), word), "[^,]+") do
table.insert(genitive, alt)
end
end
 
return genitive
return table.concat(out_categories, "")
end
end


local function head_format(POS, word, gender)
local function generate_nom_pl(word)
if POS == "noun" then
local plural = {}
gender = require("Module:getn").format_list(gender)
for alt in gmatch(require("Module:qhv-noun/head").pass_to_module("nom_pl", word), "[^,]+") do
local genitive = "aaaaa"
table.insert(plural, alt)
return "'''" .. word .. "''' ''" .. gender .. "'' (''genitive'' '''" .. link(genitive) .. "''')"
end
end
end
return plural
end


-- The main entry point.
-- The main entry point.
-- 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 = frame:getParent().args
if NAMESPACE == "Template" and SUBPAGENAME ~= "doc" then return end
PAGENAME = mw.title.getCurrentTitle().text
local parent_args = frame:getParent().args
local head = args["head"]; if head == "" then head = nil end
local head = parent_args["head"] or PAGENAME:match("%s") and require("Module:linkeach").link_for_modules(PAGENAME) or nil
local categories = {}
-- 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 = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local postype = args["type"]; if postype == "" then postype = nil end
local class = frame.args[2]; if class == "" then class = nil end
local word = args[2] or PAGENAME
local gender = mw.text.split(args[3], " ") or detect_gender(word)
local data = {
lang = lang,
heads = head,
inflections = {},
genders = {},
pos_category = poscat,
categories = {"Contionary"},
}
if pos_functions[poscat] then
pos_functions[poscat](class, parent_args, data)
end
return head_format(poscat, word) .. ncategories(categories)
return require("Module:headword").full_headword(data)
end
end


 
pos_functions.nouns = function(class, args, data)
 
local params = {
-- Display information for a noun's gender
[1] = {default = detect_gender(PAGENAME)},
-- This is separate so that it can also be used for proper nouns
[2] = {default = PAGENAME},
function noun_gender(args, data)
["nopl"] = {},
local valid_genders = {
["noinf"] = {type = "boolean", default = false},
["m"] = true,
["gen"] = {},
["f"] = true,
["pl"] = {},
["n"] = true,
["head"] = {},
["m-p"] = true,
["rc"] = {type = "boolean"},
["f-p"] = true,
["rp"] = {type = "boolean"},
["n-p"] = true}
["og"] = {},
}
local args = require("Module:parameters").process(args, params)
--data.heads = {args["head"]}
table.insert(data.genders, args[1])
table.insert(data.categories, "High Valyrian " .. (args[1] == "?" and "" or gender_names[args[1]]) .. " " .. data.pos_category)
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
if not args["noinf"] then
local g = args[1] or ""; if g == "" then g = "?" end
args["gen"] = generate_gen_sg(args["og"] or args[2], args["rc"], args["rp"])
local i = 2
while g ~= "" do
for i, form in ipairs(args["gen"]) do
if not valid_genders[g] then
args["gen"][i] = {term = form}
g = "?"
end
end
-- If any of the specifications is a "?", add the entry
args["gen"].label = "genitive"
-- to a cleanup category.
table.insert(data.inflections, args["gen"])
if g == "?" then
end
table.insert(data.categories, "Requests for gender in Proto-Germanic entries")
elseif g == "m-p" or g == "f-p" or g == "n-p" then
if data.pos_category == "nouns" and not args["noinf"] then
table.insert(data.categories, "Proto-Germanic pluralia tantum")
if not args["nopl"] then
args["pl"] = generate_nom_pl(args["og"] or args[2])
for i, form in ipairs(args["pl"]) do
args["pl"][i] = {term = form}
end
args["pl"].label = "plural"
table.insert(data.inflections, args["pl"])
end
end
table.insert(data.genders, g)
g = args["g" .. i] or ""
i = i + 1
end
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

Latest revision as of 20:58, 15 May 2021



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 legal_gender = {
	["aq"] = true,
	["lun"] = true,
	["sol"] = true,
	["ter"] = true,
	["?"] = true,
}

local gender_names = {
	["aq"] = "aquatic",
	["lun"] = "lunar",
	["sol"] = "solar",
	["ter"] = "terrestrial",
	["?"] = "unknown",
}

local legal_verb_classes = { -- TBD
	["1"] = true,
	["2"] = true,
	["3"] = true,
	["4"] = true,
	["5"] = true,
	["6"] = true,
	["7"] = true,
}

local lang = require("Module:languages").getByCode("qhv")
local m_data = require("Module:qhv-noun/data")

local function glossary_link(entry, text)
	text = text or entry
	return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. text .. "]]"
end

local function detect_gender(word)
	local ending = word:sub(-1)
	if word:find("illa$") then
		return "aq"
	elseif word:find("[aeioy]$") then
		return "lun"
	elseif ending == "r" then
		return "aq"
	elseif ending == "s" then
		return "sol"
	elseif ending == "n" then
		return "ter"
	else return "?" end
end

local function generate_gen_sg(word, rc, rp)
	local genitive = {}
	local r = rc and "gen_co"
	for alt in gmatch(require("Module:qhv-noun/head").pass_to_module((rc and "gen_co" or rp and "gen_pa" or "gen_sg"), word), "[^,]+") do
		table.insert(genitive, alt)
	end
	return genitive
end

local function generate_nom_pl(word)
	local plural = {}
	for alt in gmatch(require("Module:qhv-noun/head").pass_to_module("nom_pl", word), "[^,]+") do
		table.insert(plural, alt)
	end
	return plural
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	if NAMESPACE == "Template" and SUBPAGENAME ~= "doc" then return end
	local parent_args = frame:getParent().args
	
	local head = parent_args["head"] or PAGENAME:match("%s") and require("Module:linkeach").link_for_modules(PAGENAME) or nil
	
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	local class = frame.args[2]; if class == "" then class = nil end
	
	local data = {
		lang = lang,
		heads = head,
		inflections = {},
		genders = {},
		pos_category = poscat,
		categories = {"Contionary"},
	}
	
	if pos_functions[poscat] then
		pos_functions[poscat](class, parent_args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

pos_functions.nouns = function(class, args, data)
	local params = {
		[1] = {default = detect_gender(PAGENAME)},
		[2] = {default = PAGENAME},
		["nopl"] = {},
		["noinf"] = {type = "boolean", default = false},
		["gen"] = {},
		["pl"] = {},
		["head"] = {},
		["rc"] = {type = "boolean"},
		["rp"] = {type = "boolean"},
		["og"] = {},
	}
	
	local args = require("Module:parameters").process(args, params)
	--data.heads = {args["head"]}
	
	table.insert(data.genders, args[1])
	table.insert(data.categories, "High Valyrian " .. (args[1] == "?" and "" or gender_names[args[1]]) .. " " .. data.pos_category)
	
	if not args["noinf"] then
		args["gen"] = generate_gen_sg(args["og"] or args[2], args["rc"], args["rp"])
	
		for i, form in ipairs(args["gen"]) do
			args["gen"][i] = {term = form}
		end
		
		args["gen"].label = "genitive"
		table.insert(data.inflections, args["gen"])
	end
		
	if data.pos_category == "nouns" and not args["noinf"] then
		if not args["nopl"] then
			args["pl"] = generate_nom_pl(args["og"] or args[2])
			
			for i, form in ipairs(args["pl"]) do
				args["pl"][i] = {term = form}
			end
			
			args["pl"].label = "plural"
			table.insert(data.inflections, args["pl"])
		end
	end
end

pos_functions.adjectives = function(class, args, data)
	local params = {
		[1] = {list = "eq"},
		[2] = {list = "comp"},
		[3] = {list = "sup"},
		["unc"] = {type = "boolean"},
		["indecl"] = {type = "boolean"},
		["head"] = {},
	}
	
	local args = require("Module:parameters").process(args, params)
	local isdet = data.pos_category == "determiners"
	data.heads = {args["head"]}
	
	table.insert(data.categories, "High Valyrian " .. data.pos_category)
	if args["unc"] or isdet then
		table.insert(data.inflections, {label = "not " .. glossary_link("comparable")})
		if not isdet then table.insert(data.categories, "High Valyrian uncomparable adjectives") end
	elseif args["indecl"] then
		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

pos_functions["proper nouns"] = pos_functions.nouns
pos_functions["determiners"] = pos_functions.adjectives

pos_functions.verbs = function(class, args, data)
	local params = {
		[1] = {list = "pres"},
		[2] = {list = "subj"},
		[3] = {list = "pp"},
		["head"] = {},
	}
	
	local args = require("Module:parameters").process(args, params)
	data.heads = {args["head"]}
	
	table.insert(data.categories, "High Valyrian " .. data.pos_category)
	
	args[1] = require("Module:qhv-verb/head").fetch("act_ind_prs_1sg")
	args[2] = require("Module:qhv-verb/head").fetch("act_sub_prs_1sg")
	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

return export