Module:rad-stem: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
 
(45 intermediate revisions by the same user not shown)
Line 1: Line 1:
local export = {}
local export = {}
local getArgs = require('Module:Arguments').getArgs
local getArgs = require("Module:Arguments").getArgs
local m_table = require("Module:table")


local V = "aáàâảeéèiíìỉoóòøuúùûūủyýỳỷ"
local V = "aáàâảeéèiíìỉoóòøuúùûūủyýỳỷ"
Line 13: Line 14:


stem_data = {
stem_data = {
-- heavy stems --
    -- heavy stems --
['b'] = 'C', ['c'] = 'C', ['d'] = 'C', ['ð'] = 'C', ['dz'] = 'C', ['f'] = 'C', ['g'] = 'C', ['ħ'] = 'C', ['j'] = 'C', ['k'] = 'C', ['l'] = 'C', ['m'] = 'C', ['n'] = 'C', ['ņ'] = 'C', ['p'] = 'C', ['r'] = 'C', ['s'] = 'C', ['ș'] = 'C', ['t'] = 'C',['v'] = 'C', ['x'] = 'C', ['z'] = 'C', ['þ'] = 'C',
    ["b"] = "C",
    ["c"] = "C",
-- heavy spirants --
    ["d"] = "C",
['bH'] = 'CH', ['cH'] = 'CH', ['dH'] = 'CH', ['ðH'] = 'CH', ['dzH'] = 'CH', ['fH'] = 'CH', ['gH'] = 'CH', ['jH'] = 'CH', ['kH'] = 'CH', ['lḤ'] = 'CH', ['mḤ'] = 'CH', ['nḤ'] = 'CH', ['ņḤ'] = 'CH', ['pH'] = 'CH', ['rḤ'] = 'CH', ['sH'] = 'CH', ['șH'] = 'CH', ['tH'] = 'CH', ['vH'] = 'CH', ['xH'] = 'CH', ['zH'] = 'CH', ['þH'] = 'CH',
    ["ð"] = "C",
    ["dz"] = "C",
-- semi-light --
    ["f"] = "C",
['a^eG'] = 'G', ['a^oG'] = 'G', ['eG'] = 'G', ['G'] = 'G', ['ieG'] = 'G', ['iG'] = 'G', ['oG'] = 'G', ['øG'] = 'G', ['uG'] = 'G', ['yG'] = 'G', ['yeG'] = 'G',
    ["g"] = "C",
    ["h"] = "C",
-- light --
    ["ħ"] = "C",
['a^e'] = 'V', ['a^o'] = 'V', ['ai'] = 'V', ['au'] = 'V', ['e'] = 'V', ['i'] = 'V', ['ie'] = 'V', ['nj^e'] = 'V', ['o'] = 'V', ['ø'] = 'V', ['oe'] = 'V', ['ove'] = 'V', ['t^o'] = 'V', ['u'] = 'V', ['uve'] = 'V', ['Vj'] = 'V', ['y'] = 'V',
    ["j"] = "C",
    ["k"] = "C",
-- light spirant --
    ["ķ"] = "C",
['H'] = 'VH', ['HH'] = 'VH', [''] = 'VH', ['ḤḤ'] = 'VH',
    ["l"] = "C",
    ["m"] = "C",
    ["n"] = "C",
    ["ņ"] = "C",
    ["p"] = "C",
    ["r"] = "C",
    ["s"] = "C",
    ["ș"] = "C",
    ["t"] = "C",
    ["v"] = "C",
    ["x"] = "C",
    ["z"] = "C",
    ["þ"] = "C",
    -- heavy spirants --
    ["bH"] = "CH",
    ["cH"] = "CH",
    ["dH"] = "CH",
    ["ðH"] = "CH",
    ["dzH"] = "CH",
    ["fH"] = "CH",
    ["gH"] = "CH",
    ["jH"] = "CH",
    ["kH"] = "CH",
    ["lḤ"] = "CH",
    ["mḤ"] = "CH",
    ["nḤ"] = "CH",
    ["ņḤ"] = "CH",
    ["pH"] = "CH",
    ["rḤ"] = "CH",
    ["sH"] = "CH",
    ["șH"] = "CH",
    ["tH"] = "CH",
    ["vH"] = "CH",
    ["xH"] = "CH",
    ["zH"] = "CH",
    ["þH"] = "CH",
    -- semi-light --
    ["a^eG"] = "G",
    ["a^oG"] = "G",
    ["eG"] = "G",
    ["G"] = "G",
    ["ieG"] = "G",
    ["iG"] = "G",
    ["oG"] = "G",
    ["øG"] = "G",
    ["uG"] = "G",
    ["yG"] = "G",
    ["yeG"] = "G",
    -- light --
    ["a"] = "V",
    ["a^e"] = "V",
    ["a^o"] = "V",
    ["ai"] = "V",
    ["au"] = "V",
    ["e"] = "V",
    ["i"] = "V",
    ["ie"] = "V",
    ["iè"] = "V",
    ["nj^e"] = "V",
    ["o"] = "V",
    ["o*"] = "V",
    ["ø"] = "V",
    ["t^o"] = "V",
    ["ķ^o"] = "V",
    ["u"] = "V",
    ["ù"] = "V",
    ["y"] = "V",
    -- light spirant --
    ["H"] = "VH",
    ["HH"] = "VH",
    [""] = "VH",
    ["ḤḤ"] = "VH"
}
}


light_noun_data = { -- NOM, V, ^V, dat, acc, ins, pl, voc
light_noun_data = {
['a^e'] = {"Ra", "a", "e", "an", "ast"},
    -- NOM, V, ^V, dat, acc, ins, pl, voc
['a^o'] = {"Ra", "a", "u", "an", "ast"},
    ["a"] = {"a", "a", "a", "an", "ast"},
['ai'] = {"ai", "ai"},
    ["a^e"] = {"Ra", "a", "e", "an", "ast"},
['áj'] = {"áj", "áj"},
    ["a^o"] = {"Ra", "a", "u", "an", "ast"},
['au'] = {"au", "au"},
    ["ai"] = {"ai", "ai"},
['e'] = {"Ra", "e", "i"},
    ["áj"] = {"áj", "áj"},
['i'] = {"Re", "i"},
    ["au"] = {"au", "au"},
['ie'] = {"íRa", "ie"},
    ["e"] = {"Ra", "e", "=i"},
['o'] = {"Ra", "o", "u", "un", "ust"},
    ["i"] = {"Re", "=i"},
['ø'] = {"Ra", "ø", "y"},
    ["ie"] = {"íRa", "ie"},
['u'] = {"Re", "u"},
    ["iè"] = {"ia", "iè"},
['y'] = {"Re", "y"},
    ["o"] = {"Ra", "o", "u", "un", "ust"},
    ["o*"] = {"o*", "o", "o*", "on*", "ost*"},
['a^eG'] = {"ár", "í", "á", "ád", "aúr", "ai", "áse"},
    ["ø"] = {"Ra", "ø", "y"},
['a^oG'] = {"ár", "ív", "á", "ád", "aúr", "ai", "áse"},
    ["u"] = {"Re", "u"},
['eG'] = {"ír", "í", "ea", "íd", "eúr", "í", "íse"},
    ["ù"] = {"ù", "ù"},
['iG'] = {"ír", "í", "ea", "íd", "iúr", "í", "íse"},
    ["y"] = {"Re", "y"},
['ieG'] = {"ỉr", "ỉ", "iea", "ỉd", "ieúr", "ỉ", "ỉse"},
    ["a^eG"] = {"ár", "í", "á", "ád", "aúr", "ai", "áse"},
['oG'] = {"úr", "ív", "oa", "úd", "oúr", "í", "úse"},
    ["a^oG"] = {"ár", "ív", "á", "ád", "aúr", "ai", "áse"},
['øG'] = {"ýr", "ýj", "øa", "ýd", "øúr", "ý", "ýse"},
    ["eG"] = {"ír", "í", "ea", "íd", "eúr", "í", "íse"},
['uG'] = {"úr", "ív", "oa", "úd", "ủr", "í", "úse"},
    ["iG"] = {"ír", "í", "ea", "íd", "iúr", "í", "íse"},
['yG'] = {"ýr", "ýj", "øa", "ýd", "yúr", "ý", "ýse"},
    ["ieG"] = {"ỉr", "ỉ", "iea", "ỉd", "ieúr", "ỉ", "ỉse"},
['yeG'] = {"ỷr", "ỷ", "yea", "ỷd", "yeúr", "ỷ", "ỷse"},
    ["oG"] = {"úr", "ív", "oa", "úd", "oúr", "í", "úse"},
['G'] = {"jr", "j", "a", "x", "úr", "j", "șe"},
    ["øG"] = {"ýr", "ýj", "øa", "ýd", "øúr", "ý", "ýse"},
    ["uG"] = {"úr", "ív", "oa", "úd", "ủr", "í", "úse"},
    ["yG"] = {"ýr", "ýj", "øa", "ýd", "yúr", "ý", "ýse"},
    ["yeG"] = {"ỷr", "ỷ", "yea", "ỷd", "yeúr", "ỷ", "ỷse"},
    ["G"] = {"jr", "j", "a", "x", "úr", "j", "șe"}
}
}


pos_data = { "noun", "verb" }
pos_data = {"noun", "verb"}


function table.contains(table, element)
-- this function resolves all consonant clashes
  for _, value in pairs(table) do
function resolve_ending(resolution)
    if value == element then
    local function resolve(to_Match, to_Replace)
      return true
        if mw.ustring.find(resolution, to_Match) then
            resolution = mw.ustring.gsub(resolution, to_Match, to_Replace)
        -- mw.log( "/" .. to_Match .. "/ → " .. to_Replace .. " : " .. resolution )
        end
     end
     end
  end
  return false
end


-- this function resolves all consonant clashes
    -- resolve heavy spirant stems --
function resolve_ending(resolution)
 
    resolve("", "")
local function resolve(to_Match, to_Replace)
 
if mw.ustring.find(resolution, to_Match) then
    resolve("([^Ḥ])Ḥ%=e", "%1ge")
resolution = mw.ustring.gsub(resolution, to_Match, to_Replace)
    resolve("(ỉ[HḤ][HḤ]?%=e)$", "ỉè")
-- mw.log( "/" .. to_Match .. "/ → " .. to_Replace .. " : " .. resolution )
    resolve("(ie[HḤ][HḤ]?%=e)$", "íe")
end
    resolve("(ye[HḤ][HḤ]?%=e)$", "ýe")
end
    resolve("(a[HḤ][HḤ]?%=e)$", "ai")
    resolve("(e[HḤ][HḤ]?%=e)$", "ei")
