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
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:


require('Module:Test/data')
export = {}
 
VOWELS = "aeiouw"
 
DEVOICED = "ktfsθʧqʃ"
VOICED = "gdvzðʤ"
 
SIBILANTS = "zsʃʒ"
 
DEVOICING = {
["g"] = "k",
["d"] = "t",
["v"] = "f",
["z"] = "s",
["ð"] = "θ",
["ʤ"] = "ʧ",
}


export = {}
H_DEVOICING = {
["g"] = "k",
["d"] = "t",
["v"] = "f",
["z"] = "z",
["ð"] = "θ",
}


function export.get_forms(head,vowel,tail_str)
VvC = {
["a"] = "au",
["e"] = "ef",
["i"] = "if",
["o"] = "uu",
["u"] = "uu",
}


-- if root_str == nil then
function export.compress_consonants(str)
-- error("Root is required")
-- end
str = str or ''
local forms = {}
replace = {{"ssh","ʃʃ"},
local tail = {}
{"ddh","ðð"},
local patterns = {}
{"tth","θθ"},
{"cch","ʧʧ"},
{"sh","ʃ"},
{"dh","ð"},
{"th","θ"},
{"j","ʤ"},
{"ch","ʧ"},
{"'",""},
}
-- root_str = string.gsub(root_str,"-","")
for _,v in ipairs(replace) do
str = mw.ustring.gsub(str,v[1],v[2])
end
return str
end


-- local root = m_cu.parse_root(root_str,true)
function export.expand_consonants(str)
replace = {
{"s'h","sh"},
{"s'sh","sʃ"},
{"d'h","dh"},
{"d'dh","dð"},
{"t'h","th"},
{"t'th","tθ"},
{"ssh","ʃʃ"},
{"ddh","ðð"},
{"tth","θθ"},
{"cch","ʧʧ"},
{"sh","ʃ"},
{"dh","ð"},
{"th","θ"},
{"j","ʤ"},
{"ch","ʧ"},
}
tail = mw.text.split(tail_str,"-")
for _,v in ipairs(replace) do
str = mw.ustring.gsub(str,v[2],v[1])
end
if #tail == 1 then
return str
patterns = NOMOD_PATTERNS
end
elseif #tail == 2 then
 
patterns = ONEMOD_PATTERNS
function export.assimilate(str)
elseif #tail == 3 then
 
patterns = TWOMOD_PATTERNS
output = export.compress_consonants(str)
 
if str and str ~= '' then
--Find and record location of hyphen, if any
hyphen = mw.ustring.find(output,"-",1,true) or 0
output = mw.ustring.gsub(output,"-","")
--VvC assimilition FIXME - should not happen if v is geminate. Disabling for now.
-- output = string.gsub(output,"(["..VOWELS.."])v([^"..VOWELS.."])","%1~v%2"):gsub("(.)~v",{VvC)
--Sibilant Assimilation
output = mw.ustring.gsub(output,"(["..SIBILANTS.."])(["..SIBILANTS.."])","%2%2")
--Nasal Assimilation
output = mw.ustring.gsub(output,"m([tdszkgθðl])","n%1")
output = mw.ustring.gsub(output,"n([bfv])","m%1")
--General Devoicing
output = mw.ustring.gsub(output,"(["..DEVOICED.."])(["..VOICED.."])","%1~%2")
output = mw.ustring.gsub(output,"~(.)",DEVOICING)
output = mw.ustring.gsub(output,"(["..VOICED.."])(["..DEVOICED.."])","~%1%2")
output = mw.ustring.gsub(output,"~(.)",DEVOICING)
--H devoicing
output = mw.ustring.gsub(output,"h(["..VOICED.."])","h~%1")
output = mw.ustring.gsub(output,"~(.)",H_DEVOICING)
output = mw.ustring.gsub(output,"(["..VOICED.."])h","~%1h")
output = mw.ustring.gsub(output,"~(.)",H_DEVOICING)
output = mw.ustring.gsub(output,"hj","hʧ")
--Misc
output = mw.ustring.gsub(output,"qk","kk")
output = mw.ustring.gsub(output,"kq","kk")
output = mw.ustring.gsub(output,"ao","au")
output = mw.ustring.gsub(output,"ae","ai")
output = mw.ustring.gsub(output,"aw","au")
output = mw.ustring.gsub(output,"ua","wa")
--Add hyphen, if any
if hyphen > 0 then
output = mw.ustring.sub(output,1,hyphen-1)..'-'..mw.ustring.sub(output,hyphen)
end
end
end
for k,v in pairs(NOMOD_PATTERNS) do
return export.expand_consonants(output)
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])
forms[k] = string.gsub(forms[k],"3",tail[3])
end
 
