Module:User:Oyunqi/ug-common1

local export = {} local find = mw.ustring.find local sub = mw.ustring.sub local gsub = mw.ustring.gsub local match = mw.ustring.match local length = mw.ustring.len local vowels = "اەېىوۇۆۈ" local vowelsBack = "اوۇ" local vowelsFront = "ەۆۈ" -- local vowelsCentral = "ېى" local consonBack = "خغق" local consonFront = "كگ" local consonJsiz = "پتچخسشفقكھغگبد"

function export.getSyllables(str) local t = {} local last_end = 1 local tepildi = 0 local s, e = find(str,"(.-)[" .. vowels .. "]", 1) while s do		tepildi = 1 if s==1 then --birinchi boghum table.insert(t,sub(str,s,e)) else --bashqa boghum perqi= e - last_end if perqi == 0 then t[#t] = t[#t] .. sub(str,s,s) elseif perqi == 1 then --VCV => V'CV				table.insert(t,sub(str,s,e)) elseif perqi == 2 then --VCCV => VC'CV				table.insert(t,sub(str,s+1,e)) t[#t-1] = t[#t-1] .. sub(str,s,s) elseif perqi == 3 then --VCCCV => VCC'CV				table.insert(t,sub(str,s+2,e)) t[#t-1] = t[#t-1] .. sub(str,s,s+1) elseif perqi == 4 then --VCCCCV => VCC'CCV table.insert(t,sub(str,s+2,e)) t[#t-1] = t[#t-1] .. sub(str,s,s+1) else --			end end last_end = e + 1 s, e = find(str,"(.-)[" .. vowels .. "]", last_end) end if s==nil and tepildi==0 or #str==1 then -- no vowel word else if last_end <= #str then t[#t] = t[#t] .. sub(str,last_end) end end return t end function export.getLast(str) local cnt = 1 local base, v, c = match(str, "(.+)([" .. vowels .. "]+)([^" .. vowels .. "]*)$")	-- if length(v)>1 then v= sub(v, -1) end -- if length(c)>1 then c= sub(c, -1) end if find(base,"[" .. vowels .. "]+") then cnt = 2 end return base, v, c, cnt end

function export.checkTongue(str) local tongue = nil local t = export.getSyllables(str) if #t == 1 then tongue = checkFrontBack(t, #t) if tongue == "central" then tongue = checkCentral(str,t) end else if(t[#t] == "چە") then tongue = checkFrontBack(t, #t-1) if tongue == "central" then local tmp = gsub(str, "چە$", "") tongue = checkChe(tmp) end -- out = gsub(str, "qe$", "qi") --ok else tongue = checkFrontBack(t, #t) if tongue == "central" then tongue = checkCentral(str,t) end end end return tongue end function export.checkWord(str, change, v, c, v2, c2) local tongue = nil local found = nil local t = export.getSyllables(str) if #t == 1 then tongue = checkFrontBack(t, #t) if tongue == "central" then tongue = checkCentral(str,t) end else if(t[#t] == "چە") then tongue = checkFrontBack(t, #t-1) if tongue == "central" then local tmp = gsub(str, "چە$", "") tongue = checkChe(tmp) end -- out = gsub(str, "qe$", "qi") --ok else tongue = checkFrontBack(t, #t) if tongue == "central" then tongue = checkCentral(str,t) end end if change and change ~="no" then if v2 == "" or v2 == nil then if match(str, "[اە]$" ) then v2 = "ى" else v2 = v		   end end if c2 == "" or c2 == nil then --if match(str, "[اە]$" ) then --	v2 = "ى" --else c2 = c		   --end end else v2 = v; c2 = c	end -- print(tongue) -- che mu? front/back -- ye$ mu? no change word, e->e -- e$ ? e -> i   -- yeip e => i  end --local statut = {str=str, t = t, tongue = tongue, c2 = c2, v2 = v2} return tongue, v2, c2 end function checkFrontBack(t, i) local c1, v, c2 = match(t[i], "([" .. vowels .. "]*)([" .. vowels .. "]+)([^" .. vowels .. "]*)")  if match(v,"[" .. vowelsFront .."]$") then return "front" elseif match(v,"[" .. vowelsBack .. "]$") then return "back" else if i > 1 then return checkFrontBack(t, i-1) else return "central" end end end function checkCentral(str, t) if match(str,"[" .. consonBack .."]") then return "back" elseif match(str,"[" .. consonFront .."]") then return "front" else if #t == 1 then --if match(str, "[^bs]*i[xz]$") then return "back" end --if match(str, "[bs]*i[z]$") then return "front" end --if match(str, "[s]*i[r]$") then return "back" end end return false end end function checkChe(str) local ff = match(str,"(.-)[" .. consonBack .. "]") if ff then return "back" else return "front" end end

function export.check(frame) local args if frame.args["test"] then args = frame.args else args = frame:getParent.args end local str = args["head"] or "" local tongue = args["tongue"] or nil local change = args["change"] or 1 local PAGENAME = mw.title.getCurrentTitle.text if str == "" then str = PAGENAME; end local base, v, c, cnt = export.getLast(str) local vv = args[1] or nil local cc = args[2] or nil if tongue == nil then tongue = export.checkTongue(str) end local v1 = v; v2 = v; c1 = c; c2 = c   if vv then if c == "" then -- open if (v == "ا" or v == "ە") then v1 = vv; else v2 = vv; c2 = "ي" end else --close if (v == "ا" or v == "ە") then v2 = vv	   	elseif vv == "-" then v2 = "" end end else if c == "" then -- open c2 = "ي" end end local ae = "" local ghqgk; local ghg local consonJsiz = "پتچخسشفقكھ" local consonJliqSpecial = "غگبد" local dt	local iuu if tongue == "front" or tongue == "f" then ae = "ە" ghg = "گ" if match(c, "[" .. consonJsiz .. consonJliqSpecial .. "]$" ) then ghqgk = "ك" else ghqgk = "گ" end elseif tongue == "back" or tongue == "b" then ae = "ا" ghg = "غ" if match(c, "[" .. consonJsiz .. consonJliqSpecial .. "]$" ) then ghqgk = "ق" else ghqgk = "غ" end end if match(c, "[" .. consonJsiz .. "]$" ) then dt = "ت" else dt = "د" end if match(v2, "[اەېى]$" ) then iuu = "ى" elseif match(v2, "[وۇ]$" ) then iuu = "ۇ" elseif match(v2, "[ۆۈ]$" ) then iuu = "ۈ" end local word = {str = str, base = base, tongue = tongue, c = c, v = v, c1=c1, v1 = v1, c2 = c2, v2 = v2, ae=ae, ghqgk = ghqgk, ghg=ghg, dt=dt, iuu=iuu } return word end

return export