-- resolve heavy spirant stems --
    resolve("(ø[HḤ][HḤ]?%=e)$", "øi")
    resolve("(i[HḤ][HḤ]?%=e)$", "iè")
resolve("", "")
    resolve("(y[HḤ][HḤ]?%=e)$", "yè")
    resolve("(â[HḤ][HḤ]%=e)$", "âi")
 
    resolve("(ỉH%=i%=s)", "ỉes")
    resolve("(ieH%=i%=s)", "ies")
    resolve("(ieH%=i)", "eí")
    resolve("([ei][HḤ]%=i)", "=í")
    resolve("([íỉ][HḤ]%=i)", "ỉ")
    resolve("([øy][HḤ]%=i)", "=ý")
    resolve("(ý[HḤ]%=i)", "ỷ")
 
    resolve("([ouû]H%=[ei])", "ui")
    resolve("([ouû]H%=se)", "ûse")
    resolve("(aH%=[ei])", "ai")
    resolve("([" .. V .. "])H%=[ei]", "%1j=e")
    resolve("ieH%=([aú])", "eív=%1")
    resolve("([" .. V .. "])H%=([aú])", "%1v=%2")
 
    -- resolve semi-light and light spirant stems
    resolve("(%=ý%=s)$", "yes")
    resolve("(%=ú%=s)$", "uos")
    resolve("(%=ỉ%=s)$", "ỉes")
    resolve("([" .. C .. "][" .. C .. "])%=í%=s$", "%1ies")
    resolve("([jșķx])%=í%=s$", "%1ies")
    resolve("(%=í%=s)$", "jes")
 
    -- resolve light stems
    resolve("%=tr", "t=s")
    resolve("%=njr", "nj=s")
    resolve("aij%=R([ae])$", "aí%1")
    resolve("([^a])uv%=R([ae])$", "%1ú=%2")
    resolve("([^au])ov%=R([ae])$", "%1ú=%2")
    resolve("^[ou]v%=R([ae])$", "ú=%1")
    resolve("[ùò]v%=R([ae])$", "ú%1")
    resolve("uav%=Ra$", "uò=Ra")
    resolve("([^eoø])av%=Ra$", "%1o=Ra")
    resolve("uav%=(R?e)$", "uò=%1")
    resolve("([^eoø])av%=(R?e)$", "%1o=%2")
    resolve("([oò])%=Ra$", "%1à")
 
    -- resolve spirants
    resolve("ḤḤ%=g", "=k")
    resolve("ḤḤ%=d", "=t")
    resolve("ḤḤ%=s", "=s")
    resolve("ḤḤ%=a", "=à")
    resolve("ḤḤ%=úr", "úr")
    resolve("ḤḤ%=e", "=e")
    resolve("ḤḤ%=i", "=șe")
 
    resolve("HH%=g", "=ak")
    resolve("HH%=d", "=at")
    resolve("HH%=s", "=as")
    resolve("HH%=a", "=à")
    resolve("HH%=úr", "úr")
    resolve("HH%=e", "=e")
    resolve("HH%=i", "=așe")
    resolve("y%=à$", "ya")
    resolve("y%=a$", "øa")
    resolve("i%=à$", "ia")
    resolve("i%=a$", "ea")
    resolve("u%=à$", "ua")
    resolve("u%=a$", "oa")
    resolve("[aà]%=[aà]", "á")
    resolve("[áả]%=[aà]", "ả")
    resolve("â%=([aàáả])", "o%1")
 
    resolve("kH%=g", "k")
    resolve("kH%=d", "kt")
    resolve("[ḤH]%=g", "g")
    resolve("[ḤH]%=([ds])", "=%1")
    resolve("Ḥ%=i", "j=i")
    resolve("H%=i", "ș=i")
    resolve("Ḥ%=([" .. V .. "])", "g%1")
   
    -- resolve =g/=d
    resolve("([rvħh])%=g", "%1=u")
    resolve("(j%=g)", "j")
    resolve("(j%=d)", "x")
 
    resolve("([pf]%=g)", "f")
    resolve("([pf]%=d)", "f=t")
    resolve("(g%=g)", "g")
    resolve("(k%=g)", "k")
    resolve("(k%=d)", "t")
 
    resolve("(m%=g)", "n=g")
 
    resolve("b%=([gd])", "v=%1")
 
    resolve("(j[ctþ]%=g)", "ș=k")
    resolve("(j[ctþ]%=d)", "ș=t")
 
    resolve("j[dð]%=([gd])", "x=%1")
    resolve("jdz%=([gd])", "x=%1")
 
    resolve("([sș]?[șķ]%=g)", "ș=k")
    resolve("([sș]?[șķ]%=d)", "ș=t")
 
    resolve("[zx]?d?x%=([gd])", "x=%1")
 
    resolve("(s?[cstþ]%=g)", "s=k")
    resolve("(s?[cstþ]%=d)", "s=t")
 
    resolve("z?[zdð]%=([gd])", "z=%1")
    resolve("z?dz%=([gd])", "z=%1")
 
    resolve("([" .. C .. "])[mnņ]%=([gd])", "%1=%2")
 
    -- resolve =s
    resolve("([^a])u([sș])%=se", "%1û%2e")
    resolve("([sș])%=s", "%1")
    resolve("j%=s", "ș")
 
    -- resolve VvC
    resolve("([^eoø])av%=([^" .. V .. "])", "%1au=%2")
    resolve("^av%=([^" .. V .. "])", "au=%1")
    resolve("(àv%=)", "au=")
 
    resolve("([^a])uv%=([^" .. V .. "])", "%1ú=%2")
    resolve("([^au])ov%=([^" .. V .. "])", "%1ú=%2")
    resolve("^[ou]v%=([^" .. V .. "])", "ú=%1")
    resolve("([òù]v%=)", "ú=")
 
    resolve("([^iy])ev%=([^" .. V .. "])", "%1ø=%2")
    resolve("^ev%=([^" .. V .. "])", "ø=%1")
    resolve("(èv%=)", "ø=")
 
    resolve("([^aeuøuâ])iv%=([^" .. V .. "])", "%1y=%2")
    resolve("^iv%=([^" .. V .. "])", "y=%1")
    resolve("(ìv%=)", "y=")
 
    -- resolve CvC
    -- resolve("mv%=([" .. C .. "])","nu=%1")
    resolve("([" .. C .. "])v%=([" .. C .. "])", "%1u=%2")
    resolve("vv%=([aiuú])", "v=%1")
    resolve("([" .. C .. "])v%=R?e$", "%1u=i")
    resolve("([" .. C .. "])v%=Ra$", "%1u=a")
 
    -- resolve -ûve → -úe
    resolve("ûv%=R?e", "ú=e")
    resolve("ûv%=R?e", "ú=e")
 
    -- resolve aja, ava
    resolve("([^eoø])a[vj]%=a", "%1á")
    resolve("(à[vj]%=a)", "á")
 
    -- resolve f/þ~v/ð
    resolve("([" .. V .. O .. L .. J .. "])f%=([" .. V .. J .. "])", "%1v=%2")
    resolve("([" .. V .. O .. L .. J .. "])þ%=([" .. V .. J .. "])", "%1ð=%2")
 
    -- resolve k/g + front vowel
    resolve("k%=([ie])", "c=%1")
    resolve("g%=([ie])", "dz=%1")
 
    -- resolve palatal + i
    resolve("([jșxķ])%=i", "%1=e")


resolve("([^Ḥ])Ḥ%=e", "%1ge")
    -- resolve misc.
resolve("(ie[HḤ][HḤ]?%=e)$", "íe")
    resolve("(v%=g)", "v")
resolve("(ye[HḤ][HḤ]?%=e)$", "ýe")
    resolve("[HḤ][HḤ]%=", "=")
resolve("(a[HḤ][HḤ]?%=e)$", "ai")
    resolve("[HḤ]%=", "=")
resolve("(e[HḤ][HḤ]?%=e)$", "ei")
    resolve("au°?%=R?a", "o=à")
resolve("(ø[HḤ][HḤ]?%=e)$", "øi")
    resolve("au°?%=R?([" .. V .. "])", "o=%1")
resolve("(i[HḤ][HḤ]?%=e)$", "iè")
    resolve("%=(%S*)R", "=%1")
resolve("(y[HḤ][HḤ]?%=e)$", "yè")
    resolve("(%=)", "")
resolve("(â[HḤ][HḤ]%=e)$", "âi")
    resolve("(°)", "")
resolve("(ieH%=i%=s)", "ies")
resolve("(ieH%=i)", "eí")
resolve("([ei][HḤ]%=i)", "=í")
resolve("(í[HḤ]%=i)", "ỉ")
resolve("([øy][HḤ]%=i)", "=ý")
resolve("(ý[HḤ]%=i)", "ỷ")
resolve("([ouû]H%=[ei])", "ui")
resolve("([ouû]H%=se)", "ûse")
resolve("(aH%=[ei])", "ai")
resolve("([" .. V .. "])H%=[ei]", "%1j=e")
resolve("ieH%=([aú])", "eív=%1")
resolve("([" .. V .. "])H%=([aú])", "%1v=%2")
-- resolve semi-light and light spirant stems
resolve("(%=ý%=s)$", "yes")
resolve("(%=ú%=s)$", "uos")
resolve("(%=ỉ%=s)$", "uos")
resolve("([" .. C .. "][" .. C .. "])%=í%=s$", "%1ies")
resolve("([jșķx])%=í%=s$", "%1ies")
resolve("(%=í%=s)$", "jes")
-- resolve light stems
resolve("%=tr", "t=s")
resolve("%=njr", "nj=s")
resolve("aij%=R([ae])$", "aí%1")
resolve("([^a])uv%=R([ae])$", "%1ú=%2")
resolve("([^au])ov%=R([ae])$", "%1ú=%2")
resolve("^[ou]v%=R([ae])$", "ú=%1")
resolve("[ùò]v%=R([ae])$", "ú%1")
resolve("o%=Ra$", "oà")
-- resolve spirants
resolve("ḤḤ%=g", "=k")
resolve("ḤḤ%=d", "=t")
resolve("ḤḤ%=s", "=s")
resolve("ḤḤ%=a", "=à")
resolve("ḤḤ%=úr", "úr")
resolve("ḤḤ%=e", "=e")
resolve("ḤḤ%=i", "=șe")
resolve("HH%=g", "=ak")
resolve("HH%=d", "=at")
resolve("HH%=s", "=as")
resolve("HH%=a", "=à")
resolve("HH%=úr", "úr")
resolve("HH%=e", "=e")
resolve("HH%=i", "=așe")
resolve("y%=à", "ya")
resolve("y%=a", "øa")
resolve("i%=à", "ia")
resolve("i%=a", "ea")
resolve("u%=à", "ua")
resolve("u%=a", "oa")
resolve("[aà]%=[aà]", "á")
resolve("[áả]%=[aà]", "ả")
resolve("â%=([aàáả])", "o%1")
resolve("[ḤH]%=g", "g")
resolve("[ḤH]%=([ds])", "=%1")
resolve("Ḥ%=i", "j=i")
resolve("H%=i", "ș=i")
resolve("Ḥ%=([" .. V .. "])", "g%1")


