Module:User:Dixtosa/oge-infl-noun

local export = {}

local lang = require("Module:languages").getByCode("oge") local m_links = require("Module:links") local strutils = require("Module:string utilities") local declensionTable = require("Module:User:Dixtosa/oge-infl-noun/declension table")

--unicode charAt function uCharAt(str, index) return mw.ustring.sub(str, 1, 1) end

forms = {} rules = {}

rules["non-syllabic-u-ending-stem"] = { ["abs_sg"] = {"უ"}, ["nom_sg"] = {"უი", "ჳ"}, ["erg_sg"] = {"უმან"}, ["dat_sg"] = {"უს"}, ["gen_sg"] = {"უის", "ჳს"}, ["dir_sg"] = {"უისა", "ჳსა"}, ["ins_sg"] = {"უით", "ჳთ"}, ["adv_sg"] = {"უად"}, ["voc_sg"] = {"უო"}, } rules["ou-ending-stem"] = { ["abs_sg"] = { "" }, ["nom_sg"] = { "ჲ" }, ["erg_sg"] = { "მან" }, ["dat_sg"] = { "ს" }, ["gen_sg"] = { "ჲს" }, ["dir_sg"] = { "ჲსა" }, ["ins_sg"] = { "ჲთ" }, ["adv_sg"] = { "დ" }, ["voc_sg"] = { "ო" }, } rules["a-ending-stem"] = { ["abs_sg"] = { "" }, ["nom_sg"] = { "ჲ" }, ["erg_sg"] = { "მან" }, ["dat_sg"] = { "ს" }, ["gen_sg"] = { "ის" }, ["dir_sg"] = { "ისა" }, ["ins_sg"] = { "ით" }, ["adv_sg"] = { "დ" }, ["voc_sg"] = { "ო" }, } rules["e-ending-stem"] = { ["abs_sg"] = { "" }, ["nom_sg"] = { "ჲ" }, ["erg_sg"] = { "მან" }, ["dat_sg"] = { "ს" }, ["gen_sg"] = { "ის" }, ["dir_sg"] = { "ისა" }, ["ins_sg"] = { "ით" }, ["adv_sg"] = { "დ" }, ["voc_sg"] = { "ო" }, } rules["consonant-ending-stem"] = { ["abs_sg"] = { "" }, ["nom_sg"] = { "ი" }, ["erg_sg"] = { "მან" }, ["dat_sg"] = { "ს" }, ["gen_sg"] = { "ის" }, ["dir_sg"] = { "ისა" }, ["ins_sg"] = { "ით" }, ["adv_sg"] = { "ად" }, ["voc_sg"] = { "ო" }, } rules["ili-ending-stem"] = { ["abs_sg"] = { "" }, ["nom_sg"] = { "ი" }, ["erg_sg"] = { "მან" }, ["dat_sg"] = { "ს" }, ["gen_sg"] = { "ის" }, ["dir_sg"] = { "ისა" }, ["ins_sg"] = { "ით" }, ["adv_sg"] = { "დ" }, ["voc_sg"] = { "ო" }, } ebPluralRule = { ["abs"] = "", ["nom"] = "ი", ["erg"] = "მან", ["dat"] = "ს", ["gen"] = "ის", ["dir"] = "ისა", ["ins"] = "ით", ["adv"] = "ად", ["voc"] = "ო", } ntPluralRule = { ["nom"] = "ნი", ["erg"] = "თა", ["voc"] = "ნო", }

function init forms = {} end

function export.getForms(args) main(args, 1) local combined = {} for k, v in pairs(forms) do		combined[k] = mw.ustring.gsub(v, "[%[%]]", "") end for k, v in pairs(postpositions) do		combined[k] = mw.ustring.gsub(v, "[%[%]]", "") end return combined end

--function export.test(args, form) --	main(args, 1) --	return mw.ustring.gsub(forms[form], "[%[%]]", "") --end

function export.show(frame) if mw.text.split(mw.title.getCurrentTitle.prefixedText, ":")[1] == "Template" then return "" end local args = frame:getParent.args main(args, 0) return strutils.format(declensionTable.template, forms) end

function main(args) init term = args.term or mw.title.getCurrentTitle.text --'term' arg is for debug and testing purposes local term_info = analyze(term, args.type, args) fillTable(term_info) override(args) makelinks forms["note"] = "" end

