local export = {}
--arrays
local rounded_vow = {
= "ۆ",
= "و",
= "او", --for word beginnings
= "یُٛ",
= "یۆ",
= "یٛوٗ",
= "وٗ",
= "ۆ",
= "یٛو" --not really a vowel, but for all practical purposes
}
local centered_vow = {
= "ٔ",
= "ٲ",
= "ٲ",
= "یٖ",
= "ۆ",
}
local fem_cons = {
= "ژ",
= "ژھ",
= "چ",
= "چھ",
= "ج",
= "چ",
= "چھ",
= "ج",
= "ج",
}
local vowels = {
"َ",
"اَ",
"ا",
"آ",
"ٔ",
"ٲ",
"ُ",
"وٗ",
"ۆ",
"و",
"ِ",
"ی",
"یٖ",
"ؠ",
"ُٛ", --???
}
local non_he_ending = {"د", "ڈ", "ذ", "ر", "ڑ", "ز", "ژ", "ھ", "و"}
function export.endswith(main, subs)
return string.sub(main, #main-#subs+1, #main) == subs
end
function export.startswith(main, subs)
return string.sub(main, 1, #subs) == subs
end
--morphological changes
function replace(stem, lst, vow, forms)
local out = {}
local length = #stem
local pat
for i=1, length do
local syl = stem
for chr, repl in pairs(lst) do
local cond = true
if vow then cond = not export.startswith(syl, "و") or #syl > 2 end
if export.endswith(syl, chr) and cond then
if vow then pat = chr.."$" else pat = "^" .. chr end
out = mw.ustring.gsub(syl, pat, repl)
break
else
out = syl
end
end
end
return out
end
local function endswith_vow(str)
if #str > 2 then
for _, v in ipairs(vowels) do
if mw.ustring.match(str, v .. "$") then
return true
end
end
end
return false
end
function repl_last_vow(stem, vow_lst)
return replace(stem, vow_lst, 1)
end
function repl_last_cons(stem, cons_lst)
return replace(stem, cons_lst, 0)
end
function export.rounded(stem)
return repl_last_vow(stem, rounded_vow)
end
function export.centered(stem, vow, forms)
if vow then
return stem
end
return repl_last_vow(stem, centered_vow)
end
function export.fem(stem)
return repl_last_cons(export.centered(stem), fem_cons)
end
function export.fempl(stem)
return repl_last_cons(stem, fem_cons)
end
function export.to_text(tab)
local outstr = ""
for _, v in ipairs(tab) do
outstr = outstr .. mw.ustring.gsub(v,
"",{ = "ی" , = "ێ" })
end
return outstr
end
function export.contains_val(lst, w)
for _, t in pairs(lst) do
if mw.ustring.match(w, t) then
return true
end
end
return false
end
local function add(main, s)
return export.to_text(main) .. s
end
local function add_zer(tab, vow, forms)
local word = export.to_text(tab)
local last = mw.ustring.sub(word, mw.ustring.len(word))
local out = word
if not export.contains_val(non_he_ending, last) then
return word .. "ہِ "
end
return out .."ِ"
end
local function add_sayi(tab, vow, forms)
local word = export.to_text(tab)
local last = mw.ustring.sub(word, mw.ustring.len(word))
local out = word
if not export.contains_val(non_he_ending, last) then
return word .. "ہٕ "
end
return out .."ٕ"
end
--inflections
-- = {"<verb morph>", "<vowel ending>", "<consonant ending>"},
local erg_endings = {
= {"stem", "وان", "ان"},
= {"centered", "تھ", "ِتھ"},
= {"stem", "نَے", "ٕنَے"},
= {"rounded", "مُت", "مُت"},
= {"centered", "مٕتؠ", "ؠ مٕتؠ"},
= {"fem", "مٕژ", "مٕژ"},
= {"fempl", "مَژٕ", "zer_مَژٕ"},
= {"stem", "مہٕ", "sayi_"},
= {"stem", "کھ", "َکھ"},
= {"stem", "یہِ", "zer_"},
= {"stem", "مَو", "َو"},
= {"centered", "یِو", "ِو"},
= {"stem", "ن", "َن"},
= {"rounded", "و", ""},
= {"centered", "یہِ", "ؠ"},
= {"fem", "یہِ", ""},
= {"fempl", "یہِ", "zer_"},
= {"rounded", "تھ", "ُتھ"},
= {"centered", "یَتھ", "ِتھ"},
= {"fem", "یَتھ", "ِتھ"},
= {"fempl", "یَتھ", "ؠتھ"},
= {"rounded", "وٕ", "وٕ"},
= {"centered", "یِوٕ", "ِوٕ"},
= {"fem", "یِوٕ", "ِوٕ"},
= {"fempl", "یِوٕ", "ِوٕ"},
= {}, --don't add
= {"centered", "یِو", "ِو"},
= {"stem", "تہٕ", "تہٕ"},
= {"stem", "تَو", "تَو"},
= {"centered", "ؠ زِ", "ؠ زِ"},
= {"centered", "ؠ زؠو", "ؠ زؠو"},
= {"stem", "ہٲ", "sayi_ہٲ"},
= {"stem", "ہٲکھ", "sayi_ہٲکھ"},
= {"stem", "ہے", "zer_ہے"},
= {"stem", "ہٲو", "sayi_ہٲو"},
= {"stem", "ہیٖو", "zer_ہیٖو"},
= {"stem", "ہٲن", "sayi_ہٲن"},
}
local nom_endings = {
= {"rounded", "س", "ُس"},
= {"rounded", "کھ", "ُکھ"},
= {"rounded", "و", ""},
= {"centered", "یہِ", "ؠ"},
= {"centered", "یِوٕ", "ِوٕ"},
= {"centered", "یہِ", "ؠ"},
= {"fem", "یَس", "ِس"},
= {"fem", "یَکھ", "ٕکھ"},
= {"fem", "یہِ", ""},
= {"fempl", "یہِ", "zer_"},
= {"fempl", "یِوٕ", "ِوٕ"},
= {"fempl", "یہِ", "zer_"},
}
function export.inflection(infl, stem, vow, forms, nom, trans)
if nom_endings or erg_endings then
local inflection
if nom and nom_endings then inflection = nom_endings else inflection = erg_endings end
local form = forms]
mw.log(infl)
if infl == "impsims" then
return mw.ustring.gsub(export.to_text(stem), "ِ$", "ہِ")
elseif endswith_vow(form) then
return add(form, inflection)
else
local suff = inflection
local out = form
if mw.ustring.match(suff, "zer_") then
suff = mw.ustring.gsub(suff, "zer_", "")
out = add_zer(out)
elseif mw.ustring.match(suff, "sayi_") then
suff = mw.ustring.gsub(suff, "sayi_", "")
out = add_sayi(out)
else
out = export.to_text(out)
end
return out .. suff
end
else
return false
end
end
return export