Module:otw-headword

local export = {} local pos_functions = {}

local legal_verb_class = { ["vta"] = true, ["vti"] = true, ["via"] = true, ["vii"] = true }

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

--Helper functions local rsubn = mw.ustring.gsub local usub = mw.ustring.sub

local function rsub(term, foo, bar) local retval = rsubn(term, foo, bar) return retval end

local function get_index(str, list) if list == nil then return -1 end for i = 1, #list do if str == list[i] then return i end end return -1 end

local function in_set(str, list) if get_index(str, list) ~= -1 then return true else return false end end local function char_at(str, pos) return usub(str, pos, pos) end local function accent_vowels(str) return rsub(rsub(rsub(str, "aa", "ā"), "ii", "ī"), "oo", "ō") end local function double_vowels(str) return rsub(rsub(rsub(str, "ā", "aa"), "ī", "ii"), "ō", "oo") end

local function del_char(str, pos) local length = #str if pos > length or pos < 1 then error("invalid position") end if pos > 1 then first = usub(str, 1, pos-1) else first = "" end if pos ~= length then second = usub(str, pos+1, length) else second = "" end if in_set(char_at(first,#first), {"z", "h"}) and char_at(second,1) == "h" then return first .. "'" .. second end if char_at(first,#first) == "n" and in_set(char_at(second,1), {"s", "z", "y"}) then return first .. "'" .. second end return first .. second end

-- Algorithm as described in Valentine 2001 local function del_weak_vowels(stem) stem = accent_vowels(stem) vowels = {} weak_vowels = {} prev_vowel_weak = false for i = 1, #stem do		if in_set(char_at(stem,i), {"a", "i", "o"}) then table.insert(vowels, i)			if prev_vowel_weak then prev_vowel_weak = false else table.insert(weak_vowels ,i) prev_vowel_weak = true end elseif in_set(char_at(stem,i), {"e", "ā", "ī", "ō"}) then table.insert(vowels, i)			prev_vowel_weak = false else end end if vowels[#vowels] == weak_vowels[#weak_vowels] then table.remove(weak_vowels, #weak_vowels) end for i = #weak_vowels, 1, -1 do stem = del_char(stem, weak_vowels[i]) end return double_vowels(stem) end

