Module:User:SarahFatimaK/apc-conj

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of SarahFatimaK, for their own experimentation. Items in this module may be added and removed at SarahFatimaK's discretion; do not rely on this module's stability.


local export = {}

local PAGENAME = mw.title.getCurrentTitle().text
local cons = 'ʾʿʔʕbdḍḏfgḡhḥjkḵlḷmnpqrsṣštṭṯvwyzẓ'

function export.show(frame)
	-- get arguments
	local args = frame:getParent().args
	local form = frame.args[1] or error("Verb form (arg 1) has not been specified.")
	local pasttr = frame.args[2] or error("Past transliteration (arg 2) has not been specified.")
	local subjtr = frame.args[3] or error("Subjunctive transliteration (arg 3) have not been specified.")
	local past = frame.args[4] or PAGENAME
	-- prepare arguments
	past = mw.ustring.gsub(past, '[ًٌٍَُِّْٰ]', '')	-- remove tashkil
	pasttr = mw.ustring.gsub(mw.ustring.gsub(pasttr, 'e', 'i'), 'o', 'u')	-- change vowels e, o into i, u
	subjtr = mw.ustring.gsub(mw.ustring.gsub(subjtr, 'e', 'i'), 'o', 'u')	-- change vowels e, o into i, u
	subjtr = mw.ustring.gsub(subjtr, '^b?y(.+)$', '%1')	-- get subjunctive/present root
	-- find out type of root
	local tdef = mw.ustring.match(past, '.+([ايى])$')	-- defective root (fa3a/fi3i)
	local thol = mw.ustring.match(past, '.+(ا).$')		-- hollow root (faal)
	local tdbl = mw.ustring.match(pasttr, '.+['..cons..']['..cons..']$')	-- doubled root (fall)
	local treg = false
	
	if form == '2' or form == '5' then
		past = mw.ustring.sub(past, 1, -2) .. 'ّ' .. mw.ustring.sub(past, -1, -1)	-- add shadda after middle root letter
	end
	-- define variants of the past root
	local past2 = past
	local past2tr = pasttr
	local past3ftr = mw.ustring.gsub(pasttr, '^(.*['..cons..'][iu]['..cons..'])[iu](['..cons..'])$', '%1%2')	-- remove medial vowel i/u
	local past3ptr = past3ftr
	-- define variants of the subj/pres root
	local sjvow = mw.ustring.match(subjtr, '^([aiuāīū])')	-- prefix vowel
	local subj = mw.ustring.gsub(past, '^[ا]', '')
	if form == '4' then
		subj = mw.ustring.gsub(subj, '^[أ]', '')
	end
	if sjvow == 'ā' then	-- ʔakal and ʔaḵad
		subj = mw.ustring.gsub(subj, '^أ', 'ا')
	elseif sjvow and sjvow ~= 'a' then	-- change seat of hamza after the vowels i, u
		subj = mw.ustring.gsub(subj, '^[أإ]', sjvow == 'i' and 'ئ' or 'ؤ')

	end
	local subj2 = subj
	local subj2tr = subjtr
	local bpref = sjvow and 'b' or 'bi'		-- b-prefix
	-- special treatment by root type
	if tdef then	-- defective
		past2 = mw.ustring.sub(past, 1, -2) .. 'ي'
		past2tr = mw.ustring.sub(pasttr, 1, -2) .. (tdef == 'ي' and 'ī' or 'ē')
		past3ftr = mw.ustring.sub(pasttr, 1, -2)
		past3ptr = mw.ustring.sub(pasttr, 1, -2) .. (tdef == 'ي' and 'y' or '')
		subj2 = mw.ustring.gsub(subj, '[ايى]$', '')
		subj2tr = mw.ustring.gsub(subjtr, '[ai]$', '')
		if tdef == 'ي' and mw.ustring.sub(subjtr, -1, -1) == 'a' then
			subj = subj2..'ى'
		elseif tdef == 'ى' and mw.ustring.sub(subjtr, -1, -1) == 'i' then
			subj = subj2..'ي'
		end
	elseif thol then	-- hollow
		local sjhvow = mw.ustring.match(subjtr, '([āīū])')
		past2 = mw.ustring.gsub(past, '^(.+)ا(.)$', '%1%2')
		past2tr = mw.ustring.gsub(pasttr, '^(.+)ā(.)$', '%1i%2')
		subj = mw.ustring.sub(past, -3, -3) .. (sjhvow == 'ā' and 'ا' or (sjhvow == 'ū' and 'و' or 'ي')) .. mw.ustring.sub(past, -1, -1)
	elseif tdbl then	-- doubled
		past = past .. 'ّ'
		past2 = past .. 'ي'
		past2tr = pasttr .. 'ē'
	else	-- sound/regular
		treg = true
		subj2tr = mw.ustring.gsub(subj2tr, '([aiuāīū]['..cons..']?['..cons..'])[iu](['..cons..'])', '%1%2')
	end
	-- define imperative roots
	local imp = mw.ustring.gsub(mw.ustring.gsub(subj, '^ا', ''), '[ؤئ]', 'أ')
	local imp2 = mw.ustring.gsub(mw.ustring.gsub(subj2, '^ا', ''), '[ؤئ]', 'أ')
	local imptr = mw.ustring.gsub(subjtr, '^[aiuā]', '')
	local imp2tr = mw.ustring.gsub(subj2tr, '^[aiuā]', '')
	-- special imperative in form I regular/sound and defective
	if form == '1' then
		if treg then
			local sjrvow = mw.ustring.match(subjtr, '([aiu])['..cons..']$')
			imp = mw.ustring.sub(imp, 1, -2) .. (sjrvow == 'a' and 'ا' or (sjrvow == 'u' and 'و' or 'ي')) .. mw.ustring.sub(subj, -1, -1)
			imptr = mw.ustring.sub(imptr, 1, -3) .. (sjrvow == 'a' and 'ā' or (sjrvow == 'u' and 'ō' or 'ē')) .. mw.ustring.sub(subjtr, -1, -1)
			imptr = mw.ustring.gsub(imptr, '^ū', 'w')
			imp2tr = mw.ustring.gsub(subjtr, '^[aiu](.+a['..cons..'])$', '%1')
			imp2tr = mw.ustring.gsub(imp2tr, '^u(.+)[iu](['..cons..'])$', '%1u%2')
			imp2tr = mw.ustring.gsub(imp2tr, '^[aiā](.+)[iu](['..cons..'])$', '%1i%2')
			imp2tr = mw.ustring.gsub(imp2tr, '^ū', 'w')
		elseif tdef then
			imptr = mw.ustring.sub(imptr, 1, -2) .. (tdef == 'ي' and 'ī' or 'ā')
			imp2tr = imp2tr .. 'ˉ'
		end
	end
	-- i/u disappears when stress shifts
	past2tr = mw.ustring.gsub(past2tr, '(['..cons..'])u(['..cons..'])i(['..cons..']?)$', '%1%2u%3')		-- stressed i becomes u in emphatic environment
	past2tr = mw.ustring.gsub(past2tr, '(['..cons..'])[iu](['..cons..'][iuēī]['..cons..']?)$', '%1%2')
	-- output values in arabic script
	local res_ar = {}
	res_ar['past3m'] = past
	res_ar['past3f'] = mw.ustring.gsub(past, '[ايى]$', '')..'ت'
	res_ar['past3p'] = mw.ustring.gsub(past, '[اى]$', '')..'و'
	res_ar['past2m'] = past2..'ت'
	res_ar['past2f'] = past2..'تي'
	res_ar['past2p'] = past2..'تو'
	res_ar['past1s'] = past2..'ت'
	res_ar['past1p'] = past2..'نا'
	res_ar['subj3m'] = 'ي'..subj
	res_ar['subj3f'] = 'ت'..subj
	res_ar['subj3p'] = 'ي'..subj2..'و'
	res_ar['subj2m'] = 'ت'..subj
	res_ar['subj2f'] = 'ت'..subj2..'ي'
	res_ar['subj2p'] = 'ت'..subj2..'و'
	res_ar['subj1s'] = mw.ustring.gsub(((sjvow and (form == '1' or form == '4')) and (sjvow == 'i' and 'إ' or sjvow and 'أ') or '')..subj, 'أا', 'آ')
	res_ar['subj1p'] = 'ن'..subj
	res_ar['pres3m'] = 'بي'..subj
	res_ar['pres3f'] = 'بت'..subj
	res_ar['pres3p'] = 'بي'..subj2..'و'
	res_ar['pres2m'] = 'بت'..subj
	res_ar['pres2f'] = 'بت'..subj2..'ي'
	res_ar['pres2p'] = 'بت'..subj2..'و'
	res_ar['pres1s'] = 'ب'..subj
	res_ar['pres1p'] = 'من'..subj
	res_ar['imp2m'] = imp
	res_ar['imp2f'] = imp2..'ي'
	res_ar['imp2p'] = imp2..'و'
	-- output values in transliteration
	local res_tr = {}
	res_tr['past3m'] = pasttr
	res_tr['past3f'] = past3ftr..'it'
	res_tr['past3p'] = past3ptr..'u'
	res_tr['past2m'] = past2tr..'t'
	res_tr['past2f'] = past2tr..'ti'
	res_tr['past2p'] = past2tr..'tu'
	res_tr['past1s'] = past2tr..'t'
	res_tr['past1p'] = past2tr..'na'
	res_tr['subj3m'] = 'y'..subjtr
	res_tr['subj3f'] = 't'..subjtr
	res_tr['subj3p'] = 'y'..subj2tr..'u'
	res_tr['subj2m'] = 't'..subjtr
	res_tr['subj2f'] = 't'..subj2tr..'i'
	res_tr['subj2p'] = 't'..subj2tr..'u'
	res_tr['subj1s'] = mw.ustring.gsub(((sjvow and (form == '1' or form == '4')) and 'ʔ' or '')..subjtr, '^i', '')
	res_tr['subj1p'] = 'n'..subjtr
	res_tr['pres3m'] = bpref..(sjvow and 'y' or '')..subjtr
	res_tr['pres3f'] = bpref..'t'..subjtr
	res_tr['pres3p'] = bpref..(sjvow and 'y' or '')..subj2tr..'u'
	res_tr['pres2m'] = bpref..'t'..subjtr
	res_tr['pres2f'] = bpref..'t'..subj2tr..'i'
	res_tr['pres2p'] = bpref..'t'..subj2tr..'u'
	res_tr['pres1s'] = 'b'..subjtr
	res_tr['pres1p'] = mw.ustring.gsub(bpref, 'b', 'm')..'n'..subjtr
	res_tr['imp2m'] = imptr
	res_tr['imp2f'] = mw.ustring.gsub(imp2tr..'i', 'ˉi', 'ī')
	res_tr['imp2p'] = mw.ustring.gsub(imp2tr..'u', 'ˉu', 'ū')
	
	return
