Module:User:Oyunqi/ug-common

local export = {} local vowels = "اەېىوۇۆۈ" local fVowel = "اوۇ" local bVowel = "ەۆۈ" local cVowel = "ېى" local fPlural = "لار" local bPlural = "لەر" local fConsonant = "خغق" local fConsonant2 = "قغ" local bConsonant = "كگ" local full_vowels = require('Module:User:Oyunqi/ug-common/data') local find = mw.ustring.find local length = mw.ustring.len local match = mw.ustring.match local sub = mw.ustring.sub

-- get all syllables function export.syllables(str) local t = {} if type(str) == "table" then str = str.args[1] end if str==nil or str=="" then str = mw.title.getCurrentTitle.text end 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] --.. "222"			t[#t] = t[#t] .. sub(str,last_end) end end return t end

function export.getLast(str) local fixed, lastv, lastc = match(str, "(.-)([" .. vowels .. "]+)([^" .. vowels .. "]-)$")	if length(lastv)>1 then lastv= sub(lastv, -1) end if length(lastc)>1 then lastc= sub(lastc, -1) end return {fixed=fixed, lastv=lastv, lastc=lastc} end

function export.getPlural(str) local syllables = export.syllables(str) local fixed, lastv, lastc = export.getLast(str) if #syllables > 1 and match(syllables[#syllables], "چە$") then local aldiboghum = syllables[#syllables -1] if match(aldiboghum, "[" .. fVowel .. "]") then --front lar return fixed .. lastv .. fPlural elseif match(aldiboghum, "[" .. bVowel .. "]") then --back ler return fixed .. lastv .. bPlural else --central if match(str, "[" .. fConsonant .. "]") then -- x gh q lar return fixed .. lastv .. fPlural else return fixed .. lastv .. bPlural end end end if match(lastv, "[" .. fVowel .. "]") then return fixed .. lastv .. fPlural elseif match(lastv, "[" .. bVowel .. "]") then --back ler return fixed .. lastv .. bPlural else --central if match(str, "[" .. fConsonant .. "]") then -- x gh q lar return fixed .. lastv .. fPlural elseif match(str, "[" .. bConsonant .. "]") then -- k g ler return fixed .. lastv .. bPlural end if #syllables == 1 then if lastv == "ى" and (lastc == "ش" or lastc == "ز") then --chish, ish, iz return fixed .. lastv .. fPlural end else if match(str, "[" .. fVowel .. "]") then --front lar return fixed .. lastv .. fPlural elseif match(str, "[" .. bVowel .. "]") then --back ler return fixed .. lastv .. bPlural end if match(syllables[#syllables], "[" .. fConsonant2 .. "]") then return fixed .. lastv .. fPlural end end end -- local fixed, lastv, lastc = export.getLast(str) -- return {["syllables"] = syllables, ["lastv"] = lastv, ["lastc"] = lastc} end

function export.getAllInfo(str) local data = {} local syllables = export.syllables(str) local fixed, lastv, lastc = export.getLast(str) local lastv_new = full_vowels[lastv] data = {syllables = syllables, lastv = lastv_new, lastc = lastc} return data end

function export.getExeptions(str) return mw.loadData("Module:User:Oyunqi/ug-common/data/nouns")[str] or nil end

return export