function analyze(term, type, parameters) if (type == "non-syllabic-u-ending-stem") then local stem = "" local lastLetter = mw.ustring.sub(term, -1) if lastLetter == "ი" then stem = mw.ustring.sub(term, 0, -3) end if lastLetter == "ჳ" then stem = mw.ustring.sub(term, 0, -2) end return { rule_code = "non-syllabic-u-ending-stem", stemSingular = { abs = stem, nom = stem, erg = stem, dat = stem, gen = stem, dir = stem, ins = stem, adv = stem, voc = stem },			stemPluralEb = stem .. "უ", stemPluralNt = stem .. "უ" }	end if (type == "u-ending-stem") then local stem = mw.ustring.sub(term, 0, -2) return { rule_code = "ou-ending-stem", stemSingular = { abs = stem, nom = stem, erg = stem, dat = stem, gen = stem, dir = stem, ins = stem, adv = stem, voc = stem },			stemPluralEb = stem, stemPluralNt = stem }	end if (type == "o-ending-stem") then local stem = mw.ustring.sub(term, 0, -2) return { rule_code = "ou-ending-stem", stemSingular = { abs = stem, nom = stem, erg = stem, dat = stem, gen = stem, dir = stem, ins = stem, adv = stem, voc = stem },			stemPluralEb = stem, stemPluralNt = stem }	end if (type == "e-ending-stem") then local stem = mw.ustring.sub(term, 0, -2) local trimmed_stem = mw.ustring.sub(term, 0, -3) return { rule_code = type, stemSingular = { abs = stem, nom = stem, erg = stem, dat = stem, gen = trimmed_stem, dir = trimmed_stem, ins = trimmed_stem, adv = stem, voc = stem },			stemPluralEb = trimmed_stem, stemPluralNt = stem }	end if (type == "a-ending-stem") then local stem = mw.ustring.sub(term, 0, -2) local trimmed_stem = mw.ustring.sub(term, 0, -3) return { rule_code = type, stemSingular = { abs = stem, nom = stem, erg = stem, dat = stem, gen = trimmed_stem, dir = trimmed_stem, ins = stem, adv = stem, voc = stem },			stemPluralEb = trimmed_stem, stemPluralNt = stem }	end if (type == "consonant-ending-stem") then local stem = mw.ustring.sub(term, 0, -2) return { rule_code = type, stemSingular = { abs = stem, nom = stem, erg = stem, dat = stem, gen = stem, dir = stem, ins = stem, adv = stem, voc = stem },			stemPluralEb = stem, stemPluralNt = stem }	end if (type == "ili-ending-stem") then local stem = mw.ustring.sub(term, 0, -2) local advstem = mw.ustring.sub(term, 0, -3) return { rule_code = type, stemSingular = { abs = stem, nom = stem, erg = stem, dat = stem, gen = stem, dir = stem, ins = stem, adv = advstem, voc = stem },			stemPluralEb = stem, stemPluralNt = stem }	end if (type == "reducible-stem") then local stem = mw.ustring.sub(term, 0, -2) local reduced_stem = parameters.reduced_stem return { rule_code = "consonant-ending-stem", stemSingular = { abs = stem, nom = stem, erg = stem, dat = stem, gen = reduced_stem, dir = reduced_stem, ins = reduced_stem, adv = reduced_stem, voc = stem },			stemPluralEb = reduced_stem, stemPluralNt = stem }	end end

