Jump to content

Module:az-common

From Wiktionary, the free dictionary


local export = {}

local ufind = mw.ustring.find
local usub = mw.ustring.sub

function export.getType(term)
	local vowels = "aəeiıuüöoаәеиыуүөо"
	local vowel = "[" .. vowels .. "]"

	local last = usub(term, -1)
	local second_to_last = usub(term, -2, -2)
	local third_to_last = usub(term, -3, -3)

	if ufind(last, vowel) then
		return last, nil
	elseif ufind(second_to_last, vowel) then
		if ufind(last, "[kqгк]") then
			return second_to_last, last
		else
			return second_to_last, "c"
		end
	elseif second_to_last == last then
		return third_to_last, "cc"
	else
		return third_to_last, "c"
	end
end

function export.getLastVowel(term)
	local last_vowel = nil

	for i = mw.ustring.len(str), 1, -1 do
		local char = mw.ustring.sub(str, i, i)

		if mw.ustring.find("AIOUEƏİÖÜaıoueəiöü", char, 1, true) then
			last_vowel = char
			break
		end
	end

	return last_vowel
end

function export.getHarmonicalVowel(term, type)
	local vowels_table = {
		["a"] = { ["open"] = "a", ["close"] = "ı" },
		["ı"] = { ["open"] = "a", ["close"] = "ı" },
		["o"] = { ["open"] = "a", ["close"] = "u" },
		["u"] = { ["open"] = "a", ["close"] = "u" },
		["e"] = { ["open"] = "ə", ["close"] = "i" },
		["ə"] = { ["open"] = "ə", ["close"] = "i" },
		["i"] = { ["open"] = "ə", ["close"] = "i" },
		["ö"] = { ["open"] = "ə", ["close"] = "ü" },
		["ü"] = { ["open"] = "ə", ["close"] = "ü" }
	}

	return harmony_table[export.getLastVowel(term)][type]
end

function export.endsIn(term, classified)
	local final_letter = mw.ustring.sub(term, -1)
	local vowels = "AIOUEƏİÖÜaıoueəiöü"

	return classified and (mw.ustring.find(vowels, final_letter) and "vowel" or "consonant") or final_letter
end

return export