Modul:ki-headword

A Wikiszótárból, a nyitott szótárból

A modult a Modul:ki-headword/doc lapon tudod dokumentálni

local export = {}

local lang = require("Module:languages").getByCode("ki")

local plural_classes = {
	["1"] = "c2", ["1a"] = "c2a", ["3"] = "c4", ["7"] = "c8", ["9"] = "c10", ["11"] = "c10",
	["12"] = "c13", ["5"] = "c6", ["14"] = "c6", ["15"] = "c6"}

local plural_rules = {
		   ["1"] = {[1] = {"mw",    "a", 3}, [2] = {"mũ",   "a", 3}, [3] = { "muu",   "oi", 4}, [4] = {"muo", "o", 4}},
		  ["1a"] = {[1] = {  "",   "", 1}},
		   ["3"] = {[1] = {"mũ",  "mĩ", 3}, [2] = {"mw", "mĩ", 3}, [3] = { "muu",  "miu", 4}, [4] = {"muo", "mĩo", 4}},
		   ["5"] = {[1] = {"i", "ma", 2}, [2] = {"", "ma", 1}},
		   ["7"] = {[1] = {"kĩa",   "cia", 4}, [2] = {"kĩe", "cie", 4}, [3] = {"kĩi", "cii", 4}, [4] = {"kĩi", "cii", 4}, [5] = {"kĩo", "cio", 4}, [6] = {"kiu", "ciu", 4}, [7] = {"gĩa",   "cia", 4}, [8] = {"gĩe", "cie", 4}, [9] = {"gĩi", "cii", 4}, [10] = {"gĩi", "cii", 4}, [11] = {"gĩo", "cio", 4}, [12] = {"giu", "ciu", 4}, [13] = {"kĩ", "i", 3}, [14] = {"gĩ", "i", 3}},
		   ["9"] = {[1] = {  "",    "", 1}},
		   
           ["11"] = {[1] = {"rũh", "'h", 4},
           	         [2] = {"rũc", "nj", 4},
           	         [3] = {"rũth", "th", 5},
           	         [4] = {"rũk", "ng", 4},
           	         [5] = {"rũm", "m", 4},
           	         [6] = {"rũn", "n", 4},
           	         [7] = {"rũt", "nd", 4},
           	         [8] = {"rũb", "mb", 4},
           	         [9] = {"rũr[aeiĩouũ]*[mn]", "n", 4},
           	         [10] = {"rũr", "nd", 4},
           	         [11] = {"r[ũu][aeiĩouũ][aeiĩouũ]*[mn]", "ny", 3},
           	         [12] = {"r[ũu][aeiĩouũ]", "nj", 3},
           	         [13] = {"rũ", "n", 3 }},
           
           ["12"] = {[1] = {"ka", "tũ", 3}, [2] = {"koi", "tuu", 4}, [3] = {"ga", "tũ", 3}, [4] = {"goi", "tuu", 4}},
		  ["14"] = {[1] = { "ũ",  "mo", 2}, [2] = {"we", "me", 3}, [3] = {"wĩ", "me", 3}, [4] = {"uo", "mo", 3}, [5] = {"uu", "moi", 3}, [6] = {"w", "m", 2}},
          ["15"] = {[1] = {"kũ",   "ma", 3}, [2] = { "gũ",   "ma", 3}, [3] = {"ku", "m", 3}, [4] = {"gu", "m", 3}},
          ["16"] = {[1] = {"ha", "kũ", 3}},
}

function export.noun(frame)
	local params = {
		[1] = {required=true},
		[2] = {},
		["head"] = {},
		["h"] = {alias_of = "head"}
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {lang = lang, pos_category = "nouns", categories = {}, heads = {args["head"]}, genders = mw.text.split(args[1], "%/"), inflections = {}}
	table.insert(data.categories, lang:getCanonicalName() .. " class " .. data.genders[1] .. " nouns")
	
	local singular = args["head"] and require("Module:links").remove_links(args["head"]) or mw.title.getCurrentTitle().text
	local inflection = nil
	
	if not args[2] then
		inflection = export.generate_plural(singular, args[1])
	else
		if (args[2] ~= "-") then
			inflection = args[2]	
		end
	end
	
	local accel = {form = "p"}
	if (plural_classes[args[1]]) then
		accel.gender = plural_classes[args[1]]
	end
	
	if (inflection) then
		table.insert(data.inflections, {label = "plural", accel = accel, inflection})
	end
	
	return require("Module:headword").full_headword(data)
end

function startswith(test_string, start)
	return mw.ustring.match(test_string, "^"..start)
end

function match_case(string1, string2)
	c1 = mw.ustring.sub(string1, 1, 1)
	c2 = mw.ustring.sub(string2, 1, 1)
	if (mw.ustring.lower(c1) == c1) then
		return mw.ustring.lower(c2) .. mw.ustring.sub(string2, 2)
	end
	return mw.ustring.upper(c2).. mw.ustring.sub(string2, 2)
end

function export.generate_plural(singular, class)
	if (plural_rules[class]) then
		for k,v in ipairs(plural_rules[class]) do
			if startswith(singular, v[1]) then
				return match_case(singular, v[2]..mw.ustring.sub(singular, v[3]))
			end
		end
	end
end

return export