-- resolve =g/=d
    return resolution
resolve("([rvħ])%=g","%1=u")
resolve("(j%=g)","j")
resolve("(j%=d)","x")
resolve("([pf]%=g)","f")
resolve("([pf]%=d)","f=t")
resolve("(g%=g)","g")
resolve("(k%=g)","k")
resolve("(k%=d)","t")
resolve("(m%=g)","n=g")
resolve("b%=([gd])","v=%1")
resolve("(j[ctþ]%=g)","ș=k")
resolve("(j[ctþ]%=d)","ș=t")
resolve("j[dð]%=([gd])","x=%1")
resolve("jdz%=([gd])","x=%1")
resolve("([sș]?[șķ]%=g)","ș=k")
resolve("([sș]?[șķ]%=d)","ș=t")
resolve("[zx]?d?x%=([gd])","x=%1")
resolve("(s?[cstþ]%=g)","s=k")
resolve("(s?[cstþ]%=d)","s=t")
resolve("z?[zdð]%=([gd])","z=%1")
resolve("z?dz%=([gd])","z=%1")
resolve("([" .. C .. "])[mnņ]%=([gd])", "%1=%2")
-- resolve =s
resolve("([sș])%=s","%1")
resolve("j%=s","ș")
-- resolve VvC
resolve("([^eoø])av%=([^" .. V .. "])","%1au=%2")
resolve("^av%=([^" .. V .. "])","au=%1")
resolve("(àv%=)","au=")
resolve("([^a])uv%=([^" .. V .. "])","%1ú=%2")
resolve("([^au])ov%=([^" .. V .. "])","%1ú=%2")
resolve("^[ou]v%=([^" .. V .. "])","ú=%1")
resolve("([òù]v%=)","ú=")
resolve("([^iy])ev%=([^" .. V .. "])","%1ø=%2")
resolve("^ev%=([^" .. V .. "])","ø=%1")
resolve("(èv%=)","ø=")
resolve("([^aeuøuâ])iv%=([^" .. V .. "])","%1y=%2")
resolve("^iv%=([^" .. V .. "])","y=%1")
resolve("(ìv%=)","y=")
-- resolve CvC
-- resolve("mv%=([" .. C .. "])","nu=%1")
resolve("([" .. C .. "])v%=([" .. C .. "])","%1u=%2")
resolve("vv%=([aiuú])","v=%1")
resolve("([" .. C .. "])v%=R?e$","%1u=i")
resolve("([" .. C .. "])v%=Ra$","%1u=a")
-- resolve -ûve → -úe
resolve("ûv%=R?e", "ú=e")
-- resolve aja, ava
resolve("([^eoø])a[vj]%=a","%1á")
resolve("(à[vj]%=a)","á")
-- resolve f/þ~v/ð
resolve("([" .. V .. O .. L .. J .. "])f%=([" .. V .. J .. "])","%1v=%2")
resolve("([" .. V .. O .. L .. J .. "])þ%=([" .. V .. J .. "])","%1ð=%2")
-- resolve k/g + front vowel
resolve("k%=([ie])","c=%1")
resolve("g%=([ie])","dz=%1")
-- resolve palatal + i
resolve("([jșxķ])%=i","%1=e")
-- resolve misc.
resolve("(v%=g)","v")
resolve("[HḤ][HḤ]%=", "=")
resolve("[HḤ]%=", "=")
resolve("%=(%S*)R", "=%1")
resolve("(%=)","")
resolve("(°)","")
return resolution
end
end


function export.getNounStem(args) -- rad-inflection|pos|principle_part| 3 | 4 | 5, outputs table of principle parts
function export.getNounStem(args) -- rad-inflection|pos|principle_part| 3 | 4 | 5, outputs table of principle parts
local principle_parts = {
    local principle_parts = {
["nom"] = "",
        ["nom"] = "",
["voc"] = "",
        ["voc"] = "",
["gen"] = "",
        ["gen"] = "",
["dat"] = "",
        ["dat"] = "",
["acc"] = "",
        ["acc"] = "",
["ins"] = "",
        ["ins"] = "",
["nompl"] = "",
        ["nompl"] = "",
["genpl"] = "",
        ["genpl"] = "",
["genpl_short"] = "",
        ["genpl_short"] = "",
}
        ["anim"] = ""
    }
local stem = ""
 
local stem_broken = ""
    local stem = ""
local stem_broken_e = ""
    local stem_broken = ""
local stem_raised = ""
    local stem_broken_e = ""
local ending = ""
    local stem_raised = ""
    local ending = ""
-- create stem and ending parameters --  
 
--mw.log("Parameters:")
    -- create stem and ending parameters --
if stem_data[args[4]] or stem_data[args[5]] or stem_data[args[6]] then
    --mw.log("Parameters:")
    if stem_data[args[4]] or stem_data[args[5]] or stem_data[args[6]] then
local v_index = 4 -- max nucleus position
        local v_index = 4 -- max nucleus position
 
while true do
        while true do
if mw.ustring.find(args[v_index], "([%^%~])") and args[v_index + 1] ~= nil then
            if mw.ustring.find(args[v_index], "([%^%~])") and args[v_index + 1] ~= nil then
if mw.ustring.find(args[v_index], "([%^])") then
                if mw.ustring.find(args[v_index], "([%^])") then
stem = mw.ustring.match(args[v_index], "([^%^]+)%^") or ""
                    stem = mw.ustring.match(args[v_index], "([^%^]+)%^") or ""
stem_raised = mw.ustring.match(args[v_index], "%^([^%^]+)")
                    stem_raised = mw.ustring.match(args[v_index], "%^([^%^]+)")
else
                else
stem = args[v_index]
                    stem = args[v_index]
stem_raised = args[v_index]
                    stem_raised = args[v_index]
end
                end
if mw.ustring.find(stem, "([%~])") then
                if mw.ustring.find(stem, "([%~])") then
stem_broken = mw.ustring.match(stem, "%~([^%~%^]+)")
                    stem_broken = mw.ustring.match(stem, "%~([^%~%^]+)")
stem = mw.ustring.match(stem, "([^%~]+)%~")
                    stem = mw.ustring.match(stem, "([^%~]+)%~")
if stem_raised == args[v_index] then
                    if stem_raised == args[v_index] then
stem_raised = stem
                        stem_raised = stem
end
                    end
else
                else
stem_broken = stem
                    stem_broken = stem
end
                end
break
                break
else
            else
if mw.ustring.find(V, mw.ustring.sub(args[v_index], -1)) and args[v_index + 1] ~= nil then
                if mw.ustring.find(V, mw.ustring.sub(args[v_index], -1)) and args[v_index + 1] ~= nil then
stem = args[v_index]
                    stem = args[v_index]
stem_raised = stem
                    stem_raised = stem
stem_broken = stem
                    stem_broken = stem
break
                    break
elseif v_index == 3 then
                elseif v_index == 3 then
stem = args[3]
                    stem = args[3]
stem_raised = stem
                    stem_raised = stem
stem_broken = stem
                    stem_broken = stem
break
                    break
else
                else
v_index = 3
                    v_index = 3
end
                end
end
            end
end
        end
 
if stem_broken == "u" then
        if stem_broken == "u" then
stem_broken_e = "û"
            stem_broken_e = "û"
else
        else
stem_broken_e = stem_broken
            stem_broken_e = stem_broken
end
        end
 
if v_index > 3 then
        if v_index > 3 then
stem = args[v_index - 1] .. stem
            stem = args[v_index - 1] .. stem
stem_broken = args[v_index - 1] .. stem_broken
            stem_broken = args[v_index - 1] .. stem_broken
stem_broken_e = args[v_index - 1] .. stem_broken_e
            stem_broken_e = args[v_index - 1] .. stem_broken_e
stem_raised = args[v_index - 1] .. stem_raised
            stem_raised = args[v_index - 1] .. stem_raised
end
        end
 
if args[v_index + 2] ~= nil then
        if args[v_index + 2] ~= nil then
ending = args[v_index + 2]
            ending = args[v_index + 2]
 
stem = stem .. args[v_index + 1]
            stem = stem .. args[v_index + 1]
stem_broken = stem_broken .. args[v_index + 1]
            stem_broken = stem_broken .. args[v_index + 1]
stem_broken_e = stem_broken_e .. args[v_index + 1]
            stem_broken_e = stem_broken_e .. args[v_index + 1]
stem_raised = stem_raised .. args[v_index + 1]
            stem_raised = stem_raised .. args[v_index + 1]
        elseif args[v_index + 1] ~= nil then
elseif args[v_index + 1] ~= nil then
            ending = args[v_index + 1]
ending = args[v_index + 1]
        elseif stem_data[args[v_index]] then
            ending = args[v_index]
elseif stem_data[args[v_index]] then
            stem = ""
ending = args[v_index]
            stem_broken = ""
stem = ""
            stem_broken_e = ""
stem_broken = ""
            stem_raised = ""
stem_broken_e = ""
        else
stem_raised = ""
            error("No valid ending detected")
else error("No valid ending detected.") end
        end
elseif stem_data[args[3]] then
    elseif stem_data[args[3]] then
ending = args[3]
        ending = args[3]
stem = ""
        stem = ""
stem_broken = ""
        stem_broken = ""
stem_broken_e = ""
        stem_broken_e = ""
stem_raised = ""
        stem_raised = ""
else
    else
error("Invalid format: Please format the arguments as hv|o~u^u|þ, dv|a^u|n|þ, he|rḤ or lorál|eH")
        error("Invalid format: Please format the arguments as hv|o~u^u|þ, dv|a^u|n|þ, he|rḤ or lorál|eH")
end
    end
 
if stem_data[ending] == 'C' or stem_data[ending] == 'CH' or stem_data[ending] == 'VH' then
    if stem_data[ending] == "C" or stem_data[ending] == "CH" or stem_data[ending] == "VH" then
stem = stem .. ending
        stem = stem .. ending
stem_broken = stem_broken .. ending
        stem_broken = stem_broken .. ending
stem_broken_e = stem_broken_e .. ending
        stem_broken_e = stem_broken_e .. ending
stem_raised = stem_raised .. ending
        stem_raised = stem_raised .. ending
