Module:Test: Difference between revisions
From Allocosm
| No edit summary | No edit summary | ||
| Line 6: | Line 6: | ||
| DEVOICED = "ktfsθʧqʃ" | DEVOICED = "ktfsθʧqʃ" | ||
| VOICED = "gdvzðʤ" | VOICED = "gdvzðʤ" | ||
| SIBILANTS = "zsʃʒ" | |||
| DEVOICING = { | DEVOICING = { | ||
| Line 86: | Line 88: | ||
| 	if str and str ~= '' then | 	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. | 			--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) | 			-- 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 | 			--Nasal Assimilation | ||
| 			output = mw.ustring.gsub(output,"m([tdszkgθðl])","n%1") | 			output = mw.ustring.gsub(output,"m([tdszkgθðl])","n%1") | ||
| Line 110: | Line 118: | ||
| 			output = mw.ustring.gsub(output,"ua","wa") | 			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 | ||
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
