Jump to content

Module:hy-common

From Wiktionary, the free dictionary

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

--[[
This module holds some commonly used functions for the Armenian language.
It contains invokable functions for use in templates.
]]

local export = {}

--find if the last letter is a vowel, so that the declension template can suppress a certain impossible inflected form

function export.vowend(frame)
	local vowels = {
		["ա"] = true,
		["ե"] = true,
		["է"] = true,
		["ի"] = true,
		["ո"] = true,
		["օ"] = true,
	}
	local vowels2 = {["ու"] = true}
	
	local pagename = frame.args[1]
	
	if vowels[mw.ustring.sub(pagename, -1)] then
		return "[["..pagename.."ն]]"
	end
	
	if vowels2[mw.ustring.sub(pagename, -2)] then
		return "[["..pagename.."ն]]"
	end

	return "[["..pagename.."ը]]/[["..pagename.."ն]]"
end

--check if starts with a vowel except for <ո> [vo]; used for Western verb conjugation

function export.vowstart(frame)
	local vowels = {
		["ա"] = true,
		["ե"] = true,
		["է"] = true,
		["ի"] = true,
		["օ"] = true,
		["ը"] = true,
	}
	local vowels2 = {["ու"] = true}
	
	local pagename = frame.args[1]
	
	if vowels[mw.ustring.sub(pagename, 1,1)] then
		return 1 
	end
	
	if vowels2[mw.ustring.sub(pagename, 1,2)] then
		return 1
	end
	
	return 0
end

--remove the ending -ել/ալ

function export.elal(frame)
	local pagename = frame.args[1]
	return mw.ustring.sub(pagename,1,-3)
end

--remove the ending -նել/նալ/չել/ուլ

function export.soskacanc(frame)
	local pagename = frame.args[1]
	return mw.ustring.sub(pagename,1,-4)
end

--replace the ending -ի with ել

function export.ilToEl(frame)
	local pagename = frame.args[1]
	local endsinIl = {["իլ"] = true}
	if endsinIl[mw.ustring.sub(pagename, -2)] then
		return (pagename:gsub("իլ$", "ել"))
	end
	return  ""..pagename..""
end

--remove the ending -ցնել

function export.cnel(frame)
	local pagename = frame.args[1]
	return mw.ustring.sub(pagename,1,-5)
end

--remove the ending -ություն

function export.utyun(frame)
	local pagename = frame.args[1]
	return mw.ustring.sub(pagename,1,-8)
end

--remove the ending -ութիւն

function export.utiwn(frame)
	local pagename = frame.args[1]
	return mw.ustring.sub(pagename,1,-7)
end

--remove the ending -ի for u-declension nouns

function export.i(frame)
	local lastvowel = {["ի"] = true}
	local pagename = frame.args[1]
	
	if lastvowel[mw.ustring.sub(pagename, -1)] then
		return mw.ustring.sub(pagename,1,-2)
	end

	return ""..pagename..""
end

--remove the ending -ա for i/u-declension nouns in the Yerevan dialect

function export.a(frame)
	local lastvowel = {["ա"] = true}
	local pagename = frame.args[1]
	
	if lastvowel[mw.ustring.sub(pagename, -1)] then
		return mw.ustring.sub(pagename,1,-2)
	end

	return ""..pagename..""
end

	--insert the glide -յ- for nouns ending in -a and -o

function export.glide(frame)
	local vowels = {
		["ա"] = true,
		["ո"] = true,
		["օ"] = true,
	}
	
	local pagename = frame.args[1]
	
	if vowels[mw.ustring.sub(pagename, -1)] then
		return "յ"
	end
end

	--deletee the glide -յ- for nouns that are polysyllabic and take -ներ (for Western)

function export.glideDelete(frame)
	local lastglide = {["յ"] = true}
	local pagename = frame.args[1]
	
	if lastglide[mw.ustring.sub(pagename, -1)] then
		return mw.ustring.sub(pagename,1,-2)
	end

	return ""..pagename..""
end



-- replace final -ում with -մ for n-declension nouns
function export.um(frame)
	local pagename = frame.args[1]
	return (pagename:gsub("ում$", "մ"))
end

-- replace final -իւն with -ե for n-declension nouns in Old Armenian
function export.iwn(frame)
	local pagename = frame.args[1]
	return (pagename:gsub("իւն$", "ե"))
end

return export