end
    end
    --
--[[
 
    --[[
mw.log("Stem: " .. stem)
mw.log("Stem: " .. stem)
if stem_broken then mw.log("Broken stem: " .. stem_broken ) end
if stem_broken then mw.log("Broken stem: " .. stem_broken ) end
Line 363: Line 441:
if stem_raised then mw.log("Raised stem: " .. stem_raised ) end
if stem_raised then mw.log("Raised stem: " .. stem_raised ) end
mw.log("Ending: " .. ending)
mw.log("Ending: " .. ending)
]]--
]] -- generate endings from declension type --
 
-- generate endings from declension type --
    -- HEAVY AND HEAVY SPIRANT --
    if stem_data[ending] == "C" or stem_data[ending] == "CH" or stem_data[ending] == "VH" then
-- HEAVY AND HEAVY SPIRANT --
        -- LIGHT --
if stem_data[ending] == 'C' or stem_data[ending] == 'CH' or stem_data[ending] == 'VH' then
        if
if ending == "j" and not (mw.ustring.sub(stem, -2) == "oj" and mw.ustring.sub(stem, -3) ~= "aoj" and mw.ustring.sub(stem, -3) ~= "uoj") then
            ending == "j" and
principle_parts["nom"] = stem .. "=s"
                not (mw.ustring.sub(stem, -2) == "oj" and mw.ustring.sub(stem, -3) ~= "aoj" and
principle_parts["acc"] = stem .. "=d"
                    mw.ustring.sub(stem, -3) ~= "uoj")
principle_parts["voc"] = stem .. "=se"
        then
else
            principle_parts["nom"] = stem .. "=s"
principle_parts["nom"] = stem_broken .. "=s"
            principle_parts["acc"] = stem .. "=d"
principle_parts["acc"] = stem_broken .. "=d"
            principle_parts["voc"] = stem .. "=se"
principle_parts["voc"] = stem_broken .. "=se"
        else
end
            principle_parts["nom"] = stem_broken .. "=s"
if (ending == 'v' or ending == 'r') and stem_raised == stem then
            principle_parts["acc"] = stem_broken .. "=d"
principle_parts["gen"] = stem .. "=g"
            principle_parts["voc"] = stem_broken .. "=se"
elseif stem_raised ~= stem then
        end
principle_parts["gen"] = stem_raised .. "=g"
        if (ending == "v" or ending == "r") and stem_raised == stem then
else
            principle_parts["gen"] = stem .. "=g"
principle_parts["gen"] = stem_broken .. "=g"
        elseif stem_raised ~= stem then
end
            principle_parts["gen"] = stem_raised .. "=g"
principle_parts["dat"] = stem .. "=a"
        else
principle_parts["ins"] = stem .. "=úr"
            principle_parts["gen"] = stem_broken .. "=g"
principle_parts["nompl"] = stem_broken_e .. "=e"
        end
principle_parts["genpl"] = stem .. "=i"
        principle_parts["dat"] = stem .. "=a"
principle_parts["genpl_short"] = principle_parts["genpl"] .. "=s"
        principle_parts["ins"] = stem .. "=úr"
        principle_parts["nompl"] = stem_broken_e .. "=e"
-- LIGHT --  
        principle_parts["genpl"] = stem .. "=i"
elseif ending == 'nj^e' then
        principle_parts["genpl_short"] = principle_parts["genpl"] .. "=s"
principle_parts["nom"] = stem_broken .. "nș"
        principle_parts["anim"] = stem --for adjs only
principle_parts["voc"] = stem_broken .. "nșe"
    elseif ending == "nj^e" then
principle_parts["gen"] = stem_broken_e .. "njesk"
        principle_parts["nom"] = stem_broken .. "nș"
principle_parts["dat"] = stem_broken_e .. "=" .. "nja"
        principle_parts["voc"] = stem_broken .. "nșe"
principle_parts["acc"] = stem_broken .. "nșt"
        principle_parts["gen"] = stem_broken_e .. "njesk"
principle_parts["ins"] = stem .. "nivúr"
        principle_parts["dat"] = stem_broken_e .. "=" .. "nja"
principle_parts["nompl"] = stem_broken .. "nxe"
        principle_parts["acc"] = stem_broken .. "nșt"
principle_parts["genpl"] = stem_broken .. "nje"
        principle_parts["ins"] = stem .. "nivúr"
principle_parts["genpl_short"] = stem_broken_e .. "nje=s"
        principle_parts["nompl"] = stem_broken .. "nxe"
elseif ending == 't^o' then
        principle_parts["genpl"] = stem_broken_e .. "nje"
principle_parts["nom"] = stem_broken .. "ts"
        principle_parts["genpl_short"] = stem_broken_e .. "nje=s"
principle_parts["voc"] = stem_broken .. "tse"
    elseif mw.ustring.match(ending, "^[tķ]%^o$") then
principle_parts["gen"] = stem .. "tusk"
    local temp_stem = mw.ustring.match(ending, "^([tķ])%^o$")
principle_parts["dat"] = stem .. "ta"
        principle_parts["nom"] = stem_broken .. temp_stem .. "s"
principle_parts["acc"] = stem_broken .. "tst"
        principle_parts["voc"] = stem_broken .. temp_stem .. "se"
principle_parts["ins"] = stem_broken .. "tvúr"
        principle_parts["gen"] = stem .. temp_stem .. "usk"
principle_parts["nompl"] = stem_broken .. "tse"
        principle_parts["dat"] = stem .. temp_stem .. "a"
principle_parts["genpl"] = stem_broken .. "tsi"
        principle_parts["acc"] = stem_broken .. temp_stem .. "st"
principle_parts["genpl_short"] = stem .. "tu=s"
        principle_parts["ins"] = stem_broken .. temp_stem .. "vúr"
elseif stem_data[ending] == 'V' then
        principle_parts["nompl"] = stem_broken .. temp_stem .. "se"
principle_parts["nom"] = stem_broken_e .. "=" .. light_noun_data[ending][1]
        principle_parts["genpl"] = stem_broken .. temp_stem .. "s"
principle_parts["voc"] = stem .. light_noun_data[ending][2] .. "se"
        principle_parts["genpl_short"] = stem .. temp_stem .. "u=s"
principle_parts["gen"] = stem .. (light_noun_data[ending][3] or light_noun_data[ending][2]) .. "sk"
    elseif stem_data[ending] == "V" then
principle_parts["dat"] = stem .. (light_noun_data[ending][4] or (light_noun_data[ending][2] .. "n"))
        -- SEMI-LIGHT
principle_parts["acc"] = stem .. (light_noun_data[ending][5] or (light_noun_data[ending][2] .. "st"))
        principle_parts["nom"] = stem_broken_e .. "=" .. light_noun_data[ending][1]
principle_parts["ins"] = stem .. (light_noun_data[ending][6] or (light_noun_data[ending][2] .. "vúr"))
        principle_parts["voc"] = stem .. light_noun_data[ending][2] .. "se"
principle_parts["nompl"] = stem .. light_noun_data[ending][2] .. "re"
        principle_parts["gen"] = stem .. (light_noun_data[ending][3] or light_noun_data[ending][2]) .. "sk"
principle_parts["genpl"] = stem .. light_noun_data[ending][2]
        principle_parts["dat"] = stem .. (light_noun_data[ending][4] or (light_noun_data[ending][2] .. "n"))
principle_parts["genpl_short"] = stem .. (light_noun_data[ending][3] or light_noun_data[ending][2]) .. "=s"
        principle_parts["acc"] = stem .. (light_noun_data[ending][5] or (light_noun_data[ending][2] .. "st"))
        principle_parts["ins"] = stem .. (light_noun_data[ending][6] or (light_noun_data[ending][2] .. "vúr"))
-- SEMI-LIGHT
        principle_parts["nompl"] = stem .. light_noun_data[ending][2] .. "re"
elseif stem_data[ending] == 'G' then
        principle_parts["genpl"] = stem .. light_noun_data[ending][2]
principle_parts["nom"] = stem_broken .. light_noun_data[ending][1]
        principle_parts["genpl_short"] = stem .. (light_noun_data[ending][3] or light_noun_data[ending][2]) .. "=s"
principle_parts["voc"] = stem .. light_noun_data[ending][7]
    elseif stem_data[ending] == "G" then
principle_parts["gen"] = stem_broken .. light_noun_data[ending][2]
        principle_parts["nom"] = stem_broken .. light_noun_data[ending][1]
principle_parts["dat"] = stem .. light_noun_data[ending][3]
        principle_parts["voc"] = stem .. light_noun_data[ending][7]
principle_parts["acc"] = stem .. light_noun_data[ending][4]
        principle_parts["gen"] = stem_broken .. light_noun_data[ending][2]
principle_parts["ins"] = stem .. light_noun_data[ending][5]
        principle_parts["dat"] = stem .. light_noun_data[ending][3]
principle_parts["nompl"] = stem_broken .. light_noun_data[ending][6] .. "re"
        principle_parts["acc"] = stem .. light_noun_data[ending][4]
principle_parts["genpl"] = stem_broken .. light_noun_data[ending][6]
        principle_parts["ins"] = stem .. light_noun_data[ending][5]
principle_parts["genpl_short"] = stem_broken .. "=" .. light_noun_data[ending][6] .. "=s"
        principle_parts["nompl"] = stem_broken .. light_noun_data[ending][6] .. "re"
end
        principle_parts["genpl"] = stem_broken .. light_noun_data[ending][6]
        principle_parts["genpl_short"] = stem_broken .. "=" .. light_noun_data[ending][6] .. "=s"
--mw.log("——— Resolving ———")
    end
for part, infl in pairs(principle_parts) do
 
principle_parts[part] = resolve_ending(infl)
    --mw.log("——— Resolving ———")
end
    for part, infl in pairs(principle_parts) do
        principle_parts[part] = resolve_ending(infl)
principle_parts["type"] = stem_data[ending]
    end
 
--mw.logObject(principle_parts)
    principle_parts["type"] = stem_data[ending]
return principle_parts
 
    --mw.logObject(principle_parts)
    return principle_parts
end
end


function export.getVerbStem(args) -- outputs table of principle parts
    if args["pre"] then
        for arg, value in pairs(args) do
            if arg ~= "pre" and arg ~= "t" and arg ~= "vstem" and not mw.ustring.match(arg, "note$") then
                args[arg] = args["pre"] .. value
            end
        end
    end
    local principle_parts = {
        ["inf"] = args[1],
        ["2s"] = args[2],
        ["pst"] = args[3],
        ["prespart"] = args[4],
        ["pspart"] = args[5],
        ["passinf"] = args[6],
        ["passprespart"] = args[7] or args[6]
    }
    if args["vstem"] then
        if args.vstem == "true" then
            principle_parts["vstem"] = true
        elseif args.vstem == "false" then
            principle_parts["vstem"] = false
        end
    elseif
        mw.ustring.match(principle_parts["2s"], "[^n]v$") and not mw.ustring.match(principle_parts["inf"], "ft$") and
            not mw.ustring.match(principle_parts["inf"], "aut$")
    then
        principle_parts["vstem"] = true
    else
        principle_parts["vstem"] = false
    end