local function phonotactics(stem) final_ch = char_at(stem,#stem) penul_ch = char_at(stem,#stem) if final_ch == "y" and final_ch == "n" then stem = usub(stem, 1, #stem-1) .. "h" end if final_ch == "w" or final_ch == "y" then stem = usub(stem, 1, #stem-1) end return stem end

local function noun_class(stem) final_ch = char_at(stem,#stem) penul_ch = char_at(stem,#stem-1) if final_ch == "e" then return "II" elseif in_set(final_ch, {"a", "i", "o"}) and final_ch == penul_ch then return "II" elseif final_ch == "w" and in_set(penul_ch, {"a", "e", "i", "o"}) then return "III" elseif final_ch == "w" and in_set(penul_ch, {"k", "g"}) then return "IV" elseif final_ch == "y" and not in_set(penul_ch, {"a", "e", "i", "o"}) then return "V" else return "I" end end

local function make_plural(stem, g)	class = noun_class(stem) stem = phonotactics(stem) pl_suf = {	["an"] = {["I"] = "ag", ["II"] = "g", ["III"] = "wag", ["IV"] = "oog", ["V"] = "iig"}, ["in"] = {["I"] = "an", ["II"] = "n", ["III"] = "wan", ["IV"] = "oon", ["V"] = "iin"} } if g == "an" then return del_weak_vowels(stem .. pl_suf[g][class]) elseif g == "in" then return del_weak_vowels(stem .. pl_suf[g][class]) else return "no gender provided" end end

local function make_obviative(stem, g)	class = noun_class(stem) stem = phonotactics(stem) obv_suf = {["I"] = "an", ["II"] = "n", ["III"] = "wan", ["IV"] = "oon", ["V"] = "iin"} if g == "an" or g == "in" then return del_weak_vowels(stem .. obv_suf[class]) else return "no gender provided" end end

-- The main entry point. -- This is the only function that can be invoked from a template. function export.show(frame) PAGENAME = mw.title.getCurrentTitle.text local args = frame:getParent.args local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.") local cat = args["cat"]; if cat == "" then cat = nil end local cat2 = args["cat2"]; if cat2 == "" then cat2 = nil end local cat3 = args["cat3"]; if cat3 == "" then cat3 = nil end local head = args["head"]; if head == "" then head = nil end

local data = {lang = lang, pos_category = cat or poscat, categories = {}, heads = {head}, genders = {}, inflections = {}} if cat2 then table.insert(data.categories, "Ottawa " .. cat2) end if cat3 then table.insert(data.categories, "Ottawa " .. cat3) end if pos_functions[poscat] then pos_functions[poscat](args, data) end return require("Module:headword").full_headword(data) end

pos_functions["adverbs"] = function(args, data) local adv_type = args[1] if adv_type == "temp" or adv_type == "temporal" then table.insert(data.categories, "Ottawa temporal adverbs") elseif adv_type == "loc" or adv_type == "locative" then table.insert(data.categories, "Ottawa locative adverbs") elseif adv_type == "man" or adv_type == "manner" then table.insert(data.categories, "Ottawa manner adverbs") elseif adv_type == "conj" or adv_type == "conjunctive" then table.insert(data.categories, "Ottawa conjunctive adverbs") elseif adv_type == "quant" or adv_type == "quantitative" then table.insert(data.categories, "Ottawa quantitative adverbs") elseif adv_type == "deg" or adv_type == "degree" then table.insert(data.categories, "Ottawa adverbs of degree") elseif adv_type == "neg" or adv_type == "negative" then table.insert(data.categories, "Ottawa negative adverbs") elseif adv_type == "num" or adv_type == "number" then table.insert(data.categories, "Ottawa number adverbs") else end end

pos_functions["verbs"] = function(args, data) local class = args[1] if class == "vta" then table.insert(data.inflections, {label = "animate transitive", nil}) table.insert(data.categories, "Ottawa verb transitive animate (vta)") elseif class == "vti" then table.insert(data.inflections, {label = "inanimate transitive", nil}) table.insert(data.categories, "Ottawa verb transitive inanimate (vti)") elseif class == "vai" then table.insert(data.inflections, {label = "animate intransitive", nil}) table.insert(data.categories, "Ottawa verb animate intransitive (vai)") elseif class == "vii" then table.insert(data.inflections, {label = "inanimate intransitive", nil}) table.insert(data.categories, "Ottawa verb inanimate intransitive (vii)") else end local ccf = args["ccf"] if ccf ~= nil then table.insert(data.inflections, {label = "changed conjunct form", ccf}) end local rdf = args["rdf"] if ccf ~= nil then table.insert(data.inflections, {label = "reduplicated form", rdf}) end local stem = args["stem"] if stem ~= nil then table.insert(data.inflections, {label = "stem", stem}) end end

pos_functions["nouns"] = function(args, data) PAGENAME = mw.title.getCurrentTitle.text local g = args["g"] local plural = args["pl"] local obv = args["obv"] local loc = args["loc"] local type = args["type"]

if g == "an" then table.insert(data.genders, "an") elseif g == "in" then table.insert(data.genders, "in") else end if type == "dep" then table.insert(data.inflections, {label = "dependent", nil}) end local stem = args["stem"] if stem ~= nil then if plural == nil then plural = make_plural(stem, g) end if obv == nil then obv = make_obviative(stem, g) end end if plural ~= nil then if g == "an" then table.insert(data.inflections, {label = "plural", accel = {form = "p"}, plural}) elseif g == "in" then table.insert(data.inflections, {label = "plural", accel = {form = "p//obv"}, plural}) else table.insert(data.inflections, {label = "plural", plural}) end end if obv ~= nil then if g == "an" then table.insert(data.inflections, {label = "obviative", accel = {form = "obv"}, obv}) elseif g == "in" then table.insert(data.inflections, {label = "obviative", accel = {form = "p//obv"}, obv}) else table.insert(data.inflections, {label = "obviative", plural}) end end if loc ~= nil then if g == "an" then table.insert(data.inflections, {label = "locative", accel = {form = "loc"}, loc}) elseif g == "in" then table.insert(data.inflections, {label = "locative", accel = {form = "loc"}, loc}) else table.insert(data.inflections, {label = "locative", loc}) end end end

return export