--[[
WORK IN PROGRESS
]]--
local export = {}
local getArgs = require('Module:Arguments').getArgs
local m_IPA = require("Module:rad-IPA")
local m_links = require("Module:links")
local m_languages = require("Module:languages")
local m_parameters = require("Module:parameters")
local V = "aáàâảeéèiíìỉoóòøuúùûūủyýỳỷ"
local C = "bcdðfghħjĵkķlmnņpqrsștvwxzþ"
local O = "bcdðfghħkķpqsștvxzþ"
local O_voiced = "bdðgħvxz"
local O_unvoiced = "cfhkķpqsștþ"
local N = "mnņ"
local L = "lr"
local R = L .. N
local J = "jĵw"
stem_data = {
-- heavy stems --
['ab'] = 'C', ['av'] = 'C', ['b'] = 'C', ['c'] = 'C', ['Cf'] = 'C', ['Cm'] = 'C', ['Cn'] = 'C', ['Cņ'] = 'C', ['Cv'] = 'C', ['Cþ'] = 'C', ['d'] = 'C', ['ð'] = 'C', ['dz'] = 'C', ['eb'] = 'C', ['ev'] = 'C', ['f'] = 'C', ['g'] = 'C', ['ib'] = 'C', ['íb'] = 'C', ['ir'] = 'C', ['iv'] = 'C', ['ív'] = 'C', ['j'] = 'C', ['jð'] = 'C', ['jþ'] = 'C', ['k'] = 'C', ['l'] = 'C', ['lb'] = 'C', ['m'] = 'C', ['mb'] = 'C', ['n'] = 'C', ['ņ'] = 'C', ['ob'] = 'C', ['p'] = 'C', ['r'] = 'C', ['rb'] = 'C', ['s'] = 'C', ['ș'] = 'C', ['t'] = 'C', ['ub'] = 'C', ['uv'] = 'C', ['v'] = 'C', ['x'] = 'C', ['z'] = 'C', ['þ'] = 'C', ['st'] = 'C', ['șt'] = 'C', ['zd'] = 'C', ['xd'] = 'C',
-- heavy spirants --
['abH'] = 'CH', ['avH'] = 'CH', ['bH'] = 'CH', ['cH'] = 'CH', ['CmḤ'] = 'CH', ['CnḤ'] = 'CH', ['CņḤ'] = 'CH', ['CvH'] = 'CH', ['dH'] = 'CH', ['ðH'] = 'CH', ['dzH'] = 'CH', ['ebH'] = 'CH', ['evH'] = 'CH', ['fH'] = 'CH', ['gH'] = 'CH', ['ibH'] = 'CH', ['íbH'] = 'CH', ['ivH'] = 'CH', ['ívH'] = 'CH', ['jðH'] = 'CH', ['jH'] = 'CH', ['jþH'] = 'CH', ['kH'] = 'CH', ['lbH'] = 'CH', ['lḤ'] = 'CH', ['mbH'] = 'CH', ['mḤ'] = 'CH', ['nḤ'] = 'CH', ['ņḤ'] = 'CH', ['pH'] = 'CH', ['rbH'] = 'CH', ['rḤ'] = 'CH', ['sH'] = 'CH', ['șH'] = 'CH', ['tH'] = 'CH', ['vH'] = 'CH', ['xH'] = 'CH', ['zH'] = 'CH', ['þH'] = 'CH', ['stH'] = 'CH', ['ștH'] = 'CH', ['zdH'] = 'CH', ['xdH'] = 'CH',
-- semi-light --
['aG'] = 'G', ['eG'] = 'G', ['G'] = 'G', ['G̣'] = 'G', ['ieG'] = 'G', ['iG'] = 'G', ['oG'] = 'G', ['øG'] = 'G', ['rG̣'] = 'G', ['uG'] = 'G', ['yG'] = 'G',
-- light --
['a^e'] = 'V', ['a^o'] = 'V', ['ai'] = 'V', ['aijo'] = 'V', ['au'] = 'V', ['C^V'] = 'V', ['Cvo'] = 'V', ['Cvu'] = 'V', ['e'] = 'V', ['i'] = 'V', ['ie'] = 'V', ['io'] = 'V', ['Je'] = 'V', ['Ji'] = 'V', ['nj^e'] = 'V', ['o'] = 'V', ['ø'] = 'V', ['oe'] = 'V', ['ove'] = 'V', ['t^o'] = 'V', ['u'] = 'V', ['uve'] = 'V', ['Vj'] = 'V', ['y'] = 'V',
-- light spirant --
['a^eH'] = 'VH', ['a^oH'] = 'VH', ['aH'] = 'VH', ['aHH'] = 'VH', ['áHH'] = 'VH', ['âHH'] = 'VH', ['aòH'] = 'VH', ['eH'] = 'VH', ['H'] = 'VH', ['Ḥ'] = 'VH', ['HH'] = 'VH', ['ḤḤ'] = 'VH', ['ieH'] = 'VH', ['ieHH'] = 'VH', ['iH'] = 'VH', ['iḤ'] = 'VH', ['íH'] = 'VH', ['íḤ'] = 'VH', ['iHH'] = 'VH', ['oH'] = 'VH', ['øH'] = 'VH', ['uH'] = 'VH', ['yH'] = 'VH', ['ýH'] = 'VH', ['ýḤ'] = 'VH', ['yHH'] = 'VH',
}
pos_data = { "noun", "verb" }
function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end
-- 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 phantom consonants --
-- resolve =g
resolve("([pf]%=g)","f")
resolve("(b%=g)","vg")
resolve("(j[ctþ]%=g)","șk")
resolve("([sș]?[șķ]%=g)","șk")
resolve("([șk]?[cstþ]%=g)","sk")
resolve("(s?[cstþ]%=g)","sk")
resolve("(v%=g)","vu")
-- resolve =s
resolve("([" .. C .. "])%=s","%1=s")
-- resolve vowels
resolve("([^eo]av%=)","au")
resolve("([^a]uv%=)","ú")
resolve("([^au]ov%=)","ú")
resolve("([^i]ev%=)","ø")
resolve("([^i]v%=)","ø")
-- resolve abbreviations
return resolution
end
function getNounStem(args) -- rad-inflection|pos|principle_part| 3 | 4 | 5
local principle_parts = {
["nom"] = "",
["gen"] = "",
["dat"] = "",
["acc"] = "",
["ins"] = "",
["nompl"] = "",
["genpl"] = "",
["genpl_short"] = "",
}
local stem = ""
local stem_broken = ""
local stem_raised = ""
local ending = ""
-- create stem and ending parameters --
mw.log("Parameters:")
if stem_data[args[5]] == 'C' or stem_data[args[5]] or stem_data[args[6]] == 'C' or stem_data[args[6]] == 'CH' then
if mw.ustring.find(args[4], "([%^%~])") then
if mw.ustring.find(args[4], "([%^])") then
stem = mw.ustring.match(args[4], "([^%^]+)%^") or ""
stem_raised = mw.ustring.match(args[4], "%^([^%^]+)")
else
stem = args[4]
stem_raised = args[4]
end
if mw.ustring.find(stem, "([%~])") then
stem_broken = mw.ustring.match(stem, "%~([^%~%^]+)")
stem = mw.ustring.match(stem, "([^%~]+)%~")
if stem_raised == args[4] then
stem_raised = stem_broken
end
else
stem_broken = stem
end
else
error("The third parameter should contain a raised V^V or broken V~V stem.")
end
stem = args[3] .. stem .. args[5]
stem_broken = args[3] .. stem_broken .. args[5]
stem_raised = args[3] .. stem_raised .. args[5]
if args[6]~= nil then
stem = stem .. args[6]
stem_broken = stem_broken .. args[6]
stem_raised = stem_raised .. args[6]
ending = args[6]
else
ending = args[5]
end
elseif stem_data[args[4]] then
stem = args[3] .. args[4]
ending = args[4]
stem_broken = nil
stem_raised = nil
else
error("Invalid format: Please format the arguments as hv|o~u^u|þ, dv|a^u|n|þ, he|rḤ or lorál|eH")
end
mw.log("Stem: " .. stem)
if stem_broken then mw.log("Broken stem: " .. stem_broken ) end
if stem_raised then mw.log("Raised stem: " .. stem_raised ) end
mw.log("Ending: " .. ending)
-- generate endings from declension type --
if stem_data[ending] == 'C' or stem_data[ending] == 'CH' then -- heavy stems
principle_parts["nom"] = stem_broken .. "=s"
principle_parts["gen"] = stem_raised .. "=g"
principle_parts["dat"] = stem .. "=a"
principle_parts["acc"] = stem_broken .. "=d"
principle_parts["ins"] = stem .. "=úr"
principle_parts["nompl"] = stem_broken .. "=e"
principle_parts["genpl"] = stem .. "=i"
principle_parts["genpl_short"] = principle_parts["genpl"]
end
mw.log("——— Resolving ———")
for part, infl in pairs(principle_parts) do
principle_parts[part] = resolve_ending(infl)
end
mw.logObject(principle_parts)
return principle_parts
end
function getVerbStem(args)
end
function export.getStem(frame)
local args = getArgs(frame)
local word = mw.title.getCurrentTitle().subpageText
local to_Return = ""
if args[1] ~= nil and 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
mw.logObject(getNounStem(args))
to_Return = getNounStem(args)[args[2]]
elseif args[1] == "verb" then
mw.logObject(getVerbStem(args))
to_Return = 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", "þ"}})
]]