function export.getVerbStem(args) -- outputs table of principle parts
    -- non-finite parameters
    if principle_parts.vstem then
if args['pre'] then
        principle_parts["vnoun"] = args["vnoun"] or mw.ustring.gsub(principle_parts["2s"], "v$", "nș")
for arg, value in pairs(args) do
    else
if arg ~= "pre" and arg ~= "t" and arg ~= "vstem" and not mw.ustring.match(arg, "note$") then
        principle_parts["vnoun"] = args["vnoun"] or (mw.ustring.gsub(principle_parts["pspart"] .. "aș", "âaș$", "oàș"))
args[arg] = args['pre'] .. value
    end
end
    if mw.ustring.match(principle_parts["pspart"], "ru$") then
end
        principle_parts["pspart"] = mw.ustring.gsub(principle_parts["pspart"], "ru$", "rủ")
end
    else
        principle_parts["pspart"] = mw.ustring.gsub(principle_parts["pspart"] .. "ú", "[uú]ú$", "ủ")
local principle_parts = {
    end
["inf"] = args[1],
 
["2s"] = args[2],
    -- nonpast parameters
["pst"] = args[3],
    if args["1s"] then
["prespart"] = args[4],
        principle_parts["1s"] = args["1s"]
["pspart"] = args[5],
    else
["passinf"] = args[6],
        if principle_parts["vstem"] then
["passprespart"] = args[7] or args[6],
            principle_parts["1s"] = mw.ustring.gsub(principle_parts["2s"], "v$", "") .. "e"
}
        else
            principle_parts["1s"] = principle_parts["2s"] .. "e"
if args["vstem"] then
        end
if args.vstem == "true" then
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([âø])e$", "%1i")
principle_parts["vstem"] = true
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^eoø])ae$", "%1ai")
elseif args.vstem == "false" then
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^i])ee$", "%1ei")
principle_parts["vstem"] = false
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^aeuøâ])ie$", "%1iè")
end
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "ye$", "yè")
elseif mw.ustring.match(principle_parts["2s"],"[^n]v$") and not mw.ustring.match(principle_parts["inf"],"ft$") and not mw.ustring.match(principle_parts["inf"],"aut$") then
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^au])oe$", "%1ui")
principle_parts["vstem"] = true
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^a])ue$", "%1ui")
else
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "uave$", "uòe")
principle_parts["vstem"] = false
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^eøo])ave$", "%1oe")
end
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "iee$", "íe")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "yee$", "ýe")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "uoe$", "úe")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "aoe$", "aoi")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "nve$", "nui")
    end
    if args["3s"] then
        principle_parts["3s"] = args["3s"]
    else
        principle_parts["3s"] = principle_parts["2s"] .. "ș"
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^eoø])aș$", "%1áș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "áș$", "ảș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^aeuøâ])iș$", "%1eaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^i])eș$", "%1eaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^a])uș$", "%1oaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^au])oș$", "%1oaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "aoș$", "aôș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "[øy]ș$", "øaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "âș$", "oaș")
        if principle_parts["vstem"] then
            principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "vș$", "ș")
        end
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "[sș]ș$", "ș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "nvș$", "mș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^eoø])avș$", "%1auș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([nņlr])gș$", "%1ș")
    end
    principle_parts["pl"] = args["pl"]
    principle_parts["a"] = args["a"] or mw.ustring.gsub(principle_parts["2s"] .. "a", "([eoø])a$", "%1à")
    principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "aa$", "á")
    principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "áa$", "ả")
    principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "âa$", "oà")
    if principle_parts["vstem"] then
        principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "ava$", "á")
    end
    --principle_parts["aa"] = args["aa"] --or mw.ustring.gsub(principle_parts["2s"] .. "á", "([^eoø])avá$", "%1áva")
    --principle_parts["ai"] = args["ai"] --or mw.ustring.gsub(principle_parts["2s"] .. "ai", "([^eoø])avai$", "%1áe")
    if principle_parts["vstem"] then
        principle_parts["depers"] = args["depers"] or mw.ustring.gsub(principle_parts["2s"], "v$", "")
    else
        principle_parts["depers"] = args["depers"]
        if principle_parts["depers"] then
            principle_parts["depers"] = mw.ustring.gsub(principle_parts["depers"], "([^eoø])av$", "%1au")
        end
    end
    --principle_parts["o"] = mw.ustring.gsub(principle_parts["2s"] .. "o", "([au])o$", "%1ò")
    local imp_temp = args["depers"]
    if imp_temp then
        if mw.ustring.match(imp_temp, "au$") then
            imp_temp = nil
        elseif mw.ustring.find(imp_temp, "[uú]$") then
            imp_temp = imp_temp .. "a"
        else
        imp_temp = principle_parts["2s"] .. "a"
        end
    end
    if principle_parts["vstem"] then
        principle_parts["imp"] = args["imp"] or mw.ustring.gsub(principle_parts["2s"], "v$", "ja")
    else
        principle_parts["imp"] = args["imp"] or imp_temp or nil
    end
    if args["r"] then
        principle_parts["r"] = args["r"]
    else
        principle_parts["r"] = (principle_parts["depers"] or principle_parts["2s"]) .. "r"
        if principle_parts["vstem"] then
            principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "vr$", "r")
        end
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "([sș])r$", "%1tr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "([zx])r$", "%1dr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "rr$", "r")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "nr$", "rr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "mr$", "mbr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "ņr$", "ņgr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "nvr$", "nur")
    end
 
    -- past parameters
    principle_parts["apst"] = args["apst"] or mw.ustring.gsub(principle_parts["pst"] .. "a", "([eoø])a$", "%1à")
    principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "aa$", "á")
    principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "áa$", "ả")
    principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "âa$", "oà")
    -- principle_parts["aipst"] = args["aipst"]
    principle_parts["epst"] = args["epst"]
    if args["rpst"] then
        principle_parts["rpst"] = args["rpst"]
    else
        principle_parts["rpst"] = principle_parts["pst"] .. "r"
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "([sș])r$", "%1tr")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "([zx])r$", "%1dr")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "rr$", "r")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "nr$", "rr")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "mr$", "mbr")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "ņr$", "ņgr")
    end


-- non-finite parameters
    return principle_parts
if principle_parts.vstem then
principle_parts["vnoun"] = args["vnoun"] or mw.ustring.gsub(principle_parts["2s"],"v$","nș")
else
principle_parts["vnoun"] = args["vnoun"] or (mw.ustring.gsub(principle_parts["pspart"] .. "aș","âaș$","oàș"))
end
if mw.ustring.match(principle_parts["pspart"], "ru$") then
principle_parts["pspart"] = mw.ustring.gsub(principle_parts["pspart"], "ru$", "rủ")
else
principle_parts["pspart"] = mw.ustring.gsub(principle_parts["pspart"] .. "ú","âaș$","oàș")
end
-- nonpast parameters
if args["1s"] then
principle_parts["1s"] = args["1s"]
else
if principle_parts["vstem"] then
principle_parts["1s"] = mw.ustring.gsub(principle_parts["2s"], "v$", "") .. "e"
else
principle_parts["1s"] = principle_parts["2s"] .. "e"
end
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([âø])e$", "%1i")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^eoø])ae$", "%1ai")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^i])ee$", "%1ei")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^aeuøâ])ie$", "%1iè")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "ye$", "%1yè")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^au])oe$", "%1ui")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^a])ue$", "%1ui")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "iee$", "íe")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "yee$", "ýe")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "uoe$", "úe")
principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "nve$", "nui")
end
if args["3s"] then
principle_parts["3s"] = args["3s"]
else
principle_parts["3s"] = principle_parts["2s"] .. "ș"
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^eoø])aș$", "%1áș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "áș$", "ảș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^aeuøâ])iș$", "%1eaș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^i])eș$", "%1eaș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^a])uș$", "%1oaș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^au])oș$", "%1oaș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "[øy]ș$", "øaș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "âș$", "oaș")
if principle_parts["vstem"] then principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "vș$", "ș") end
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "[sș]ș$", "ș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "nvș$", "mș")
principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([nņlr])gș$", "%1ș")
end
principle_parts["pl"] = args["pl"]
principle_parts["a"] = args["a"] or mw.ustring.gsub(principle_parts["2s"] .. "a", "([eoø])a$", "%1à")
principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "aa$", "á")
principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "áa$", "ả")
principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "âa$", "oà")
if principle_parts["vstem"] then principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "ava$", "á") end
--principle_parts["aa"] = args["aa"] --or mw.ustring.gsub(principle_parts["2s"] .. "á", "([^eoø])avá$", "%1áva")
--principle_parts["ai"] = args["ai"] --or mw.ustring.gsub(principle_parts["2s"] .. "ai", "([^eoø])avai$", "%1áe")
if principle_parts["vstem"] then
principle_parts["depers"] = args["depers"] or mw.ustring.gsub(principle_parts["2s"], "v$", "")
else
principle_parts["depers"] = args["depers"]
end
--principle_parts["o"] = mw.ustring.gsub(principle_parts["2s"] .. "o", "([au])o$", "%1ò")
local imp_temp = args["depers"]
if imp_temp then
if mw.ustring.match(imp_temp, "au$") then
imp_temp = nil
else
imp_temp = imp_temp .. "a"
end
end
if principle_parts["vstem"] then
principle_parts["imp"] = args["imp"] or mw.ustring.gsub(principle_parts["2s"], "v$", "ja")
else
principle_parts["imp"] = args["imp"] or imp_temp or nil
end
if args["r"] then
principle_parts["r"] = args["r"]
else
principle_parts["r"] = (principle_parts["depers"] or principle_parts["2s"]) .. "r"
if principle_parts["vstem"] then principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "vr$", "r") end
principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "([sș])r$", "%1tr")
principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "([zx])r$", "%1dr")
principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "rr$", "r")
principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "nr$", "rr")
principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "mr$", "mbr")
principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "ņr$", "ņgr")
principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "nvr$", "nur")
end
-- past parameters
principle_parts["apst"] = args["apst"] or mw.ustring.gsub(principle_parts["pst"] .. "a", "([eoø])a$", "%1à")
principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "aa$", "á")
principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "áa$", "ả")
principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "âa$", "oà")
-- principle_parts["aipst"] = args["aipst"]
principle_parts["epst"] = args["epst"]
if args["rpst"] then
principle_parts["rpst"] = args["rpst"]
else
principle_parts["rpst"] = principle_parts["pst"] .. "r"
principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "([sș])r$", "%1tr")
principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "([zx])r$", "%1dr")
principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "rr$", "r")
principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "nr$", "rr")
principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "mr$", "mbr")
principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "ņr$", "ņgr")
end
return principle_parts
end
end


