Module:Test: Difference between revisions

From Allocosm
(Created page with " require('Module:Test/data') export = {} function export.get_forms(head,vowel,tail_str) -- if root_str == nil then -- error("Root is required") -- end local forms = {} local tail = {} local patterns = {} -- root_str = string.gsub(root_str,"-","") -- local root = m_cu.parse_root(root_str,true) tail = mw.text.split(tail_str,"-") if #tail == 1 then patterns = NOMOD_PATTERNS elseif #tail == 2 then patterns = ONEMOD_PATTERNS elseif #tail == 3 then p...")
 
No edit summary
Line 4: Line 4:
export = {}
export = {}


function export.get_forms(head,vowel,tail_str)
function export.get_forms(root,mod,manual)
 
mod = mod or ''
-- if root_str == nil then
-- error("Root is required")
-- end
local forms = {}
local forms = {}
local tail = {}
local patterns = {}
local patterns = {}
-- root_str = string.gsub(root_str,"-","")
local head = ""
 
local vowel = ""
-- local root = m_cu.parse_root(root_str,true)
local root = m_cu.parse_root(root..mod,true)
local tail =  mw.text.split(root[#root],"-")
tail = mw.text.split(tail_str,"-")
if #root == 1 then
--TBD
elseif #root == 2 then
vowel = root[1]
else
table.remove(root,#root)
vowel = root[#root]
table.remove(root,#root)
head = table.concat(root)
end
if #tail == 1 then
if #tail == 1 then
Line 28: Line 36:
end
end
for k,v in pairs(NOMOD_PATTERNS) do
for k,v in pairs(patterns) do
forms[k] = string.gsub(v,"C",head)
forms[k] = string.gsub(v,"C",head)
forms[k] = string.gsub(forms[k],"V",vowel)
forms[k] = string.gsub(forms[k],"V",vowel)
forms[k] = string.gsub(forms[k],"1",tail[1])
forms[k] = string.gsub(forms[k],"1",tail[1])
forms[k] = string.gsub(forms[k],"2",tail[2])
forms[k] = string.gsub(forms[k],"2",tail[2] or '')
forms[k] = string.gsub(forms[k],"3",tail[3])
forms[k] = string.gsub(forms[k],"3",tail[3] or '')
end
 
for k,v in pairs(forms) do
forms[k] = m_cu.assimilate(v)
end
for k,v in pairs(manual) do
forms[k] = v
end
end



Revision as of 02:56, 11 February 2024

Documentation for this module may be created at Module:Test/doc

require('Module:Test/data')

export = {}

function export.get_forms(root,mod,manual)
	mod = mod or ''
	
	local forms = {}
	local patterns = {}
	
	local head = ""
	local vowel = ""
	
	local root = m_cu.parse_root(root..mod,true)
	
	local tail =  mw.text.split(root[#root],"-")
	
	if #root == 1 then
		--TBD
	elseif #root == 2 then
		vowel = root[1]
	else
		table.remove(root,#root)
		vowel = root[#root]
		table.remove(root,#root)
		head = table.concat(root)
	end
	
	if #tail == 1 then
		patterns = NOMOD_PATTERNS
	elseif #tail == 2 then
		patterns = ONEMOD_PATTERNS
	elseif #tail == 3 then
		patterns = TWOMOD_PATTERNS
	end
	
	for k,v in pairs(patterns) do
		forms[k] = string.gsub(v,"C",head)
		forms[k] = string.gsub(forms[k],"V",vowel)
		forms[k] = string.gsub(forms[k],"1",tail[1])
		forms[k] = string.gsub(forms[k],"2",tail[2] or '')
		forms[k] = string.gsub(forms[k],"3",tail[3] or '')
	end

	for k,v in pairs(forms) do
		forms[k] = m_cu.assimilate(v)
	end
	
	for k,v in pairs(manual) do
		forms[k] = v
	end

	mw.logObject(forms)
	return forms
end

return export