Module:kilta-headword: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
 
(49 intermediate revisions by the same user not shown)
Line 3: Line 3:
local gsub = mw.ustring.gsub
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local sub = mw.ustring.sub
local split = mw.text.split


local TILDEB = u(0x0330) -- COMBINING TILDE BELOW ̰◌
local TILDEB = u(0x0330) -- COMBINING TILDE BELOW ̰◌
Line 16: Line 17:
end
end


local function plural(word, escape)
local function plural(word, n, pos)
local pl = {}
local w = split(word, " ")
if escape then
n = tonumber(n)
pl = escape
if n > #w then error("Word index outside bounds.") end
elseif word:match("[kh]wa$") or word:match("a$") then
pl = {sub(word, 1, -1) .. "úr"}
if pos == "n" then
elseif word:match("ës$") or word:match("uin$") or word:match("[str]$") then
if w[n]:match("[kh]wa$") then
pl = {word .. "á"}
w[n] = sub(w[n], 1, -3) .. "úr"
elseif word:match("[nml]$") then
elseif w[n]:match("a$") then
pl = {word .. "ur"}
w[n] = sub(w[n], 1, -2) .. "úr"
elseif w[n]:match("ës$") or w[n]:match("uin$") or w[n]:match("[str]$") then
w[n] = w[n] .. "á"
elseif w[n]:match("[nml]$") then
w[n] = w[n] .. "ur"
end
elseif pos == "adj" then
if w[n]:match("[kh]win$") then
w[n] = sub(w[n], 1, -4) .. "ú"
elseif w[n]:match("in$") then
w[n] = sub(w[n], 1, -3) .. "u"
end
end
end
pl.label = "plural"
return {label = "plural", table.concat(w, " ")}
return pl
end
end


Line 36: Line 47:
local params = {
local params = {
[1] = {},
[1] = {},
[2] = {list = true},
["pl"] = {list = true},
["w"] = {default = PAGENAME},
["w"] = {default = mw.title.getCurrentTitle().text},
["n"] = {type = number, default = 1}
}
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)
local word = args["w"]
local word = args.w
local pos = args[1]; local pl = args[2]
local pos = args[1]; local pl = args.pl
local data = {lang = lang, pos_category = deabb[pos], heads = {word}, categories = {}, inflections = {},}
local data = {lang = lang, pos_category = deabb[pos], heads = {word}, categories = {}, inflections = {},}
if pl[1] == '-' then
if pl[1] == '-' then
Line 54: Line 67:
if pos == "adv" then table.insert(data.categories, lang:getCanonicalName() .. " comparative " .. deabb[pos]) end ]=]
if pos == "adv" then table.insert(data.categories, lang:getCanonicalName() .. " comparative " .. deabb[pos]) end ]=]
else
else
table.insert(data.inflections, plural(word, pl[1] and pl or nil))
if pl[1] then
pl.label = "plural"
table.insert(data.inflections, pl)
else
table.insert(data.inflections, plural(word, args.n, pos))
end
end
end

Latest revision as of 12:15, 15 May 2024

Documentation for this module may be created at Module:kilta-headword/doc

local match = mw.ustring.match
local u = mw.ustring.char
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local split = mw.text.split

local TILDEB = u(0x0330) -- COMBINING TILDE BELOW ̰◌

local export = {}

local lang = require("Module:languages").getByCode("kilta")
local deabb = {["adj"] = "adjectives", ["v"] = "verbs", ["adv"] = "adverbs", ["n"] = "nouns"}

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

local function plural(word, n, pos)
	local w = split(word, " ")
	n = tonumber(n)
	if n > #w then error("Word index outside bounds.") end
	
	if pos == "n" then
		if w[n]:match("[kh]wa$") then
			w[n] = sub(w[n], 1, -3) .. "úr"
		elseif w[n]:match("a$") then
			w[n] = sub(w[n], 1, -2) .. "úr"
		elseif w[n]:match("ës$") or w[n]:match("uin$") or w[n]:match("[str]$") then
			w[n] = w[n] .. "á"
		elseif w[n]:match("[nml]$") then
			w[n] = w[n] .. "ur"
		end
	elseif pos == "adj" then
		if w[n]:match("[kh]win$") then
			w[n] = sub(w[n], 1, -4) .. "ú"
		elseif w[n]:match("in$") then
			w[n] = sub(w[n], 1, -3) .. "u"
		end
	end
	
	return {label = "plural", table.concat(w, " ")}
end

function export.show(frame)
	
	local params = {
		[1] = {},
		["pl"] = {list = true},
		["w"] = {default = mw.title.getCurrentTitle().text},
		["n"] = {type = number, default = 1}
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local word = args.w
	local pos = args[1]; local pl = args.pl
	local data = {lang = lang, pos_category = deabb[pos], heads = {word}, categories = {}, inflections = {},}

	
	if pl[1] == '-' then
		if pos == "n" then
			table.insert(data.inflections, {label = glossary_link("uncountable")})
			table.insert(data.categories, lang:getCanonicalName() .. " uncountable " .. deabb[pos])
		end
	--[=[ elseif pos ~= "v" then
		table.insert(data.inflections, {label = glossary_link("comparative"), redup(word)})
		if pos == "adv" then table.insert(data.categories, lang:getCanonicalName() .. " comparative " .. deabb[pos]) end ]=]
	else
		if pl[1] then
			pl.label = "plural"
			table.insert(data.inflections, pl)
		else
			table.insert(data.inflections, plural(word, args.n, pos))
		end
	end
	
	return require('Module:headword').full_headword(data)
end

return export