mw.logObject(forms)
return forms
end
end


return export
return export

Latest revision as of 21:47, 5 March 2024

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

export = {}

VOWELS = "aeiouw"

DEVOICED = "ktfsθʧqʃ"
VOICED = "gdvzðʤ"

SIBILANTS = "zsʃʒ"

DEVOICING = {
	["g"] = "k",
	["d"] = "t",
	["v"] = "f",
	["z"] = "s",
	["ð"] = "θ",
	["ʤ"] = "ʧ",
}

H_DEVOICING = {
	["g"] = "k",
	["d"] = "t",
	["v"] = "f",
	["z"] = "z",
	["ð"] = "θ",
}

VvC = {
	["a"] = "au",
	["e"] = "ef",
	["i"] = "if",
	["o"] = "uu",
	["u"] = "uu",
}

function export.compress_consonants(str)
	
	str = str or ''
	
	replace = {{"ssh","ʃʃ"},
				{"ddh","ðð"},
				{"tth","θθ"}, 
				{"cch","ʧʧ"},
				{"sh","ʃ"},
				{"dh","ð"},
				{"th","θ"},
				{"j","ʤ"},
				{"ch","ʧ"},
				{"'",""},
	}
	
	for _,v in ipairs(replace) do
		str = mw.ustring.gsub(str,v[1],v[2])
	end
	
	return str
end

function export.expand_consonants(str)
	replace = {
				{"s'h","sh"},
				{"s'sh","sʃ"},
				{"d'h","dh"},
				{"d'dh","dð"},
				{"t'h","th"},
				{"t'th","tθ"},
				{"ssh","ʃʃ"},
				{"ddh","ðð"},
				{"tth","θθ"}, 
				{"cch","ʧʧ"},
				{"sh","ʃ"},
				{"dh","ð"},
				{"th","θ"},
				{"j","ʤ"},
				{"ch","ʧ"},
	}
	
	for _,v in ipairs(replace) do
		str = mw.ustring.gsub(str,v[2],v[1])
	end
	
	return str
end

function export.assimilate(str)

	output = export.compress_consonants(str)

	if str and str ~= '' then
			--Find and record location of hyphen, if any
			hyphen = mw.ustring.find(output,"-",1,true) or 0
			output = mw.ustring.gsub(output,"-","")
			
			--VvC assimilition FIXME - should not happen if v is geminate. Disabling for now.
			-- output = string.gsub(output,"(["..VOWELS.."])v([^"..VOWELS.."])","%1~v%2"):gsub("(.)~v",{VvC)
			--Sibilant Assimilation
			output = mw.ustring.gsub(output,"(["..SIBILANTS.."])(["..SIBILANTS.."])","%2%2")
			--Nasal Assimilation
			output = mw.ustring.gsub(output,"m([tdszkgθðl])","n%1")
			output = mw.ustring.gsub(output,"n([bfv])","m%1")
			--General Devoicing
			output = mw.ustring.gsub(output,"(["..DEVOICED.."])(["..VOICED.."])","%1~%2")
			output = mw.ustring.gsub(output,"~(.)",DEVOICING)
			output = mw.ustring.gsub(output,"(["..VOICED.."])(["..DEVOICED.."])","~%1%2")
			output = mw.ustring.gsub(output,"~(.)",DEVOICING)
			--H devoicing
			output = mw.ustring.gsub(output,"h(["..VOICED.."])","h~%1")
			output = mw.ustring.gsub(output,"~(.)",H_DEVOICING)
			output = mw.ustring.gsub(output,"(["..VOICED.."])h","~%1h")
			output = mw.ustring.gsub(output,"~(.)",H_DEVOICING)	
			output = mw.ustring.gsub(output,"hj","hʧ")	
			--Misc
			output = mw.ustring.gsub(output,"qk","kk")
			output = mw.ustring.gsub(output,"kq","kk")
			output = mw.ustring.gsub(output,"ao","au")
			output = mw.ustring.gsub(output,"ae","ai")
			output = mw.ustring.gsub(output,"aw","au")
			output = mw.ustring.gsub(output,"ua","wa")
		
			--Add hyphen, if any
			if hyphen > 0 then
				output = mw.ustring.sub(output,1,hyphen-1)..'-'..mw.ustring.sub(output,hyphen)	
			end
	end
	
	return export.expand_consonants(output)
end

return export