function fillTable(term_info, params) local noPlural = false; local stemSingular = term_info.stemSingular local stemPluralEb = term_info.stemPluralEb local stemPluralNt = term_info.stemPluralNt local rule = rules[term_info.rule_code] forms["term"] = term forms["abs_sg"] = "" ..   stemSingular["abs"] ..         rule["abs_sg"][1] .. "" if rule["abs_sg"][2] ~= nil then forms["abs_sg"] = forms["abs_sg"] .. ", " .. "" ..   stemSingular["abs"] ..         rule["abs_sg"][2] .. "" end forms["nom_sg"] = "" ..   stemSingular["nom"] ..         rule["nom_sg"][1] .. "" if rule["nom_sg"][2] ~= nil then forms["nom_sg"] = forms["nom_sg"] .. ", " .. "" ..   stemSingular["nom"] ..         rule["nom_sg"][2] .. "" end forms["erg_sg"] = "" ..   stemSingular["erg"] ..         rule["erg_sg"][1] .. "" if rule["erg_sg"][2] ~= nil then forms["erg_sg"] = forms["erg_sg"] .. ", " .. "" ..   stemSingular["erg"] ..         rule["erg_sg"][2] .. "" end forms["dat_sg"] = "" ..   stemSingular["dat"] ..         rule["dat_sg"][1] .. "" .. "(ა)" if rule["dat_sg"][2] ~= nil then forms["dat_sg"] = forms["dat_sg"] .. ", " .. "" ..   stemSingular["dat"] ..         rule["dat_sg"][2] .. "" .. "(ა)" end forms["gen_sg"] = "" ..   stemSingular["gen"] ..			rule["gen_sg"][1] .. "" .. "(ა)" if rule["gen_sg"][2] ~= nil then forms["gen_sg"] = forms["gen_sg"] .. ", " .. "" ..   stemSingular["gen"] ..			rule["gen_sg"][2] .. "" .. "(ა)" end forms["dir_sg"] = "" ..   stemSingular["dir"] ..			rule["dir_sg"][1] .. "" if rule["dir_sg"][2] ~= nil then forms["dir_sg"] = forms["dir_sg"] .. ", " .. "" ..   stemSingular["dir"] ..			rule["dir_sg"][2] .. "" end forms["ins_sg"] = "" ..	 stemSingular["ins"] ..			rule["ins_sg"][1] .. "" .. "(ა)" if rule["ins_sg"][2] ~= nil then forms["ins_sg"] = forms["ins_sg"] .. ", " .. "" ..	 stemSingular["ins"] ..			rule["ins_sg"][2] .. "" .. "(ა)" end forms["adv_sg"] = "" ..	 stemSingular["adv"] ..			rule["adv_sg"][1] .. "" if rule["adv_sg"][2] ~= nil then forms["adv_sg"] = forms["adv_sg"] .. ", " .. "" ..	 stemSingular["adv"] ..			rule["adv_sg"][2] .. "" end forms["voc_sg"] = "(ჵ)" .. stemSingular["voc"] ..        rule["voc_sg"][1] .. "" if rule["voc_sg"][2] ~= nil then forms["voc_sg"] = forms["voc_sg"] .. ", " .. "(ჵ)" .. stemSingular["voc"] ..        rule["voc_sg"][2] .. "" end forms["abs_pl_eb"] = noPlural or "" .. stemPluralEb .. "ებ" .. ebPluralRule["abs"] .. "" forms["nom_pl_eb"] = noPlural or "" .. stemPluralEb .. "ებ" .. ebPluralRule["nom"] .. "" forms["erg_pl_eb"] = noPlural or "" .. stemPluralEb .. "ებ" .. ebPluralRule["erg"] .. "" forms["dat_pl_eb"] = noPlural or "" .. stemPluralEb .. "ებ" .. ebPluralRule["dat"] .. "(ა)" forms["gen_pl_eb"] = noPlural or "" .. stemPluralEb .. "ებ" .. ebPluralRule["gen"] .. "(ა)" forms["dir_pl_eb"] = noPlural or "" .. stemPluralEb .. "ებ" .. ebPluralRule["dir"] .. "" forms["ins_pl_eb"] = noPlural or "" .. stemPluralEb .. "ებ" .. ebPluralRule["ins"] .. "(ა)" forms["adv_pl_eb"] = noPlural or "" .. stemPluralEb .. "ებ" .. ebPluralRule["adv"] .. "" forms["voc_pl_eb"] = noPlural or "(ჵ)" .. stemPluralEb .. "ებ" .. ebPluralRule["voc"] .. "" forms["abs_pl_nt"] = "—" forms["nom_pl_nt"] = noPlural or "" .. stemPluralNt .. ntPluralRule["nom"] .. "" forms["erg_pl_nt"] = noPlural or "" .. stemPluralNt .. ntPluralRule["erg"] .. "" forms["dat_pl_nt"] = noPlural or "" .. stemPluralNt .. ntPluralRule["erg"] .. "" forms["gen_pl_nt"] = noPlural or "" .. stemPluralNt .. ntPluralRule["erg"] .. "" forms["dir_pl_nt"] = noPlural or "" .. stemPluralNt .. ntPluralRule["erg"] .. "" forms["ins_pl_nt"] = noPlural or "" .. stemPluralNt .. ntPluralRule["erg"] .. "" forms["adv_pl_nt"] = noPlural or "" .. stemPluralNt .. ntPluralRule["erg"] .. "" forms["voc_pl_nt"] = noPlural or "(ჵ)" .. stemPluralNt .. ntPluralRule["voc"] .. ""

end

function override(args) for case, text in pairs(forms) do --WARNING: NOTE, etc.		forms[case] = mw.ustring.gsub(args[case] or "+", "+", forms[case]) end end

function makelinks for case, text in pairs(forms) do --WARNING: NOTE, etc.		text = mw.ustring.gsub( text, "%[%[(.-)%]%](%([აი]%))", function (captured, sav) -- hyphen is 0 or more non greedy					return m_links.full_link({lang = lang, term = captured, alt = captured .. sav}) end) text = mw.ustring.gsub( text, "(%([ჵ]%))%[%[(.-)%]%]", function (vocative_intensifier, captured) -- hyphen is 0 or more non greedy					return m_links.full_link({lang = lang, term = captured, alt = vocative_intensifier .. captured}) end) forms[case] = mw.ustring.gsub( text, "%[%[[^#]-%]%]", function (captured) 					return m_links.full_link({lang = lang, term = captured}) end)	end end

return export