function export.getStem(frame)
function export.getStem(frame)
local args = getArgs(frame)
    local args = getArgs(frame)
local word = mw.title.getCurrentTitle().subpageText
    local word = mw.title.getCurrentTitle().subpageText
local to_Return = ""
    local to_Return = ""
 
if args[1] ~= nil and table.contains(pos_data, args[1]) then
    if args[1] ~= nil and m_table.contains(pos_data, args[1]) then
local pos = args[1]
        local pos = args[1]
else
    else
local error_text = "Parameter 1 must be:"
        local error_text = "Parameter 1 must be:"
for i, _ in pairs(data) do
        for i, _ in pairs(data) do
error_text = error_text .. " [" .. i .. "]"
            error_text = error_text .. " [" .. i .. "]"
end
        end
error(error_text)
        error(error_text)
end
    end
 
if args[1] == "noun" then
    if args[1] == "noun" then
to_Return = export.getNounStem(args)[args[2]]
        to_Return = export.getNounStem(args)[args[2]]
elseif args[1] == "verb" then
    elseif args[1] == "verb" then
to_Return = export.getVerbStem(args)[args[2]]
        to_Return = export.getVerbStem(args)[args[2]]
end
    end
 
return to_Return
    return to_Return
end
end



Latest revision as of 10:59, 7 October 2024

local export = {}
local getArgs = require("Module:Arguments").getArgs
local m_table = require("Module:table")

local V = "aáàâảeéèiíìỉoóòøuúùûūủyýỳỷ"
local C = "bcdðfghħjĵkķlmnņpqrsștvwxzþ°"
local O_voiced = "bdðgħvxz"
local O_unvoiced = "cfhkķpqsștþ"
local O = O_voiced .. O_unvoiced
local N = "mnņ"
local L = "lr"
local R = L .. N
local J = "jĵw"

stem_data = {
    -- heavy stems --
    ["b"] = "C",
    ["c"] = "C",
    ["d"] = "C",
    ["ð"] = "C",
    ["dz"] = "C",
    ["f"] = "C",
    ["g"] = "C",
    ["h"] = "C",
    ["ħ"] = "C",
    ["j"] = "C",
    ["k"] = "C",
    ["ķ"] = "C",
    ["l"] = "C",
    ["m"] = "C",
    ["n"] = "C",
    ["ņ"] = "C",
    ["p"] = "C",
    ["r"] = "C",
    ["s"] = "C",
    ["ș"] = "C",
    ["t"] = "C",
    ["v"] = "C",
    ["x"] = "C",
    ["z"] = "C",
    ["þ"] = "C",
    -- heavy spirants --
    ["bH"] = "CH",
    ["cH"] = "CH",
    ["dH"] = "CH",
    ["ðH"] = "CH",
    ["dzH"] = "CH",
    ["fH"] = "CH",
    ["gH"] = "CH",
    ["jH"] = "CH",
    ["kH"] = "CH",
    ["lḤ"] = "CH",
    ["mḤ"] = "CH",
    ["nḤ"] = "CH",
    ["ņḤ"] = "CH",
    ["pH"] = "CH",
    ["rḤ"] = "CH",
    ["sH"] = "CH",
    ["șH"] = "CH",
    ["tH"] = "CH",
    ["vH"] = "CH",
    ["xH"] = "CH",
    ["zH"] = "CH",
    ["þH"] = "CH",
    -- semi-light --
    ["a^eG"] = "G",
    ["a^oG"] = "G",
    ["eG"] = "G",
    ["G"] = "G",
    ["ieG"] = "G",
    ["iG"] = "G",
    ["oG"] = "G",
    ["øG"] = "G",
    ["uG"] = "G",
    ["yG"] = "G",
    ["yeG"] = "G",
    -- light --
    ["a"] = "V",
    ["a^e"] = "V",
    ["a^o"] = "V",
    ["ai"] = "V",
    ["au"] = "V",
    ["e"] = "V",
    ["i"] = "V",
    ["ie"] = "V",
    ["iè"] = "V",
    ["nj^e"] = "V",
    ["o"] = "V",
    ["o*"] = "V",
    ["ø"] = "V",
    ["t^o"] = "V",
    ["ķ^o"] = "V",
    ["u"] = "V",
    ["ù"] = "V",
    ["y"] = "V",
    -- light spirant --
    ["H"] = "VH",
    ["HH"] = "VH",
    ["Ḥ"] = "VH",
    ["ḤḤ"] = "VH"
}

light_noun_data = {
    -- NOM, V, ^V, dat, acc, ins, pl, voc
    ["a"] = {"a", "a", "a", "an", "ast"},
    ["a^e"] = {"Ra", "a", "e", "an", "ast"},
    ["a^o"] = {"Ra", "a", "u", "an", "ast"},
    ["ai"] = {"ai", "ai"},
    ["áj"] = {"áj", "áj"},
    ["au"] = {"au", "au"},
    ["e"] = {"Ra", "e", "=i"},
    ["i"] = {"Re", "=i"},
    ["ie"] = {"íRa", "ie"},
    ["iè"] = {"ia", "iè"},
    ["o"] = {"Ra", "o", "u", "un", "ust"},
    ["o*"] = {"o*", "o", "o*", "on*", "ost*"},
    ["ø"] = {"Ra", "ø", "y"},
    ["u"] = {"Re", "u"},
    ["ù"] = {"ù", "ù"},
    ["y"] = {"Re", "y"},
    ["a^eG"] = {"ár", "í", "á", "ád", "aúr", "ai", "áse"},
    ["a^oG"] = {"ár", "ív", "á", "ád", "aúr", "ai", "áse"},
    ["eG"] = {"ír", "í", "ea", "íd", "eúr", "í", "íse"},
    ["iG"] = {"ír", "í", "ea", "íd", "iúr", "í", "íse"},
    ["ieG"] = {"ỉr", "ỉ", "iea", "ỉd", "ieúr", "ỉ", "ỉse"},
    ["oG"] = {"úr", "ív", "oa", "úd", "oúr", "í", "úse"},
    ["øG"] = {"ýr", "ýj", "øa", "ýd", "øúr", "ý", "ýse"},
    ["uG"] = {"úr", "ív", "oa", "úd", "ủr", "í", "úse"},
    ["yG"] = {"ýr", "ýj", "øa", "ýd", "yúr", "ý", "ýse"},
    ["yeG"] = {"ỷr", "ỷ", "yea", "ỷd", "yeúr", "ỷ", "ỷse"},
    ["G"] = {"jr", "j", "a", "x", "úr", "j", "șe"}
}

pos_data = {"noun", "verb"}

