Implements {{ka-infl-noun}}
.
local export = {}
local lang = require("Module:languages").getByCode("ka")
local m_links = require("Module:links")
local strutils = require("Module:string utilities")
local declensionTable = require("Module:ka-infl-noun/declension table")
local postpositionTable = require("Module:ka-infl-noun/postposition table")
--unicode charAt
function uCharAt(str, index)
return mw.ustring.sub(str, 1, 1)
end
-- to know what savrtsobi means better see this ]
local function savrtsobi(s)
dat = uCharAt(s, 1)
gen = uCharAt(s, 2)
ins = uCharAt(s, 3)
adv = uCharAt(s, 4)
return {
= dat ~= "-" and "("..dat..")" or "",
= gen ~= "-" and "("..gen..")" or "",
= ins ~= "-" and "("..ins..")" or "",
= adv ~= "-" and "("..adv..")" or "",
}
end
rules = {}
rules = {
= "ი",
= "მა",
= "ს",
= "ის",
= "ით",
= "ად",
= "ო",
}
rules = {
= "ი",
= "მა",
= "ს",
= "ის",
= "ით",
= "ად",
= "",
}
rules = {
= "",
= "მ",
= "ს",
= "ს",
= "თ",
= "დ",
= "",
}
rules = {
= "",
= "მ",
= "ს",
= "ის",
= "ით",
= "დ",
= "ვ",
}
rules = {
= "",
= "მ",
= "ს",
= "ს",
= "თ",
= "დ",
= "",
}
rules = rules
rules = {
= "",
= "მ",
= "ს",
= "ს",
= "თ",
= "დ",
= "ვ",
}
rules = rules
local modernPluralRule = {
= "ი",
= "მა",
= "ს",
= "ის",
= "ით",
= "ად",
= "ო",
}
local archaicPluralRule = {
= "ნი",
= "თ",
= "თ",
= "თ",
--
--
= "ნო",
}
function init()
forms = {}
postpositions = {}
definers = {}
word = nil
genstem = nil
term = nil
noplural = false
givenname = false
noarchaic = false
nosingular = false
wordType = nil
DEFINERS = {}
terms = nil
--
STEM_SG = nil
STEM_SG_ADV = nil
STEM_SG_GEN_INST = nil
STEM_PL = nil
RULE = nil
SAVRTSOBI = nil
NOSINGULAR = nil
NOPLURAL = nil
NOARCHAIC = nil
end
function export.getForms(args)
main(args, 1)
local combined = {}
for k, v in pairs(forms) do
combined = mw.ustring.gsub(v, "]", "")
end
for k, v in pairs(postpositions) do
combined = mw.ustring.gsub(v, "]", "")
end
return combined
end
--function export.test(args, form)
-- main(args, 1)
-- return mw.ustring.gsub(forms, "]", "")
--end
function export.show(frame)
if mw.text.split(mw.title.getCurrentTitle().prefixedText, ":") == "Template" then return "" end
local args = frame:getParent().args
main(args, 0)
return strutils.format(declensionTable.template, forms) .. "\n" .. strutils.format(mw.getCurrentFrame():preprocess(postpositionTable.template), postpositions)
end
function main(args)
init()
term = args.term or mw.title.getCurrentTitle().text --'term' arg is for debug and testing purposes
terms = mw.text.split(term, " ")
if #terms == 1 then
word = term
else
word = terms
table.remove(terms, #terms)
definers = terms
end
local i = 1
if args ~= nil and (args == "" or mw.ustring.find(args, "") ~= nil) then
genstem = args
if genstem == "" then genstem = word end
i = i + 1
end
local params = {}
params = false
params = false
params = false
params = false
local newarg = args
while newarg ~= nil do
if newarg == "-" then newarg = "noplural" end
params = true
newarg = args
i = i + 1
end
noplural = params
givenname = params
noarchaic = params
nosingular = params
analyze()
deriveDefiners()
fillTable()
--postpositions. this has to happen before making links because it depends on square ] brackets
fillPostpositions()
override(args)
makelinks()
forms = ""
end
function analyze()
--initializing defaults for all endings
if nosingular then NOSINGULAR = "" end
if noplural or givenname then NOPLURAL = "" end
if noarchaic then NOARCHAIC = "" end
SAVRTSOBI = savrtsobi("აააა")
--end defaultization xD
local lastLetter = mw.ustring.sub(word, -1)
if lastLetter == "ი" then
STEM_SG = mw.ustring.sub(word, 0, -2)
STEM_SG_GEN_INST = genstem or STEM_SG
STEM_SG_ADV = genstem or STEM_SG
STEM_PL = genstem or STEM_SG
wordType = "კაცი"
if givenname then
SAVRTSOBI = savrtsobi("-აა-")
end
if genstem ~= nil then
if #genstem == #word then
STEM_SG = genstem
wordType = "ჩაი"
if not givenname then
STEM_PL = mw.ustring.sub(word, 0, -2); --rules : "ტრამვაი"
end
end
else
if givenname then
wordType = "დავითი"
end
end
elseif lastLetter == "ა" then
STEM_SG = word
STEM_SG_GEN_INST = mw.ustring.sub(word, 0, -2)
STEM_SG_ADV = word
STEM_PL = mw.ustring.sub(word, 0, -2)
wordType = "მთა"
if givenname then
STEM_SG_GEN_INST = word
wordType = "ანა"
SAVRTSOBI = savrtsobi("-იი-")
elseif genstem ~= nil then
STEM_SG_GEN_INST = genstem
wordType = "ხბო"
if #genstem ~= #word then
STEM_SG_ADV = genstem .. "ა"
STEM_PL = genstem
wordType = "მთა"
else
SAVRTSOBI = savrtsobi("აიია")
end
end
elseif lastLetter == "ე" then
STEM_SG = word
STEM_SG_GEN_INST = mw.ustring.sub(word, 0, -2)
STEM_SG_ADV = word
STEM_PL = word
wordType = "მთა"
if givenname then
SAVRTSOBI = savrtsobi("-იი-")
STEM_SG_GEN_INST = word
wordType = "ანა"
end
if genstem ~= nil then
STEM_SG_GEN_INST = genstem
STEM_PL = genstem
wordType = "ხბო"
if #genstem ~= #word then
STEM_SG_ADV = genstem.."ა"
wordType = "მთა"
SAVRTSOBI = savrtsobi("აიია")
end
end
elseif lastLetter == "ო" or lastLetter == "უ" then
STEM_SG = word
STEM_SG_GEN_INST = word
STEM_SG_ADV = word
STEM_PL = word
SAVRTSOBI = savrtsobi("აიია")
if givenname then
SAVRTSOBI = savrtsobi("-იი-")
end
wordType = "ხბო"
if givenname then
wordType = "დოდო"
end
end
RULE = rules
end
function fillTable()
forms = term
forms = NOSINGULAR or " .. STEM_SG .. RULE .. "]]"
forms = NOSINGULAR or " .. STEM_SG .. RULE .. "]]"
forms = NOSINGULAR or " .. STEM_SG .. RULE .. "]]" .. SAVRTSOBI
forms = NOSINGULAR or " .. STEM_SG_GEN_INST .. RULE .. "]]" .. SAVRTSOBI
forms = NOSINGULAR or " .. STEM_SG_GEN_INST .. RULE .. "]]" .. SAVRTSOBI
forms = NOSINGULAR or " .. STEM_SG_ADV .. RULE .. "]]" .. SAVRTSOBI
forms = NOSINGULAR or " .. STEM_SG .. RULE .. "]]"
forms = NOPLURAL or " .. STEM_PL .. "ებ" .. modernPluralRule .. "]]"
forms = NOPLURAL or " .. STEM_PL .. "ებ" .. modernPluralRule .. "]]"
forms = NOPLURAL or " .. STEM_PL .. "ებ" .. modernPluralRule .. "]](ა)"
forms = NOPLURAL or " .. STEM_PL .. "ებ" .. modernPluralRule .. "]](ა)"
forms = NOPLURAL or " .. STEM_PL .. "ებ" .. modernPluralRule .. "]](ა)"
forms = NOPLURAL or " .. STEM_PL .. "ებ" .. modernPluralRule .. "]](ა)"
forms = NOPLURAL or " .. STEM_PL .. "ებ" .. modernPluralRule .. "]]"
forms = NOPLURAL or NOARCHAIC or " .. STEM_SG .. archaicPluralRule .. "]]"
forms = NOPLURAL or NOARCHAIC or " .. STEM_SG .. archaicPluralRule .. "]](ა)"
forms = NOPLURAL or NOARCHAIC or " .. STEM_SG .. archaicPluralRule .. "]](ა)"
forms = NOPLURAL or NOARCHAIC or " .. STEM_SG .. archaicPluralRule .. "]](ა)"
--forms
--forms
forms = NOPLURAL or NOARCHAIC or " .. STEM_SG .. archaicPluralRule .. "]]"
end
function deriveDefiners()
local marker = {
= "ი",
= "მა",
= "",
= "ი",
= "ი",
= "",
= "ო",
= "ი",
= "",
= "",
= "",
= "ნო",
}
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
DEFINERS = ""
for index, definer in pairs(definers) do
local trimLast = mw.ustring.sub(definer, 0, -2);
local lastLetter = mw.ustring.sub(definer, -1)
for case, val in pairs(DEFINERS) do
DEFINERS = DEFINERS .. trimLast .. (lastLetter == "ი" and marker or lastLetter) .. " "
end
--DEFINERS = DEFINERS .. " " .. trimLast + (lastLetter == "ი" and marker or lastLetter)
end
end
function override(args)
for case, text in pairs(forms) do --WARNING: NOTE, etc.
forms = mw.ustring.gsub(args or "+", "+", forms)
end
for case, text in pairs(postpositions) do --WARNING: NOTE, etc.
postpositions = mw.ustring.gsub(args or "+", "+", postpositions)
end
end
function makelinks()
for case, text in pairs(forms) do --WARNING: NOTE, etc.
forms = mw.ustring.gsub( text, "%%](%(%))", function (captured, sav) -- hyphen is 0 or more non greedy
return m_links.full_link({lang = lang, term = captured, alt = captured .. sav}) end)
forms = mw.ustring.gsub( forms, "%-%]%]", function (captured)
return m_links.full_link({lang = lang, term = captured}) end)
end
for postposition, text in pairs(postpositions) do --WARNING: NOTE, etc.
postpositions = mw.ustring.gsub( text, "%%]", function (captured) -- hyphen is 0 or more non greedy
return m_links.full_link({lang = lang, term = captured}) end)
end
end
--<number of letters to truncate>, <letters to add>
--plurals are OK.
postpRules = {}
postpRules = {
= {"dat", 1, "ივით"},
= {"dat", 1, "ზე"},
= {"dat", 1, "თან"},
= {"dat", 1, "ში"},
= {"gen", 0, "თვის"},
= {"gen", 0, "ებრ"},
= {"gen", 0, "კენ"},
= {"gen", 0, "გან"},
= {"ins", 1, "დან"},
= {"ins", 0, "ურთ"},
= {"adv", 1, "მდე"}
}
postpRules = {
= {"dat", 1, "ივით"},
= {"dat", 1, "ზე"},
= {"dat", 1, "თან"},
= {"dat", 1, "ში"},
= {"gen", 0, "თვის"},
= {"gen", 0, "ებრ"},
= {"gen", 0, "კენ"},
= {"gen", 0, "გან"},
= {"ins", 1, "დან"},
= {"ins", 0, "-"},
= {"adv", 1, "მდე"}
}
postpRules = {
= {"dat", 1, "ვით"},
= {"dat", 1, "ზე"},
= {"dat", 0, "თან"},
= {"dat", 1, "ში"},
= {"gen", 0, "თვის"},
= {"gen", 0, "ებრ"},
= {"gen", 0, "კენ"},
= {"gen", 0, "გან"},
= {"ins", 1, "დან"},
= {"ins", 0, "ურთ"},
= {"adv", 1, "მდე"}
}
postpRules = {
= {"dat", 0, "ავით"},
= {"dat", 1, "ზე"},
= {"dat", 0, "თან"},
= {"dat", 1, "ში"},
= {"gen", 0, "თვის"},
= {"gen", 0, "ებრ"},
= {"gen", 0, "კენ"},
= {"gen", 0, "გან"},
= {"ins", 1, "დან"},
= {"ins", 0, "ურთ"},
= {"adv", 1, "მდე"}
}
postpRules = {
= {"dat", 0, "ავით"},
= {"dat", 1, "ზე"},
= {"dat", 0, "თან"},
= {"dat", 1, "ში"},
= {"gen", 0, "თვის"},
= {"gen", 0, "ებრ"},
= {"gen", 0, "კენ"},
= {"gen", 0, "გან"},
= {"ins", 1, "დან"},
= {"ins", 0, "-"},
= {"adv", 1, "მდე"}
}
postpRules = postpRules
postpRules = postpRules
postpRules = postpRules
postpRules = postpRules
function fillPostpositions()
postpositions = term
local postpRule = postpRules
local postpRule_pl = postpRules
for postSuffix, postGrammar in pairs(postpRule) do
local case = postGrammar;
local pattern = string.rep(".", postGrammar) .. "%]%]";
if case == "dat" or case == "gen" or case == "ins" or case == "adv" then
pattern = pattern .. "%(??%)?"
end
local res = mw.ustring.gsub(forms, pattern, postGrammar.."]]")
if postGrammar == "-" then res = "-" end
postpositions = res
end
for postSuffix, postGrammar in pairs(postpRule_pl) do
local case = postGrammar;
local pattern = string.rep(".", postGrammar) .. "%]%]";
if case == "dat" or case == "gen" or case == "ins" or case == "adv" then
pattern = pattern .. "%(??%)?"
end
local res = mw.ustring.gsub(forms, pattern, postGrammar.."]]")
if postGrammar == "-" then res = "-" end
postpositions = res
end
end
return export