Module:qay-noun/head

From Linguifex
< Module:qay-noun
Revision as of 12:23, 25 June 2022 by Sware (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:qay-noun/head/doc

local export = {}

local m_p = require("Module:qay-noun")
local m_d = require("Module:qay-noun/data")
local PAGENAME = mw.title.getCurrentTitle().text

local function detect_decl(word)
	if word:match("[aeiouy]$") then
		return "v"
	else
		return "c"
	end
end

function export.generate(frame)
	local case = frame.args[1]
	local word = frame.args[2] == nil and nil or PAGENAME
	local data = {forms = {}, categories = {}}
	local decl = detect_decl(word)
	local stem = word
	
	stem = {table.concat(stem), "a"}
	
	if m_d[word] then m_d[word](stem, data)
	else m_d[decl](stem, data) end
	
	if tostring(mw.getCurrentFrame():preprocess('function')):find('<strong class="error"') then --iferror
    	return "?"
    end
	
	return table.concat(data.forms[case], ",")
end

function export.pass_to_module(term, case, gender)
	local stem = PAGENAME
	local data = {forms = {}, categories = {}}
	local decl = gender .. "_" .. detect_decl(stem)
	
	stem = {table.concat(stem), "a"}
	
	if m_d[word] then m_d[word](stem, data)
	else m_d[decl](stem, data) end
	
	return table.concat(data.forms[case], ",")
end

return export