-- this function resolves all consonant clashes
function resolve_ending(resolution)
    local function resolve(to_Match, to_Replace)
        if mw.ustring.find(resolution, to_Match) then
            resolution = mw.ustring.gsub(resolution, to_Match, to_Replace)
        -- mw.log( "/" .. to_Match .. "/ → " .. to_Replace .. " : " .. resolution )
        end
    end

    -- resolve heavy spirant stems --

    resolve("", "")

    resolve("([^Ḥ])Ḥ%=e", "%1ge")
    resolve("(ỉ[HḤ][HḤ]?%=e)$", "ỉè")
    resolve("(ie[HḤ][HḤ]?%=e)$", "íe")
    resolve("(ye[HḤ][HḤ]?%=e)$", "ýe")
    resolve("(a[HḤ][HḤ]?%=e)$", "ai")
    resolve("(e[HḤ][HḤ]?%=e)$", "ei")
    resolve("(ø[HḤ][HḤ]?%=e)$", "øi")
    resolve("(i[HḤ][HḤ]?%=e)$", "iè")
    resolve("(y[HḤ][HḤ]?%=e)$", "yè")
    resolve("(â[HḤ][HḤ]%=e)$", "âi")

    resolve("(ỉH%=i%=s)", "ỉes")
    resolve("(ieH%=i%=s)", "ies")
    resolve("(ieH%=i)", "eí")
    resolve("([ei][HḤ]%=i)", "=í")
    resolve("([íỉ][HḤ]%=i)", "ỉ")
    resolve("([øy][HḤ]%=i)", "=ý")
    resolve("(ý[HḤ]%=i)", "ỷ")

    resolve("([ouû]H%=[ei])", "ui")
    resolve("([ouû]H%=se)", "ûse")
    resolve("(aH%=[ei])", "ai")
    resolve("([" .. V .. "])H%=[ei]", "%1j=e")
    resolve("ieH%=([aú])", "eív=%1")
    resolve("([" .. V .. "])H%=([aú])", "%1v=%2")

    -- resolve semi-light and light spirant stems
    resolve("(%=ý%=s)$", "yes")
    resolve("(%=ú%=s)$", "uos")
    resolve("(%=ỉ%=s)$", "ỉes")
    resolve("([" .. C .. "][" .. C .. "])%=í%=s$", "%1ies")
    resolve("([jșķx])%=í%=s$", "%1ies")
    resolve("(%=í%=s)$", "jes")

    -- resolve light stems
    resolve("%=tr", "t=s")
    resolve("%=njr", "nj=s")
    resolve("aij%=R([ae])$", "aí%1")
    resolve("([^a])uv%=R([ae])$", "%1ú=%2")
    resolve("([^au])ov%=R([ae])$", "%1ú=%2")
    resolve("^[ou]v%=R([ae])$", "ú=%1")
    resolve("[ùò]v%=R([ae])$", "ú%1")
    resolve("uav%=Ra$", "uò=Ra")
    resolve("([^eoø])av%=Ra$", "%1o=Ra")
    resolve("uav%=(R?e)$", "uò=%1")
    resolve("([^eoø])av%=(R?e)$", "%1o=%2")
    resolve("([oò])%=Ra$", "%1à")

    -- resolve spirants
    resolve("ḤḤ%=g", "=k")
    resolve("ḤḤ%=d", "=t")
    resolve("ḤḤ%=s", "=s")
    resolve("ḤḤ%=a", "=à")
    resolve("ḤḤ%=úr", "úr")
    resolve("ḤḤ%=e", "=e")
    resolve("ḤḤ%=i", "=șe")

    resolve("HH%=g", "=ak")
    resolve("HH%=d", "=at")
    resolve("HH%=s", "=as")
    resolve("HH%=a", "=à")
    resolve("HH%=úr", "úr")
    resolve("HH%=e", "=e")
    resolve("HH%=i", "=așe")
    resolve("y%=à$", "ya")
    resolve("y%=a$", "øa")
    resolve("i%=à$", "ia")
    resolve("i%=a$", "ea")
    resolve("u%=à$", "ua")
    resolve("u%=a$", "oa")
    resolve("[aà]%=[aà]", "á")
    resolve("[áả]%=[aà]", "ả")
    resolve("â%=([aàáả])", "o%1")

    resolve("kH%=g", "k")
    resolve("kH%=d", "kt")
    resolve("[ḤH]%=g", "g")
    resolve("[ḤH]%=([ds])", "=%1")
    resolve("Ḥ%=i", "j=i")
    resolve("H%=i", "ș=i")
    resolve("Ḥ%=([" .. V .. "])", "g%1")
    
    -- resolve =g/=d
    resolve("([rvħh])%=g", "%1=u")
    resolve("(j%=g)", "j")
    resolve("(j%=d)", "x")

    resolve("([pf]%=g)", "f")
    resolve("([pf]%=d)", "f=t")
    resolve("(g%=g)", "g")
    resolve("(k%=g)", "k")
    resolve("(k%=d)", "t")

    resolve("(m%=g)", "n=g")

    resolve("b%=([gd])", "v=%1")

    resolve("(j[ctþ]%=g)", "ș=k")
    resolve("(j[ctþ]%=d)", "ș=t")

    resolve("j[dð]%=([gd])", "x=%1")
    resolve("jdz%=([gd])", "x=%1")

    resolve("([sș]?[șķ]%=g)", "ș=k")
    resolve("([sș]?[șķ]%=d)", "ș=t")

    resolve("[zx]?d?x%=([gd])", "x=%1")

    resolve("(s?[cstþ]%=g)", "s=k")
    resolve("(s?[cstþ]%=d)", "s=t")

    resolve("z?[zdð]%=([gd])", "z=%1")
    resolve("z?dz%=([gd])", "z=%1")

    resolve("([" .. C .. "])[mnņ]%=([gd])", "%1=%2")

    -- resolve =s
    resolve("([^a])u([sș])%=se", "%1û%2e")
    resolve("([sș])%=s", "%1")
    resolve("j%=s", "ș")

    -- resolve VvC
    resolve("([^eoø])av%=([^" .. V .. "])", "%1au=%2")
    resolve("^av%=([^" .. V .. "])", "au=%1")
    resolve("(àv%=)", "au=")

    resolve("([^a])uv%=([^" .. V .. "])", "%1ú=%2")
    resolve("([^au])ov%=([^" .. V .. "])", "%1ú=%2")
    resolve("^[ou]v%=([^" .. V .. "])", "ú=%1")
    resolve("([òù]v%=)", "ú=")

    resolve("([^iy])ev%=([^" .. V .. "])", "%1ø=%2")
    resolve("^ev%=([^" .. V .. "])", "ø=%1")
    resolve("(èv%=)", "ø=")

    resolve("([^aeuøuâ])iv%=([^" .. V .. "])", "%1y=%2")
    resolve("^iv%=([^" .. V .. "])", "y=%1")
    resolve("(ìv%=)", "y=")

    -- resolve CvC
    -- resolve("mv%=([" .. C .. "])","nu=%1")
    resolve("([" .. C .. "])v%=([" .. C .. "])", "%1u=%2")
    resolve("vv%=([aiuú])", "v=%1")
    resolve("([" .. C .. "])v%=R?e$", "%1u=i")
    resolve("([" .. C .. "])v%=Ra$", "%1u=a")

    -- resolve -ûve → -úe
    resolve("ûv%=R?e", "ú=e")
    resolve("ûv%=R?e", "ú=e")

    -- resolve aja, ava
    resolve("([^eoø])a[vj]%=a", "%1á")
    resolve("(à[vj]%=a)", "á")

    -- resolve f/þ~v/ð
    resolve("([" .. V .. O .. L .. J .. "])f%=([" .. V .. J .. "])", "%1v=%2")
    resolve("([" .. V .. O .. L .. J .. "])þ%=([" .. V .. J .. "])", "%1ð=%2")

    -- resolve k/g + front vowel
    resolve("k%=([ie])", "c=%1")
    resolve("g%=([ie])", "dz=%1")

    -- resolve palatal + i
    resolve("([jșxķ])%=i", "%1=e")

    -- resolve misc.
    resolve("(v%=g)", "v")
    resolve("[HḤ][HḤ]%=", "=")
    resolve("[HḤ]%=", "=")
    resolve("au°?%=R?a", "o=à")
    resolve("au°?%=R?([" .. V .. "])", "o=%1")
    resolve("%=(%S*)R", "=%1")
    resolve("(%=)", "")
    resolve("(°)", "")

    return resolution
end

function export.getNounStem(args) -- rad-inflection|pos|principle_part| 3 | 4 | 5, outputs table of principle parts
    local principle_parts = {
        ["nom"] = "",
        ["voc"] = "",
        ["gen"] = "",
        ["dat"] = "",
        ["acc"] = "",
        ["ins"] = "",
        ["nompl"] = "",
        ["genpl"] = "",
        ["genpl_short"] = "",
        ["anim"] = ""
    }

    local stem = ""
    local stem_broken = ""
    local stem_broken_e = ""
    local stem_raised = ""
    local ending = ""

    -- create stem and ending parameters --
    --mw.log("Parameters:")
    if stem_data[args[4]] or stem_data[args[5]] or stem_data[args[6]] then
        local v_index = 4 -- max nucleus position

        while true do
            if mw.ustring.find(args[v_index], "([%^%~])") and args[v_index + 1] ~= nil then
                if mw.ustring.find(args[v_index], "([%^])") then
                    stem = mw.ustring.match(args[v_index], "([^%^]+)%^") or ""
                    stem_raised = mw.ustring.match(args[v_index], "%^([^%^]+)")
                else
                    stem = args[v_index]
                    stem_raised = args[v_index]
                end
                if mw.ustring.find(stem, "([%~])") then
                    stem_broken = mw.ustring.match(stem, "%~([^%~%^]+)")
                    stem = mw.ustring.match(stem, "([^%~]+)%~")
                    if stem_raised == args[v_index] then
                        stem_raised = stem
                    end
                else
                    stem_broken = stem
                end
                break
            else
                if mw.ustring.find(V, mw.ustring.sub(args[v_index], -1)) and args[v_index + 1] ~= nil then
                    stem = args[v_index]
                    stem_raised = stem
                    stem_broken = stem
                    break
                elseif v_index == 3 then
                    stem = args[3]
                    stem_raised = stem
                    stem_broken = stem
                    break
                else
                    v_index = 3
                end
            end
        end

        if stem_broken == "u" then
            stem_broken_e = "û"
        else
            stem_broken_e = stem_broken
        end

        if v_index > 3 then
            stem = args[v_index - 1] .. stem
            stem_broken = args[v_index - 1] .. stem_broken
            stem_broken_e = args[v_index - 1] .. stem_broken_e
            stem_raised = args[v_index - 1] .. stem_raised
        end

        if args[v_index + 2] ~= nil then
            ending = args[v_index + 2]

            stem = stem .. args[v_index + 1]
            stem_broken = stem_broken .. args[v_index + 1]
            stem_broken_e = stem_broken_e .. args[v_index + 1]
            stem_raised = stem_raised .. args[v_index + 1]
        elseif args[v_index + 1] ~= nil then
            ending = args[v_index + 1]
        elseif stem_data[args[v_index]] then
            ending = args[v_index]
            stem = ""
            stem_broken = ""
            stem_broken_e = ""
            stem_raised = ""
        else
            error("No valid ending detected")
        end
    elseif stem_data[args[3]] then
        ending = args[3]
        stem = ""
        stem_broken = ""
        stem_broken_e = ""
        stem_raised = ""
    else
        error("Invalid format: Please format the arguments as hv|o~u^u|þ, dv|a^u|n|þ, he|rḤ or lorál|eH")
    end

    if stem_data[ending] == "C" or stem_data[ending] == "CH" or stem_data[ending] == "VH" then
        stem = stem .. ending
        stem_broken = stem_broken .. ending
        stem_broken_e = stem_broken_e .. ending
        stem_raised = stem_raised .. ending
    end
     --

    --[[
	mw.log("Stem: " .. stem)
	if stem_broken then mw.log("Broken stem: " .. stem_broken ) end
	if stem_broken_e then mw.log("Broken stem (û): " .. stem_broken_e ) end
	if stem_raised then mw.log("Raised stem: " .. stem_raised ) end
	mw.log("Ending: " .. ending)
	]] -- generate endings from declension type --

    -- HEAVY AND HEAVY SPIRANT --
    if stem_data[ending] == "C" or stem_data[ending] == "CH" or stem_data[ending] == "VH" then
        -- LIGHT --
        if
            ending == "j" and
                not (mw.ustring.sub(stem, -2) == "oj" and mw.ustring.sub(stem, -3) ~= "aoj" and
                    mw.ustring.sub(stem, -3) ~= "uoj")
         then
            principle_parts["nom"] = stem .. "=s"
            principle_parts["acc"] = stem .. "=d"
            principle_parts["voc"] = stem .. "=se"
        else
            principle_parts["nom"] = stem_broken .. "=s"
            principle_parts["acc"] = stem_broken .. "=d"
            principle_parts["voc"] = stem_broken .. "=se"
        end
        if (ending == "v" or ending == "r") and stem_raised == stem then
            principle_parts["gen"] = stem .. "=g"
        elseif stem_raised ~= stem then
            principle_parts["gen"] = stem_raised .. "=g"
        else
            principle_parts["gen"] = stem_broken .. "=g"
        end
        principle_parts["dat"] = stem .. "=a"
        principle_parts["ins"] = stem .. "=úr"
        principle_parts["nompl"] = stem_broken_e .. "=e"
        principle_parts["genpl"] = stem .. "=i"
        principle_parts["genpl_short"] = principle_parts["genpl"] .. "=s"
        principle_parts["anim"] = stem --for adjs only
    elseif ending == "nj^e" then
        principle_parts["nom"] = stem_broken .. "nș"
        principle_parts["voc"] = stem_broken .. "nșe"
        principle_parts["gen"] = stem_broken_e .. "njesk"
        principle_parts["dat"] = stem_broken_e .. "=" .. "nja"
        principle_parts["acc"] = stem_broken .. "nșt"
        principle_parts["ins"] = stem .. "nivúr"
        principle_parts["nompl"] = stem_broken .. "nxe"
        principle_parts["genpl"] = stem_broken_e .. "nje"
        principle_parts["genpl_short"] = stem_broken_e .. "nje=s"
    elseif mw.ustring.match(ending, "^[tķ]%^o$") then
    	local temp_stem = mw.ustring.match(ending, "^([tķ])%^o$")
        principle_parts["nom"] = stem_broken .. temp_stem .. "s"
        principle_parts["voc"] = stem_broken .. temp_stem .. "se"
        principle_parts["gen"] = stem .. temp_stem .. "usk"
        principle_parts["dat"] = stem .. temp_stem .. "a"
        principle_parts["acc"] = stem_broken .. temp_stem .. "st"
        principle_parts["ins"] = stem_broken .. temp_stem .. "vúr"
        principle_parts["nompl"] = stem_broken .. temp_stem .. "se"
        principle_parts["genpl"] = stem_broken .. temp_stem .. "s"
        principle_parts["genpl_short"] = stem .. temp_stem .. "u=s"
    elseif stem_data[ending] == "V" then
        -- SEMI-LIGHT
        principle_parts["nom"] = stem_broken_e .. "=" .. light_noun_data[ending][1]
        principle_parts["voc"] = stem .. light_noun_data[ending][2] .. "se"
        principle_parts["gen"] = stem .. (light_noun_data[ending][3] or light_noun_data[ending][2]) .. "sk"
        principle_parts["dat"] = stem .. (light_noun_data[ending][4] or (light_noun_data[ending][2] .. "n"))
        principle_parts["acc"] = stem .. (light_noun_data[ending][5] or (light_noun_data[ending][2] .. "st"))
        principle_parts["ins"] = stem .. (light_noun_data[ending][6] or (light_noun_data[ending][2] .. "vúr"))
        principle_parts["nompl"] = stem .. light_noun_data[ending][2] .. "re"
        principle_parts["genpl"] = stem .. light_noun_data[ending][2]
        principle_parts["genpl_short"] = stem .. (light_noun_data[ending][3] or light_noun_data[ending][2]) .. "=s"
    elseif stem_data[ending] == "G" then
        principle_parts["nom"] = stem_broken .. light_noun_data[ending][1]
        principle_parts["voc"] = stem .. light_noun_data[ending][7]
        principle_parts["gen"] = stem_broken .. light_noun_data[ending][2]
        principle_parts["dat"] = stem .. light_noun_data[ending][3]
        principle_parts["acc"] = stem .. light_noun_data[ending][4]
        principle_parts["ins"] = stem .. light_noun_data[ending][5]
        principle_parts["nompl"] = stem_broken .. light_noun_data[ending][6] .. "re"
        principle_parts["genpl"] = stem_broken .. light_noun_data[ending][6]
        principle_parts["genpl_short"] = stem_broken .. "=" .. light_noun_data[ending][6] .. "=s"
    end

    --mw.log("——— Resolving ———")
    for part, infl in pairs(principle_parts) do
        principle_parts[part] = resolve_ending(infl)
    end

    principle_parts["type"] = stem_data[ending]

    --mw.logObject(principle_parts)
    return principle_parts
