Module:Test: Difference between revisions

From Allocosm
No edit summary
No edit summary
 
(2 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",
["ð"] = "θ",
["ʤ"] = "ʧ",
}
 
H_DEVOICING = {
["g"] = "k",
["d"] = "t",
["v"] = "f",
["z"] = "z",
["ð"] = "θ",
}


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


function export.get_forms(root,mod,manual)
function export.compress_consonants(str)
mod = mod or ''
local forms = {}
str = str or ''
local patterns = {}
local head = ""
replace = {{"ssh","ʃʃ"},
local vowel = ""
{"ddh","ðð"},
{"tth","θθ"},
{"cch","ʧʧ"},
{"sh","ʃ"},
{"dh","ð"},
{"th","θ"},
{"j","ʤ"},
{"ch","ʧ"},
{"'",""},
}
local root = m_cu.parse_root(root..mod,true)
for _,v in ipairs(replace) do
str = mw.ustring.gsub(str,v[1],v[2])
end
local tail =  mw.text.split(root[#root],"-")
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","ʧ"},
}
if #root == 1 then
for _,v in ipairs(replace) do
--TBD
str = mw.ustring.gsub(str,v[2],v[1])
elseif #root == 2 then
vowel = root[1]
else
table.remove(root,#root)
vowel = root[#root]
table.remove(root,#root)
head = table.concat(root)
end
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)
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
if str and str ~= '' then
forms[k] = m_cu.assimilate(v)
--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(manual) do
return export.expand_consonants(output)
forms[k] = v
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