Module:User:Julien Daux/nv-module

local p = {}

local paradigms={}

paradigms["impf"] ={} paradigms["impf"]["∅"] ={"sh","ni","","iid","oh"} paradigms["impf"]["ni"] ={"nish","ní","#","niid","noh"} paradigms["impf"]["yíní"] ={"úínísh","úíní","ó","úíníid","úínóh"} paradigms["impf"]["yii"] ={"iish","ii","ii","iid","ooh"}

--[[   Forms to check :   -  ájółtaʼ   - nabéshhil, nayííyil, nabóhil

]]

-- Common data local disj_= "" local conj_= "" local cl_= "" local c_ = "" local v_ = "" local f_ = "" local tr_= ""

-- convenience shortcuts DA = "da" JI = "ji"

-- Entry point function p.conj(frame) -- retrieve parameters mode = frame.args[1] asp  = frame.args[2] cl_  = frame.args[3] stem = frame.args[4] disj_ = frame.args["disj"] or "" conj_ = frame.args["conj"] or "" obj_ = frame.args["obj"]  or "" -- various pre-formatting par  = paradigms[mode][asp] split_stem(stem)

local data = {} data.form_1sg = proc("", "", "", par[1]) data.form_2sg = proc("", "", "", par[2]) data.form_3sg = proc("",obj_,"", par[3]) data.form_4sg = proc("", "", JI, par[3]) data.form_1dl = proc("", "", "", par[4]) data.form_2dl = proc("", "", "", par[5]) data.form_1pl = proc(DA, "", "", par[4]) data.form_2pl = proc(DA, "", "", par[5]) data.form_3pl = proc(DA,obj_,"", par[3]) data.form_4pl = proc(DA, "", JI, par[3]) if frame.args["test"] then return make_string(data) else return make_table("IMPERFECTIVE",data) end end

-- Various helper functions

local subst = mw.ustring.gsub local find = mw.ustring.find local sub  = mw.ustring.sub local len  = mw.ustring.len

function last(str, i)   return sub(str, len(str) - i + 1) end

function first(str, i)   return sub(str,1,len(str)-i) end

function at(str, i)   j = (i>0) and i or (len(str)+i+1) return sub(str, j, j) end

function is_in(s, ss) for _, k in ipairs(ss)  do       if s == k  then return true end end return false end

function split_stem(stem) c1, c2 = find(stem, cons_re) v1, v2 = find(stem, vow_re) c_ = sub(stem, c1, c2) v_ = sub(stem, v1, v2) f_ = "" if v2 ~= nil and v2 < len(stem) then f_ = sub(stem, v2+1) end end

vowels = "aąáeęéiíoó" vow_re = "([".. vowels.."]+)" cons_re= "([^%-" .. vowels .."]+)"

hiss={ "s", "z", "ts", "dz", "tsʼ"} hush={ "sh","zh", "ch", "j", "chʼ"}

local d_effect = { ["z"] = "dz", ["zh"] = "j", ["gh"] = "g", ["y"]  = "g", ["w"] = "g",  ["l"]  = "dl", ["ʼ"] = "tʼ", ["m"]  = "ʼm", ["n"] = "ʼn" } -- Note: the majority of y- and w- stems are underlyingly gh- stem; true y- and w- stems are the exception and should be listed separately.

local devoicing = { ["z"] = "s",  ["gh"] = "h", ["zh"] = "sh", ["l"] = "ł", ["w"] = "h", ["y"] = "h"}

local surds = {"s","sh","h"}

function is_vowel(char) v1, v2 = find(char, vow_re) return v1 ~= nil and v2 ~= nil end

function starts_vowel(pref) return is_vowel(at(pref,1)) end

function starts_cons(pref) return is_cons(at(pref,1)) end

function split_pref(pref) if last(pref, 2) == "sh" then return first(pref,2), "sh" end

final = last(pref, 1) if final == "h" or final =="d" then return first(pref,1), final end

return pref, "" end

function apply_high_tone(pref) c1, c2 = find(pref, cons_re) v1, v2 = find(pref, vow_re) pc = c2 and sub(pref, c1, c2) or "" pv = sub(pref, v1, v2) if pv =="i" then pv = "í" elseif pv =="o" then pv = "ó" end return pc.. pv end

-- MAIN FUNCTION

function proc(da, obj, subj, pref) disj = disj_ conj = conj_ p, pf = split_pref(pref) cl, c, v, f = cl_, c_, v_, f_

-- transitive verbs obj  = (obj_ ~= "y") and obj_ or obj

-- conversions obj = (obj == "a") and "ʼ" or obj obj = (obj == "y") and "i" or obj cl  = (cl_ == "∅") and "" or cl