end

function export.getVerbStem(args) -- outputs table of principle parts
    if args["pre"] then
        for arg, value in pairs(args) do
            if arg ~= "pre" and arg ~= "t" and arg ~= "vstem" and not mw.ustring.match(arg, "note$") then
                args[arg] = args["pre"] .. value
            end
        end
    end

    local principle_parts = {
        ["inf"] = args[1],
        ["2s"] = args[2],
        ["pst"] = args[3],
        ["prespart"] = args[4],
        ["pspart"] = args[5],
        ["passinf"] = args[6],
        ["passprespart"] = args[7] or args[6]
    }

    if args["vstem"] then
        if args.vstem == "true" then
            principle_parts["vstem"] = true
        elseif args.vstem == "false" then
            principle_parts["vstem"] = false
        end
    elseif
        mw.ustring.match(principle_parts["2s"], "[^n]v$") and not mw.ustring.match(principle_parts["inf"], "ft$") and
            not mw.ustring.match(principle_parts["inf"], "aut$")
     then
        principle_parts["vstem"] = true
    else
        principle_parts["vstem"] = false
    end

    -- non-finite parameters
    if principle_parts.vstem then
        principle_parts["vnoun"] = args["vnoun"] or mw.ustring.gsub(principle_parts["2s"], "v$", "nș")
    else
        principle_parts["vnoun"] = args["vnoun"] or (mw.ustring.gsub(principle_parts["pspart"] .. "aș", "âaș$", "oàș"))
    end
    if mw.ustring.match(principle_parts["pspart"], "ru$") then
        principle_parts["pspart"] = mw.ustring.gsub(principle_parts["pspart"], "ru$", "rủ")
    else
        principle_parts["pspart"] = mw.ustring.gsub(principle_parts["pspart"] .. "ú", "[uú]ú$", "ủ")
    end

    -- nonpast parameters
    if args["1s"] then
        principle_parts["1s"] = args["1s"]
    else
        if principle_parts["vstem"] then
            principle_parts["1s"] = mw.ustring.gsub(principle_parts["2s"], "v$", "") .. "e"
        else
            principle_parts["1s"] = principle_parts["2s"] .. "e"
        end
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([âø])e$", "%1i")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^eoø])ae$", "%1ai")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^i])ee$", "%1ei")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^aeuøâ])ie$", "%1iè")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "ye$", "yè")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^au])oe$", "%1ui")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^a])ue$", "%1ui")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "uave$", "uòe")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "([^eøo])ave$", "%1oe")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "iee$", "íe")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "yee$", "ýe")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "uoe$", "úe")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "aoe$", "aoi")
        principle_parts["1s"] = mw.ustring.gsub(principle_parts["1s"], "nve$", "nui")
    end
    if args["3s"] then
        principle_parts["3s"] = args["3s"]
    else
        principle_parts["3s"] = principle_parts["2s"] .. "ș"
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^eoø])aș$", "%1áș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "áș$", "ảș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^aeuøâ])iș$", "%1eaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^i])eș$", "%1eaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^a])uș$", "%1oaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^au])oș$", "%1oaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "aoș$", "aôș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "[øy]ș$", "øaș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "âș$", "oaș")
        if principle_parts["vstem"] then
            principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "vș$", "ș")
        end
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "[sș]ș$", "ș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "nvș$", "mș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([^eoø])avș$", "%1auș")
        principle_parts["3s"] = mw.ustring.gsub(principle_parts["3s"], "([nņlr])gș$", "%1ș")
    end
    principle_parts["pl"] = args["pl"]
    principle_parts["a"] = args["a"] or mw.ustring.gsub(principle_parts["2s"] .. "a", "([eoø])a$", "%1à")
    principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "aa$", "á")
    principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "áa$", "ả")
    principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "âa$", "oà")
    if principle_parts["vstem"] then
        principle_parts["a"] = mw.ustring.gsub(principle_parts["a"], "ava$", "á")
    end
    --principle_parts["aa"] = args["aa"] --or mw.ustring.gsub(principle_parts["2s"] .. "á", "([^eoø])avá$", "%1áva")
    --principle_parts["ai"] = args["ai"] --or mw.ustring.gsub(principle_parts["2s"] .. "ai", "([^eoø])avai$", "%1áe")
    if principle_parts["vstem"] then
        principle_parts["depers"] = args["depers"] or mw.ustring.gsub(principle_parts["2s"], "v$", "")
    else
        principle_parts["depers"] = args["depers"]
        if principle_parts["depers"] then
            principle_parts["depers"] = mw.ustring.gsub(principle_parts["depers"], "([^eoø])av$", "%1au")
        end
    end
    --principle_parts["o"] = mw.ustring.gsub(principle_parts["2s"] .. "o", "([au])o$", "%1ò")
    local imp_temp = args["depers"]
    if imp_temp then
        if mw.ustring.match(imp_temp, "au$") then
            imp_temp = nil
        elseif mw.ustring.find(imp_temp, "[uú]$") then
            imp_temp = imp_temp .. "a"
        else
        	imp_temp = principle_parts["2s"] .. "a"
        end
    end
    if principle_parts["vstem"] then
        principle_parts["imp"] = args["imp"] or mw.ustring.gsub(principle_parts["2s"], "v$", "ja")
    else
        principle_parts["imp"] = args["imp"] or imp_temp or nil
    end
    if args["r"] then
        principle_parts["r"] = args["r"]
    else
        principle_parts["r"] = (principle_parts["depers"] or principle_parts["2s"]) .. "r"
        if principle_parts["vstem"] then
            principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "vr$", "r")
        end
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "([sș])r$", "%1tr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "([zx])r$", "%1dr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "rr$", "r")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "nr$", "rr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "mr$", "mbr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "ņr$", "ņgr")
        principle_parts["r"] = mw.ustring.gsub(principle_parts["r"], "nvr$", "nur")
    end

    -- past parameters
    principle_parts["apst"] = args["apst"] or mw.ustring.gsub(principle_parts["pst"] .. "a", "([eoø])a$", "%1à")
    principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "aa$", "á")
    principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "áa$", "ả")
    principle_parts["apst"] = mw.ustring.gsub(principle_parts["apst"], "âa$", "oà")
    -- principle_parts["aipst"] = args["aipst"]
    principle_parts["epst"] = args["epst"]
    if args["rpst"] then
        principle_parts["rpst"] = args["rpst"]
    else
        principle_parts["rpst"] = principle_parts["pst"] .. "r"
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "([sș])r$", "%1tr")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "([zx])r$", "%1dr")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "rr$", "r")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "nr$", "rr")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "mr$", "mbr")
        principle_parts["rpst"] = mw.ustring.gsub(principle_parts["rpst"], "ņr$", "ņgr")
    end

    return principle_parts
end

function export.getStem(frame)
    local args = getArgs(frame)
    local word = mw.title.getCurrentTitle().subpageText
    local to_Return = ""

    if args[1] ~= nil and m_table.contains(pos_data, args[1]) then
        local pos = args[1]
    else
        local error_text = "Parameter 1 must be:"
        for i, _ in pairs(data) do
            error_text = error_text .. " [" .. i .. "]"
        end
        error(error_text)
    end

    if args[1] == "noun" then
        to_Return = export.getNounStem(args)[args[2]]
    elseif args[1] == "verb" then
        to_Return = export.getVerbStem(args)[args[2]]
    end

    return to_Return
end

return export

--[[
Debug console test string:
=p.getStem(mw.getCurrentFrame():newChild{title="whatever",args={"noun", "nom", "dv", "a^u", "n", "þ"}})
]]--