Module:tr-conj

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

local export = {}

function export.main(frame)
	local lv = { --low vowels
		["a"] = "a", ["ı"] = "a",
		["o"] = "a", ["u"] = "a",
		["e"] = "e", ["i"] = "e",
		["ö"] = "e", ["ü"] = "e"
	}
	
	local hv = { --high vowels
		["a"] = "ı", ["ı"] = "ı",
		["o"] = "u", ["u"] = "u",
		["e"] = "i", ["i"] = "i",
		["ö"] = "ü", ["ü"] = "ü"
	}
	
	local inf_noun = { --infinitive and verbal noun
		[1] = "infinitive",
		[2] = "verbal noun",
	}
	
	local imper_part = { --impersonal participles
		[1] = "imperfective",
		[2] = "perfective",
		[3] = "prospective"
	}
	
	local per_part = { --personal participles
		[1] = "non-prospective",
		[2] = "prospective"
	}
	
	local time_adv = { --temporal adverbs
		[1] = "simple",
		[2] = "specific",
		[3] = "perfective",
		[4] = '"since"',
		[5] = '"until"',
		[6] = '"as long as"'
	}
	
	local mode_adv = { --modal adverbs
		[1] = "simple",
		[2] = "reduplicated",
		[3] = '"as if"'
	}
	
	local nm = { --"normal" moods names (moods which use copula personal endings)
		[1] = "aorist",
		[2] = "continuous",
		[3] = "inferential",
		[4] = "future",
		[5] = "progressive",
		[6] = "necessitative"
	}
	
	local nqual = { --qualifiers for "normal" moods
		[1] = "simple",
		[2] = "past",
		[3] = "inferential",
		[4] = "conditional",
	}
	
	local wm = { --"weird" moods names (moods which don't use copula personal endings)
		[1] = "past",
		[2] = "conditional"
	}
	
	local wqual = { --"weird" moods qualifiers
		[1] = "simple",
		[12] = "conditional",
		[22] = "past",
		[3] = "inferential"
	}
	
	local impqual = { -- imperative qualifiers
		[1] = "simple",
		[2] = "formal",
		[3] = "informal"
	}
	
	local new_row = ""
	local note = ""
	local comma = ""
	
	local voiceless = "ptkçfshş"

	local str = frame:getParent().args.title or mw.title.getCurrentTitle().text
	local irr = frame:getParent().args[1]

	local function link_term(term, index)
		index = index or 1
		if term ~= " " then
			if term == str then
				return "[[" .. term .. "]]"
			end
			if index == 1 then
				return "[[" .. term .. "#Turkish|" .. term .. "]]"
			else
				return term
			end
		else
			return " "
		end
	end

	local v2, v1, c = mw.ustring.match(str, "([aeıioöuü]*)[^aeıioöuü]*([aeıioöuü]+)([^aeıioöuü]*)m[ae]k$")
	c = mw.ustring.sub(c, -1, -1)

	local stem = mw.ustring.sub(str, 1, -4)
	local altStem_V, altStem_iyor = stem, stem --alternative stems before vowels and before -iyor

	if irr == "d" then
		irr = "e"
		altStem_V = mw.ustring.sub(stem, 1, -2) .. "d"
		altStem_iyor = altStem_V
	elseif not irr then
		if c == "" then
			altStem_V = stem .. "y"
			altStem_iyor = mw.ustring.sub(stem, 1, -2)
			if v2 == "" then
				altStem_V = altStem_iyor .. "iy"
			end
		else
			if v2 == "" then
				irr = lv[v1]
			else
				irr = hv[v1]
			end
		end
	end

	local neg_stem = stem .. "m" .. lv[v1]
	local pot_stem = altStem_V .. lv[v1] .. "bil"
	local impot_stem = altStem_V ..lv[v1] .. "m" .. lv[v1]

	local tab = [=[
<div class="NavFrame" style="width: 100%">
<div class="NavHead" style="background:#DFDFDF" >Conjugation of '']=] .. str .. [=['' </div>
<div class="NavContent">
<div class="vsSwitcher" data-toggle-category="complex tenses" style="max-width:100%;">

{| border="1px solid #aaaaaa" style="border-collapse:collapse; background:#F9F9F9; text-align:center; width:100%" class="inflection-table"
|-
! class="vsToggleElement" colspan=8 style="background:#DFDFDF" | Positive conjugation
|-
| rowspan=2 colspan=2 |
! colspan=3 style="background:#DFDFDF" | singular
! colspan=3 style="background:#DFDFDF" | plural
|-
! style="background:#DFDFDF" | 1st (ben)
! style="background:#DFDFDF" | 2nd (sen)
! style="background:#DFDFDF" | 3rd (o)
! style="background:#DFDFDF" | 1st (biz)
! style="background:#DFDFDF" | 2nd (siz)
! style="background:#DFDFDF" | 3rd (onlar)]=]

	local function conjugate(stem, index)
		v2, v1, c = mw.ustring.match(stem, "([aeıioöuü]?)[^aeıioöuü]*([aeıioöuü])([^aeıioöuü]*)$")
		c = mw.ustring.sub(c, -1, -1)

		if not irr and c == "" then
			irr = v1
			if v2 == "" then
				v2 = "e"
			end
		end

		mw.log(stem .. irr )

		irr = irr .. "r"
	
		if index % 2 == 0 then
			irr = v1 .. "z"
			altStem_V = stem .. "y"
			altStem_iyor = mw.ustring.sub(stem, 1, -2)
		elseif index == 3 then
			irr = "ir"
			altStem_V, altStem_iyor = stem, stem
		end
	
		local nms = {
			altStem_iyor .. irr, 
			altStem_iyor .. (c ~= "" and hv[v1] or hv[v2]) .. "yor",
			stem .. "m" .. hv[v1] .. "ş", 
			altStem_V .. lv[v1] .. "c" .. lv[v1] .. "k",
			stem .. "m" .. lv[v1] .. "kt" .. lv[v1], 
			stem .. "m" .. lv[v1] .. "l" .. hv[lv[v1]]
		} -- normal mood suffixes
		
		for i in ipairs(nms) do
			local suf = nms[i] --suffix
			nms[i] = {}
			
			local sv, sc = mw.ustring.match(suf, "([aeıioöuü]*)([^aeıioöuü]*)$") --suffix vowel, suffix consonant
			local suf_y = (sc ~= "" and "" or "y") --eventual buffer y
			local suf_len = (sc == "k" and "ğ" or "") --lenition of k
			local suf_len_y = (sc == "k" and "ğ" or (sc == "z" and "y" or "")) --lenition of k and insertion of y
			local suf_di = ((mw.ustring.find(voiceless, sc) and sc~= "") and "t" or "d") .. hv[sv]
			
			nms[i][1] = {
				((sc ~= "k" and sc ~= "z") and suf or mw.ustring.sub(suf, 1, -2) .. suf_len) .. suf_y .. (sc ~= "z" and hv[sv] or "") .. "m",
				suf .. "s" .. hv[sv] .. "n",
				suf,
				((sc ~= "k" and sc ~= "z") and suf or mw.ustring.sub(suf, 1, -2) .. suf_len_y) .. suf_y .. hv[sv] .. "z",
				suf .. "s" .. hv[sv] .. "n" .. hv[sv] .. "z",
				suf .. "l" .. lv[sv] .. "r"
			}
			
			nms[i][2] = {
				suf .. suf_y .. suf_di .. "m", 
				suf .. suf_y .. suf_di .. "n", 
				suf .. suf_y .. suf_di, 
				suf .. suf_y .. suf_di .. "k", 
				suf .. suf_y .. suf_di .. "n" .. hv[sv] .. "z", 
				suf .. "l" .. lv[sv] .. "rd" .. hv[lv[sv]]
			}
			
			nms[i][3] = {
				suf .. suf_y .. "m" .. hv[sv] .. "ş" .. hv[sv] .. "m", 
				suf .. suf_y .. "m" .. hv[sv] .. "şs" .. hv[sv] .. "n", 
				suf .. suf_y .. "m" .. hv[sv] .. "ş", 
				suf .. suf_y .. "m" .. hv[sv] .. "ş" .. hv[sv] .. "z", 
				suf .. suf_y .. "m" .. hv[sv] .. "şs" .. hv[sv] .. "n" .. hv[sv] .. "z", 
				suf .. "l" .. lv[sv] .. "rm" .. hv[lv[sv]] .. "ş"
			}
			
			nms[i][4] = {
				suf .. suf_y .. "s" .. lv[sv] .. "m", 
				suf .. suf_y .. "s" .. lv[sv] .. "n", 
				suf .. suf_y .. "s" .. lv[sv], 
				suf .. suf_y .. "s" .. lv[sv] .. "k", 
				suf .. suf_y .. "s" .. lv[sv] .. "n" .. hv[lv[sv]] .. "z", 
				suf .. "l" .. lv[sv] .. "rs" .. lv[sv]
			}
		end --compound tenses and personal endings
		
		local wms = {
			stem .. ((mw.ustring.find(voiceless, c) and c~= "") and "t" or "d") .. hv[v1],
			stem .. "s" .. lv[v1]
		} --weird mood suffixes
		
		for i in ipairs(wms) do
			local suf = wms[i] --suffix
			wms[i] = {}
			
			local sv = mw.ustring.match(suf, "([aeıioöuü]*)$") --suffix vowel
			
			wms[i][1] = {
				suf .. "m", 
				suf .. "n", 
				suf, 
				suf .. "k", 
				suf .. "n" .. hv[sv] .. "z", 
				suf .. "l" .. lv[sv] .. "r"
			}
			
			if hv[sv] == sv then
				wms[i][2] = {
					suf .. "ys" .. lv[sv] .. "m", 
					suf .. "ys" .. lv[sv] .. "n", 
					suf .. "ys" .. lv[sv], 
					suf .. "ys" .. lv[sv] .. "k", 
					suf .. "ys" .. lv[sv] .. "n" .. hv[lv[sv]] .. "z", 
					suf .. "l" .. lv[sv] .. "rs" .. lv[sv]
				}
			else
				wms[i][2] = {
					suf .. "yd" .. hv[sv] .. "m",
					suf .. "yd" .. hv[sv] .. "n",
					suf .. "yd" .. hv[sv],
					suf .. "yd" .. hv[sv] .. "k",
					suf .. "yd" .. hv[sv] .. "n" .. hv[sv] .. "z",
					suf .. "l" .. lv[sv] .. "rd" .. hv[lv[sv]]
				}
				
				wms[i][3] = {
					suf .. "ym" .. hv[sv] .. "ş" .. hv[sv] .. "m",
					suf .. "ym" .. hv[sv] .. "şs" .. hv[sv] .. "n",
					suf .. "ym" .. hv[sv] .. "ş",
					suf .. "ym" .. hv[sv] .. "ş" .. hv[sv] .. "z",
					suf .. "ym" .. hv[sv] .. "şs" .. hv[sv] .. "n" .. hv[sv] .. "z",
					suf .. "l" .. lv[sv] .. "rm" .. hv[lv[sv]] .. "ş"
				}
			end
		end --compound tenses and personal endings
		
		local opt = {
			altStem_V .. lv[v1] .. "y" .. hv[lv[v1]] .. "m",
			altStem_V .. lv[v1] .. "s" .. hv[lv[v1]] .. "n",
			altStem_V .. lv[v1],
			altStem_V .. lv[v1] .. "l" .. hv[lv[v1]] .. "m",
			altStem_V .. lv[v1] .. "s" .. hv[lv[v1]] .. "n" .. hv[lv[v1]] .. "z",
			altStem_V ..lv[v1] .. "l" .. lv[v1] .. "r"
		} --optative 
		
		local imp = {}
		imp[1] = {
			" ",
			stem,
			stem .. "s" .. hv[v1] .. "n",
			" ",
			altStem_V .. hv[v1] .. "n",
			stem .. "s" .. hv[v1] .. "nl" .. lv[v1] .. "r"
		} --normal imperative
		imp[2] = {
			" ",
			altStem_V .. hv[v1] .. "n" .. hv[v1] .. "z",
			" ",
			" ",
			altStem_V .. hv[v1] .. "n" .. hv[v1] .. "z",
			" "
		} --formal imperative
		imp[3] = {
			" ",
			wms[2][1][2] .. lv[v1],
			" ",
			" ",
			wms[2][1][5] .. lv[v1],
			" "
		} --informal imperative
		
		local inf_noun_s = {
			stem .. "m" .. lv[v1] .. "k",
			stem .. "m" .. lv[v1]
		}
		
		local imper_part_s = {
			altStem_V .. lv[v1] .. "n",
			stem .. "m" .. hv[v1] .. "ş",
			altStem_V .. lv[v1] .. "c" .. lv[v1] .. "k"
		}
		
		local per_part_s = {
			stem .. ((mw.ustring.find(voiceless, c) and c ~= "") and "t" or "d") .. hv[v1],
			altStem_V .. lv[v1] .. "c" .. lv[v1]
		}
		for i in ipairs(per_part_s) do
			local suf = per_part_s[i]
			local sv = mw.ustring.match(suf, "([aeıioöuü*])$")
			
			per_part_s[i] = {
				suf .. "ğ" .. hv[sv] .. "m",
				suf .. "ğ" .. hv[sv] .. "n",
				suf .. "ğ" .. hv[sv],
				suf .. "ğ" .. hv[sv] .. "m" .. hv[sv] .. "z",
				suf .. "ğ" .. hv[sv] .. "n" .. hv[sv] .. "z",
				suf .. "kl" .. lv[sv] .. "r" .. hv[lv[sv]]
			}
		end
		
		local time_adv_s = {
			altStem_iyor .. irr .. "ken",
			altStem_V .. hv[v1] .. "nc" .. lv[v1],
			altStem_V .. hv[v1] .. "p",
			altStem_V .. lv[v1] .. "l" .. hv[lv[v1]],
			altStem_V .. lv[v1] .. "s" .. hv[lv[v1]] .. "y" .. lv[v1],
			stem .. ((mw.ustring.find(voiceless, c) and c ~= "") and "t" or "d") .. hv[v1] .. "kç" .. lv[v1]
		}
		
		local mode_adv_s = {
			altStem_V .. lv[v1] .. "r" .. lv[v1] .. "k",
			altStem_V .. lv[v1] .. " " .. altStem_V .. lv[v1],
			altStem_iyor .. irr .. "c" .. lv[v1] .. "s" .. hv[lv[v1]] .. "n" .. lv[v1]
		}
	
		for i in ipairs(nms) do
			tab = tab .. [=[

|-
! colspan=2 rowspan=1 class="vsShow" style="background:#abf" | ]=] .. nm[i] .. [=[

! rowspan=4 class="vsHide" style="background:#abf" | ]=] .. nm[i]
			for j in ipairs(nms[i]) do
				new_row = (j ~= 1) and [=[

|- class="vsHide"]=] or ""
				tab = tab .. new_row .. [=[

! class="vsHide" style="background:#abf" | ]=] .. nqual[j]
				for k in ipairs(nms[i][j]) do
					tab = tab  .. [=[

| style="background:#cdf" | ]=] .. link_term(nms[i][j][k], j)
				end
			end  
		end --adding normal moods to the table
		
		for i in ipairs(wms) do
			tab = tab .. [=[

|-
! colspan=2 rowspan=1 class="vsShow" style="background:#afb" | ]=] .. wm[i] .. [=[

! rowspan=]=] .. #wms[i] ..[=[ class="vsHide" style="background:#afb" | ]=] .. wm[i]
			for j in ipairs(wms[i]) do
				new_row = (j ~= 1) and [=[

|- class="vsHide"]=] or ""
			tab = tab .. new_row .. [=[

! class="vsHide" style="background:#afb" | ]=] .. wqual[(j ~= 2 and 0 or 10)*i + j]
				for k in ipairs(wms[i][j]) do
					tab = tab  .. [=[

| style="background:#cfd" | ]=] .. link_term(wms[i][j][k], j)
				end
			end
		end --adding weird moods to the table
		
		tab = tab .. [=[

|-
! colspan=2 style="background:#afb" | optative]=]
		for i in ipairs(opt) do
			tab = tab .. [=[

| style="background:#cfd" | ]=] .. link_term(opt[i])
		end --adding optative mood to the table
	
		tab = tab .. [=[

|-
! colspan=2 rowspan=1 class="vsShow" style="background:#afb" | imperative
! rowspan=3 class="vsHide" style="background:#afb" | imperative]=]
		for i in ipairs(imp) do
			new_row = (i ~= 1) and [=[

|- class="vsHide"]=]or ""
			tab = tab .. new_row .. [=[

! class="vsHide" style="background:#afb" | ]=] .. impqual[i]
			for j in ipairs(imp[i]) do
				tab = tab  .. [=[

| style="background:#cfd" | ]=] .. link_term(imp[i][j])
			end
		end --adding imperative mood to the table
		
		for i in ipairs(inf_noun) do
			tab = tab .. [=[

|-
! colspan=2 style="background:#ffa" | ]=] .. inf_noun[i] .. [=[

| colspan=6 style="background:#ffc" | ]=] .. link_term(inf_noun_s[i])
		end --adding infinitive and verbal noun
		
		tab = tab .. [=[

|-
! class="vsShow" colspan=2 style="background:#fda" | impersonal participle
! class="vsHide" rowspan=3 style="background:#fda" | impersonal participle
| class="vsShow" colspan=6 style="background:#feb" | ]=]
		for i in ipairs(imper_part) do
			comma = ( i ~= 1) and ", " or ""
			tab = tab .. comma .. link_term(imper_part_s[i])
		end
		for i in ipairs(imper_part_s) do
			new_row = (i ~= 1) and [=[

|- class="vsHide"]=] or ""
			tab = tab .. new_row .. [=[

! class="vsHide" style="background:#fda" | ]=] .. imper_part[i] .. [=[

| class="vsHide" colspan=6 style="background:#feb"| ]=] .. link_term(imper_part_s[i])
		end --adding impersonal participles
		
		tab = tab .. [=[

|-
! rowspan=2 style="background:#fda" | personal participle]=]
		for i in ipairs(per_part) do
			new_row = (i ~= 1) and [=[

|-]=] or ""
			tab = tab .. new_row .. [=[

! style="background:#fda" | ]=] .. per_part[i]
			for j in ipairs(per_part_s[i]) do
				tab = tab .. [=[

| style="background:#feb" | ]=] .. link_term(per_part_s[i][j])
			end
		end --adding personal participles
		
		tab = tab .. [=[

|-
! class="vsShow" colspan=2 style="background:#faa" | temporal adverb
! class="vsHide" rowspan=6 style="background:#faa" | temporal adverb
| class="vsShow" colspan=6 style="background:#fcc" | ]=]
		for i in ipairs(time_adv) do
			note = (i == 1) and "<sup>1</sup>" or ""
			comma = (i ~= 1) and ", " or ""
			tab = tab .. comma .. link_term(time_adv_s[i]) .. note
		end
		for i in ipairs(time_adv) do
			note = (i == 1) and "<sup>1</sup>" or ""
			new_row = (i ~= 1) and [=[

|-]=] or ""
			tab = tab .. new_row .. [=[

! class="vsHide" style="background:#faa" | ]=] .. time_adv[i] .. [=[

| class="vsHide" colspan=6 style="background:#fcc" | ]=] .. link_term(time_adv_s[i]) .. note
		end --adding temporal adverbs
		
		tab = tab .. [=[

|-
! class="vsShow" colspan=2 style="background:#faa" | modal adverb
! class="vsHide" rowspan=3 style="background:#faa" | modal adverb
| class="vsShow" colspan=6 style="background:#fcc" | ]=]
		for i in ipairs(mode_adv) do
			note = (i == 3) and "<sup>1</sup>" or ""
			comma = (i ~= 1) and ", " or ""
			tab = tab .. comma .. link_term(mode_adv_s[i]) .. note
		end	
		for i in ipairs(mode_adv) do
			note = (i == 3) and "<sup>1</sup>" or ""
			new_row = (i ~= 1) and [=[

|-]=] or ""
			tab = tab .. new_row .. [=[

! class="vsHide" style="background:#faa" | ]=] .. mode_adv[i] .. [=[

| class="vsHide" colspan=6 style="background:#fcc" | ]=] .. link_term(mode_adv_s[i]) .. note
		end --adding modal adverbs
		
		tab = tab .. [=[

|-
| colspan=8 style="background:#DFDFDF" | <sup>1</sup>) The suffixes [[-ken#Turkish|''-ken'']] and [[-cesine#Turkish|''-cesine'']] may be suffixed to the base form of any of the following tenses: aorist, continuous, inferential (even when it follows another suffix), and future.
|}</div>]=]
		if index == 2 or index == 3 then
			tab = tab .. "</div>"
		elseif index == 4 then
			tab = tab .. "</div></div></div>"
		end
	end
	
	conjugate(stem, 1)



	--NEGATIVE
	
	

	tab = tab .. [=[

<div class="vsSwitcher" data-toggle-category="negative conjugation" style="max-width:100%;">
* <p style="display:flex; align-self:left">Show negative conjugation: <span class="vsToggleElement">&nbsp;</span></p>
<div class="vsHide vsSwitcher" data-toggle-category="complex tenses" style="max-width:100%;">

{| border="1px solid #aaaaaa" style="border-collapse:collapse; background:#F9F9F9; text-align:center; width:100%" class="inflection-table"
|-
! class="vsToggleElement" colspan=8 style="background: #DFDFDF" | Negative conjugation
|-
| rowspan=2 colspan=2 |
! colspan=3 style="background:#DFDFDF" | singular
! colspan=3 style="background:#DFDFDF" | plural
|-
! style="background:#DFDFDF" | 1st (ben)
! style="background:#DFDFDF" | 2nd (sen)
! style="background:#DFDFDF" | 3rd (o)
! style="background:#DFDFDF" | 1st (biz)
! style="background:#DFDFDF" | 2nd (siz)
! style="background:#DFDFDF" | 3rd (onlar)]=]
	
	conjugate(neg_stem, 2)



	--POTENTIAL
	
	

	tab = tab .. [=[

<div class="vsSwitcher" data-toggle-category="potential conjugation" style="max-width:100%;">
* <p style="display:flex; align-self:left">Show potential conjugation: <span class="vsToggleElement">&nbsp;</span></p>
<div class="vsHide vsSwitcher" data-toggle-category="complex tenses" style="max-width:100%;">

{| border="1px solid #aaaaaa" style="border-collapse:collapse; background:#F9F9F9; text-align:center; width:100%" class="inflection-table"
|-
! class="vsToggleElement" colspan=8 style="background: #DFDFDF" | Potential conjugation
|-
| rowspan=2 colspan=2 |
! colspan=3 style="background:#DFDFDF" | singular
! colspan=3 style="background:#DFDFDF" | plural
|-
! style="background:#DFDFDF" | 1st (ben)
! style="background:#DFDFDF" | 2nd (sen)
! style="background:#DFDFDF" | 3rd (o)
! style="background:#DFDFDF" | 1st (biz)
! style="background:#DFDFDF" | 2nd (siz)
! style="background:#DFDFDF" | 3rd (onlar)]=]
	
	conjugate(pot_stem, 3)



	--IMPOTENTIAL
	
	

	tab = tab .. [=[

<div class="vsSwitcher" data-toggle-category="impotential conjugation" style="max-width:100%;">
* <p style="display:flex; align-self:left">Show impotential conjugation: <span class="vsToggleElement">&nbsp;</span></p>
<div class="vsHide vsSwitcher" data-toggle-category="complex tenses" style="max-width:100%;">

{| border="1px solid #aaaaaa" style="border-collapse:collapse; background:#F9F9F9; text-align:center; width:100%" class="inflection-table"
|-
! class="vsToggleElement" colspan=8 style="background: #DFDFDF" | Impotential conjugation
|-
| rowspan=2 colspan=2 |
! colspan=3 style="background:#DFDFDF" | singular
! colspan=3 style="background:#DFDFDF" | plural
|-
! style="background:#DFDFDF" | 1st (ben)
! style="background:#DFDFDF" | 2nd (sen)
! style="background:#DFDFDF" | 3rd (o)
! style="background:#DFDFDF" | 1st (biz)
! style="background:#DFDFDF" | 2nd (siz)
! style="background:#DFDFDF" | 3rd (onlar)]=]
	
	conjugate(impot_stem, 4)
	
	return(tab)
end

return export