-- PARADIGM ADJUSTMENTS

-- ni/ni 3sg resolution if p == "#" then p = "" if conj ~= "" then p = "ee" elseif obj ~= "" then obj = apply_high_tone(obj) elseif subj ~= "" then subj = apply_high_tone(subj) elseif da ~= "" then elseif disj ~= "" then else p = "yí" end end

-- conjunct + paradigm adjustment if last(conj, 1) == "i" then if p ~= "" then conj = first(conj, 1) p = (p..pf=="ni") and "í" or p     end end

-- ú transformation if obj..subj..conj ~= "" then p= subst(p, "ú", "í") else p= subst(p, "ú", "") end

--if c then -- return disj.. da..obj..subj..conj.. p..pf..c..v..f  --return mw.title.getCurrentTitle.subpageText --end

-- PERSON-CLASSIFIER-STEM ADJUSTMENTS

-- 1-dual d-effect if pf == "d" then pf = "" if cl=="ł" or cl=="l" then cl = "l" else cl = "" c = d_effect[c] or c      end

-- classifier d-effect elseif cl == "d" then cl = "" c = d_effect[c] or c

-- devoicing from ł-classifier elseif cl == "ł" then c = devoicing[c] or c     if c == "s" or c == "sh" then cl = "" end

-- devoicing from 1sg and 2dl elseif is_in(pf, surds) then if cl == "" then c = devoicing[c] or c     elseif cl == "l" then cl = "ł" end end -- sandwich rule if pf == "sh" and (cl == "ł" or cl == "l") then cl = "" end

-- h-deletion if pf=="h" and cl == "ł" then pf = "" end

-- assibilation if pf == "sh" and (is_in(c,hiss) or is_in(f,hiss)) then pf = "s" elseif pf == "s" and ( is_in(c,hush) or is_in(f,hush) ) then pf = "sh" end

-- CONJUNCT ADJUSTMENTS

-- i --> y in front of vowels -- and doubling rule if obj == "i" then if p == "ii" and disj..da=="" then p = "yii" elseif starts_vowel(p) then obj = "y" end end

-- ho   if obj == "ho" then if subj..conj == "" then if p == ""  then obj = "ha" elseif p..pf =="ni" then obj, p = "hó", "" elseif p == "ii" then obj = "hw" elseif at(p,1) == "o" then obj = "h" end end end

-- 4-sg adjustment if subj == "ji" then if starts_vowel(conj..p..pf..cl) then subj = "j" elseif disj..da..obj ~= ""  and conj..p      ~= ""   then subj = "zh" end end

-- unspec obj if obj == "ʼ" then if subj..conj == "" then if p == ""  then p = "a" elseif p..pf =="ni" then p = "í" end end

-- if starts word without a vowel if disj..da == "" and not is_vowel(at(subj..conj..p..pf, 1)) then obj = "ʼa" end end

-- unspec hop if obj == "ʼ" and subj == "zh" then obj, subj = subj, obj end

-- DISJUNCT ADJUSTMENTS

-- na —> ni   if disj_ == "na" and is_in(at(da..obj..subj..conj..p,1), {"j", "d", "s", "sh" }) then disj ="ni" end

--  disj = disj..da   -- a-away --[[

One of the trickiest part of code. This prefix is best represented as    an underlying ʼi prefix.

Without unspec object: --->    D  O  P   PF |  D  O  P  PF     --+--+ 1s. ʼi -  -   sh | ʼi  -  i   sh 2s. ʼi -  ni  -  | ʼa  -  ni  - 3s. ʼi -  -   -  | ʼi  -  i   - 3o. ʼi i  -   -  | ʼi  i  i   - 4s. ʼi ji -   -  | ʼa  ji -   - 1d. ʼi -  ii  d  | ʼi  -  ii  d 2d. ʼi -  o   h  | ʼo  -  o   h     ʼi  -  oo  h  | ʼo  -  oo  h

+ simplification iii --> ii, ooo --> oo

With unspec object (after application of unspec rule above): --->    D  O  P   PF |  D  O  P  PF     --+--+ 1s. ʼi ʼ  a   sh | ʼe  ʼ  e   sh 2s. ʼi ʼ  í   -  | ʼi  ʼ  í   - 3s. ʼi ʼ  a   -  | ʼe  ʼ  e   - 1d. ʼi ʼ  ii  d  | ʼi  ʼ  ii  d 2d. ʼi ʼ  o   h  | ʼo  ʼ  o   h

]]

if disj == "a" then

-- change underlying representation disj = "ʼi"

-- with unspec object if obj == "ʼ" then if p == "a" then disj, p = "ʼe", "e" elseif at(p,1) == "o" then disj = "ʼo" end

