Module:oj-headword


local export = {}
local pos_functions = {}

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

local lang = require("Module:languages").getByCode("oj")
local m_scripts = require("Module:languages")
local Latn = m_scripts.getByCode("Latn")
local Cans = m_scripts.getByCode("Cans")

-- 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

-- 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, "Ojibwe " .. cat2) end
	if cat3 then table.insert(data.categories, "Ojibwe " .. cat3) end
	
	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end
	
	return require("Module:headword").full_headword(data)
end


pos_functions["nouns"] = function(args, data)
	local script_code = args[1]
	local translit = args[2]
	script = Latn
	if script_code == "c" then script = Cans end
	
	if translit ~= nil then
		if script_code == "c" then table.insert(data.inflections, {label = "Latin spelling", sc=Latn, translit})
		else table.insert(data.inflections, {label = "Canadian syllabics spelling", sc=Cans, translit})
		end
	end
	
	local gender = args["g"]
	local plural = args["pl"]
	local plother = args["plother"]
	local obv = args["obv"]
	local loc = args["loc"]
	local dim = args["dim"]
	
	if gender == "an" then table.insert(data.genders, "an")
	elseif gender == "in" then table.insert(data.genders, "in")
	else end
	
	if plural ~= nil then
		if gender == "an" then table.insert(data.inflections, {label = "plural", sc=script, accel = {form = "p"}, plural}) 
		elseif gender == "in" then table.insert(data.inflections, {label = "plural", sc=script, accel = {form = "p//obv"}, plural}) 
		else table.insert(data.inflections, {label = "plural", plural}) end
	end
	
	if plother ~= nil then
		if script_code == "Cans" then table.insert(data.inflections, {label = "plural Latin spelling", sc=Latn, plother})
		else table.insert(data.inflections, {label = "plural Canadian syllabics spelling", sc=Cans, plother})
		end
	end
	
	if obv ~= nil then
		if gender == "an" then table.insert(data.inflections, {label = "obviative", sc=script, accel = {form = "obv"}, obv}) 
		elseif gender == "in" then table.insert(data.inflections, {label = "obviative", sc=script, accel = {form = "p//obv"}, obv}) 
		else table.insert(data.inflections, {label = "obviative", plural})  end
	end
	
	if loc ~= nil then table.insert(data.inflections, {label = "locative", sc=script, accel = {form = "loc"}, loc})  end
	if dim ~= nil then table.insert(data.inflections, {label = "diminutive", sc=script, accel = {form = "dim"}, dim}) end
end
	
pos_functions["verbs"] = function(args, data)
	local script = args[1]
	local class = args[2]
	if class == "vta" then
		table.insert(data.inflections, {label = "animate transitive", nil})
		table.insert(data.categories, "Ojibwe verb transitive animate (vta)")
	elseif class == "vti" then
		table.insert(data.inflections, {label = "inanimate transitive", nil})
		table.insert(data.categories, "Ojibwe verb transitive inanimate (vti)")
	elseif class == "vai" then
		table.insert(data.inflections, {label = "animate intransitive", nil})
		table.insert(data.categories, "Ojibwe verb animate intransitive (vai)")
	elseif class == "vii" then
		table.insert(data.inflections, {label = "inanimate intransitive", nil})
		table.insert(data.categories, "Ojibwe verb inanimate intransitive (vii)")
	else
		error("invalid verb class")
	end
	
	local ccf = args["ccf"]
	if ccf ~= nil then table.insert(data.inflections, {label = "changed conjunct form", ccf}) end
	local rdf = args["rdf"]
	if rdf ~= 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



return export