'<table class="wikitable vsSwitcher vsToggleCategory-conjugation autocollapsed" style="text-align:center; border: 0.5px solid #CCC;">' ..
'<tr><th class="vsToggleElement" style="text-align:left; width:40em" colspan="9">&#160; &#160; Conjugation of <i class="Arab mention" lang="ajp">'..past..'</i></th></tr>' ..
'<tr class="vsHide"><th colspan="2"></th><th colspan="3">singular</th><td rowspan="10"></td><th colspan="3">plural</th></tr>' ..
'<tr class="vsHide"><th colspan="2"></th><th>1<sup>st</sup> person</th><th>2<sup>nd</sup> person</th><th>3<sup>rd</sup> person</th><th>1<sup>st</sup> person</th><th>2<sup>nd</sup> person</th><th>3<sup>rd</sup> person</th></tr>' ..
'<tr class="vsHide">' ..
'	<th rowspan="2">past</th><th><span class="gender"><abbr title="masculine gender">m</abbr></span></th>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['past1s']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['past1s']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['past2m']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['past2m']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['past3m']..'</span> (<span lang="ajp-Latn" class="tr Latn">'..res_tr['past3m']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['past1p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['past1p']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['past2p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['past2p']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['past3p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['past3p']..'</span>)</td></tr>' ..
'<tr class="vsHide">' ..
'	<th><span class="gender"><abbr title="feminine gender">f</abbr></span></th>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['past2f']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['past2f']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['past3f']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['past3f']..'</span>)</td></tr>' ..
'<tr class="vsHide">' ..
'	<th rowspan="2">present</th><th><span class="gender"><abbr title="masculine gender">m</abbr></span></th>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['pres1s']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['pres1s']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['pres2m']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['pres2m']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['pres3m']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['pres3m']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['pres1p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['pres1p']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['pres2p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['pres2p']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['pres3p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['pres3p']..'</span>)</td></tr>' ..
'<tr class="vsHide">' ..
'	<th><span class="gender"><abbr title="feminine gender">f</abbr></span></th>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['pres2f']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['pres2f']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['pres3f']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['pres3f']..'</span>)</td></tr>' ..
'<tr class="vsHide">' ..
'	<th rowspan="2">subjunctive</th><th><span class="gender"><abbr title="masculine gender">m</abbr></span></th>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['subj1s']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['subj1s']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['subj2m']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['subj2m']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['subj3m']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['subj3m']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['subj1p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['subj1p']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['subj2p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['subj2p']..'</span>)</td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['subj3p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['subj3p']..'</span>)</td></tr>' ..
'<tr class="vsHide"><th><span class="gender"><abbr title="feminine gender">f</abbr></span></th>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['subj2f']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['subj2f']..'</span>)</td>' ..
'	<td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['subj3f']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['subj3f']..'</span>)</td></tr>' ..
'<tr class="vsHide"><th rowspan="2">imperative</th><th><span class="gender"><abbr title="masculine gender">m</abbr></span></th>' ..
'	<td rowspan="2"></td><td><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['imp2m']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['imp2m']..'</span>)</td>' ..
'	<td rowspan="2"></td><td rowspan="2"></td>' ..
'	<td rowspan="2"><span class="Arab form-of lang-apc" lang="ajp">'..res_ar['imp2p']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['imp2p']..'</span>)</td>' ..
'	<td rowspan="2"></td></tr>' ..
'<tr class="vsHide">' ..
'	<th><span class="gender"><abbr title="feminine gender">f</abbr></span></th>' ..
'	<td><span class="Arab form-of lang-apc 2&#124;f&#124;s&#124;imperative-form-of" lang="ajp">'..res_ar['imp2f']..'</span>&#8206; (<span lang="ajp-Latn" class="tr Latn">'..res_tr['imp2f']..'</span>)</td></tr>' ..
'</table>'
	
end

return export