-- without unspec object elseif subj..conj == "" then if p == ""  then p = "i" elseif p == "oo" then disj = "ʼ" elseif p == "o" then disj = "ʼo" elseif p == "ni" then disj = "ʼa" end else disj = "ʼa" end end

-- pre-stem í —> é if last(disj, 1) == "í" and obj..subj..conj..p == "" then disj = first(disj, 1).."é" end -- pre-stem a —> aa  if at(disj,-1) == "a" and obj..subj..conj..p == "" then p = "a" end

-- disj high tone spreading if is_in( at(disj, -1), {"á", "é", "í","ó"} ) then if obj ~= "" then obj = apply_high_tone(obj) elseif subj ~= "" then subj = apply_high_tone(subj) elseif conj ~= "" then conj = apply_high_tone(conj) elseif p ~= "" then p = apply_high_tone(p) end end

-- Ca + i = Cei if at(disj, -1) == "a" and at(disj, -2) ~= "h" then next = at(obj.. subj.. conj..p, 1) if next == "i" or next == "í" then disj = first(disj, 1).."e" end end

-- ORTHOGRAPHIC ADJUSTMENTS

if cl == "" then -- simplification of geminate if pf == c and c ~= "h" then pf = "" -- rewriting of "h" as "x" elseif pf == "s" and c == "h" then c = "x" end end -- peg rule prestem = disj..obj..subj..conj..p  if prestem == "" then prestem = "yi" elseif at(prestem,1) == "i" or at(prestem,1) == "í" then prestem = "y".. prestem elseif at(prestem,1) == "o" or at(prestem,1) == "ó" then prestem = "w".. prestem end

-- remove initial glottal stop if at(prestem,1) == "ʼ" then prestem = sub(prestem,2) end

-- triple-vowel simplification prestem = subst(prestem, "iii", "ii") prestem = subst(prestem, "ooo", "oo")

return prestem..pf..cl..c..v..f

end

--################################## function highlight(form1,form2) form2 = mw.title.getCurrentTitle.subpageText

if form1 ~= form2 then return "" .. form1 .. "" else return "'''" .. form1 .. "'''"   end end

function make_table(mode, data)

local text =' {|style="margin-bottom:.1em; margin-right:1em;width:50em; border:1px solid #AAAAAA; border-collapse:collapse;" cellpadding="4" rules="all"\n'

text = text .. '!WIDTH="98" style="background-color:#EFEAAA;text-align:left;font-size:90%;"|' .. mode..'\n!WIDTH="162" style="background-color:#EFEFFF;text-align:center;font-size:90%;"|singular\n!WIDTH="162" style="background-color:#EFEFFF;text-align:center;font-size:90%;"|duoplural\n!WIDTH="162" style="background-color:#EFEFFF;text-align:center;font-size:90%;"|plural\n'

text = text..'|-\n' text = text.. '!style="background-color:#EFEFFF;text-align:left;font-size:90%;"|1st person\n' text = text.. '|style="text-align:center;"|' .. highlight(data.form_1sg)..' \n' text = text.. '|style="text-align:center;"|' .. highlight(data.form_1dl)..' \n' text = text..'|style="text-align:center;"|' .. highlight(data.form_1pl)..'\n' text = text..'|-\n' text = text.. '!style="background-color:#EFEFFF;text-align:left;font-size:90%;"|2nd person\n' text = text.. '|style="text-align:center;"|' .. highlight(data.form_2sg)..' \n' text = text.. '|style="text-align:center;"|' .. highlight(data.form_2dl)..'\n' text = text.. '|style="text-align:center;"|' .. highlight(data.form_2pl)..'\n' text = text..'|-\n' text = text.. '!style="background-color:#EFEFFF;text-align:left;font-size:90%;"|3rd person\n' text = text.. '|style="text-align:center;" colspan=2|' .. highlight(data.form_3sg)..' \n' text = text.. '|style="text-align:center;"|' .. highlight(data.form_3pl)..'\n' text = text..'|-\n' text = text.. '!style="background-color:#EFEFFF;text-align:left;font-size:90%;"|4th person\n' text = text.. '|style="text-align:center;" colspan=2|' .. highlight(data.form_4sg)..' \n' text = text..'|style="text-align:center;"|' .. highlight(data.form_4pl)..'\n' text=text.. '|}'   return text end

function make_string(data) return data.form_1sg.. " ".. data.form_1dl.. " "..data.form_1pl .. " "..data.form_2sg.. " ".. data.form_2dl.." "..data.form_2pl.. " ".. data.form_3sg.. " ".. data.form_3pl.. " "..data.form_4sg.. " "..data.form_4pl end

return p