Module:User:Oyunqi/ug-common/testcases
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 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,"(.-)" , 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 .. 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 .. sub(str,s,s)
elseif perqi == 3 then --VCCCV => VCC'CV
table.insert(t,sub(str,s+2,e))
t = t .. sub(str,s,s+1)
elseif perqi == 4 then --VCCCCV => VCC'CCV
table.insert(t,sub(str,s+2,e))
t = t .. sub(str,s,s+1)
else
--
end
end
last_end = e + 1
s, e = find(str,"(.-)" , last_end)
end
if s==nil and tepildi==0 or #str==1 then
-- no vowel word
else
if last_end <= #str then
--t = t --.. "222"
t = t .. sub(str,last_end)
end
end
return t
end
function export.getLast(str)
local fixed, lastv, lastc = match(str, "(.-)(+)(-)$")
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, "چە$") then
local aldiboghum = syllables
if match(aldiboghum, "") then --front lar
return fixed .. lastv .. fPlural
elseif match(aldiboghum, "") then --back ler
return fixed .. lastv .. bPlural
else --central
if match(str, "") then -- x gh q lar
return fixed .. lastv .. fPlural
else
return fixed .. lastv .. bPlural
end
end
end
if match(lastv, "") then
return fixed .. lastv .. fPlural
elseif match(lastv, "") then --back ler
return fixed .. lastv .. bPlural
else --central
if match(str, "") then -- x gh q lar
return fixed .. lastv .. fPlural
elseif match(str, "") 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, "") then --front lar
return fixed .. lastv .. fPlural
elseif match(str, "") then --back ler
return fixed .. lastv .. bPlural
end
if match(syllables, "") then
return fixed .. lastv .. fPlural
end
end
end
-- local fixed, lastv, lastc = export.getLast(str)
-- return { = syllables, = lastv, = 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
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") or nil
end
return export