Module:akk-conj

local common = require("Module:akk-common") local render = require("Module:akk-conj/table")

local STEM = {} STEM["G"] = { stem = require("Module:akk-conj/g/stem"), endings = require("Module:akk-conj/g/endings"), weakness = require("Module:akk-conj/g/weakness") } STEM["D"] = { stem = require("Module:akk-conj/d/stem"), endings = require("Module:akk-conj/d/endings"), weakness = require("Module:akk-conj/d/weakness") }

local export = {}

InflectionTable = {}

function InflectionTable:new_raw(stems, endings) local object = { number = self:number, dur   = endings:dur(stems.dur1, stems.dur2), pret  = endings:pret(stems.pret1, stems.pret2), perf  = endings:perf(stems.perf1, stems.perf2), imp   = endings:imp(stems), inf   = endings:nominal(stems.inf), part  = endings:nominal(stems.part), adj   = endings:nominal(stems.adj), }    setmetatable(object, {__index = self}) return object end

function InflectionTable:number return { {"1.sg"}, {"2.sg", "m"}, {"2.sg", "f"}, {"3.sg"}, {"1.pl"}, {"2.pl"}, {"3.pl", "m"}, {"3.pl", "f"}, } end

function InflectionTable:render(stem_name) if stem_name == nil or stem_name == "" then error("A stem must be specified") end return render.render(stem_name, self) end

function parse_root(root) if not root then error("A root must be specified under the parameter `root`. e.g: ") end local R = {} local i = 0 for r in mw.ustring.gmatch(root, "(.)[-]?") do 		i = i + 1 R[i] = r	end return R end

local function override(table_, args) local keys = { ["1sg"]  = 1, ["2sgm"] = 2, ["2sgf"] = 3, ["3sg"]  = 4, ["1pl"]  = 5, ["2pl"]  = 6, ["3plm"] = 7, ["3plf"] = 8, }	for name, value in pairs(args) do		if type(name) == "string" then local iter  = mw.ustring.gmatch(name, "[^\\.]+") local tense = iter or "" local person = iter or "" local number = iter or "" local gender = iter or "" local array = table_[tense] if type(array) == "table" then key = keys[person..number..gender] if key then array[key] = value end end end end end

function InflectionTable:from_args(args) local stem_module = STEM[args.stem]; local root = parse_root(args.root) local weakness = stem_module.weakness(root, args) local stems = stem_module.stem(root, args.class, args) local endings = stem_module.endings(weakness) local table = InflectionTable:new_raw(stems, endings) override(table, args) return table end

function export.main(frame) local args = frame:getParent.args -- positional argument support args.stem = args.stem or args[1] args.root = args.root or args[2] args.class = args.class or args[3]

if args.stem == "G" then local table = InflectionTable:from_args(args) return table:render("G-stem", args.debug) elseif args.stem == "D" then local table = InflectionTable:from_args(args) return table:render("D-stem", args.debug) elseif args.stem == "Š" then error("Not yet implemented") elseif args.stem == "N" then error("Not yet implemented") elseif args.stem == "Gt" then error("Not yet implemented") elseif args.stem == "Dt" then error("Not yet implemented") elseif args.stem == "Št" then error("Not yet implemented") elseif args.stem == "Nt" then error("Not yet implemented") elseif args.stem == "Gtn" then error("Not yet implemented") elseif args.stem == "Dtn" then error("Not yet implemented") elseif args.stem == "Ntn" then error("Not yet implemented") elseif args.stem == "Štn" then error("Not yet implemented") else error("Not a valid Akkadian stem.") end end

return export