local lang = require("Module:languages").getByCode("pbg")
local rfind = mw.ustring.find
local rsplit = mw.text.split
local export = {}
local function rsub(term, foo, bar)
local retval = mw.ustring.gsub(term, foo, bar)
return retval
end
-- apply rsub() repeatedly until no change
local function rsub_repeatedly(term, foo, bar)
while true do
local new_term = rsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
local function postprocess(args, data)
data.lemma = data.forms
-- Check if the lemma form matches the page name
if (lang:makeEntryName(data.lemma)) ~= mw.title.getCurrentTitle().text then
table.insert(data.categories, lang:getCanonicalName() .. " entries with inflection not matching pagename")
end
end
-- Table-generating functions
local function make_table(data)
local function repl(param)
local no_store = false
if param == "info" then
return mw.getContentLanguage():ucfirst(data.info or "")
end
local forms = data.forms
if not forms then
return "—"
end
local ret = {}
for key, subform in ipairs(forms) do
table.insert(ret, require("Module:links").full_link({lang = lang, term = subform}))
end
return table.concat(ret, "<br/>")
end
local wikicode = mw.getCurrentFrame():expandTemplate{
title = 'inflection-table-top',
args = {
title = '{{{info}}}',
tall = 'yes',
palette = 'green'
}
}
wikicode = wikicode .. [=[
! colspan = "11" class = "outer"|Subjective construction
|-
!
! <abbr title="also known as present-past">current</abbr>
! <abbr title="also known as simple future">non-current</abbr>
! immediate past
! simultaneous present
! past perfect
! future intentional
! future immediate
|-
! masculine
| {{{smcurr}}}
| {{{smncur}}}
| {{{smimpa}}}
| {{{smsipa}}}
| {{{smpape}}}
| {{{smfuin}}}
| {{{smfuim}}}
|-
! feminine
| {{{sfcurr}}}
| {{{sfncur}}}
| {{{sfimpa}}}
| {{{sfsipa}}}
| {{{sfpape}}}
| {{{sffuin}}}
| {{{sffuim}}}
|-
! plural
| {{{spcurr}}}
| {{{spncur}}}
| {{{spimpa}}}
| {{{spsipa}}}
| {{{sppape}}}
| {{{spfuin}}}
| {{{spfuim}}}
]=]
--wikicode = wikicode .. mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-bottom', args = {notes =
--"<small>1. Preceded by the adverb ''{{{janiwa}}}''.<br/>2. Preceded by the adverb ''{{{janiti}}}''.<br/>3. Preceded by the adverb ''{{{janiya}}}''. <br/>This table is not exhaustive.</small>"} }
return mw.ustring.gsub(wikicode, "{{{?(+)}}}", repl) .. require("Module:utilities").format_categories(data.categories, lang)
end --normal table
-- Inflection functions (common nouns)
function export.show(frame)
local args = frame:getParent().args
local data = {
forms = {},
categories = {},
= {},
}
local ending_text = 0
-- add the lemma form
local base = args.pagename or mw.title.getCurrentTitle().text
--find the conjugation
local conjugation
local c
local root
if rfind(base, "aa$") then
conjugation = "second"
root = rsub(base, "aa$", "")
c = 2
elseif rfind(base, "a$") then
conjugation = "first"
root = rsub(base, "a$", "")
c = 1
end
if not conjugation then error("Verbs must end in -a, -aa") end
--add the forms
local suffixes = {
{ --first conjugation
curr = {m = "i", f = "ü", p = "in"},
ncur = {m = "eechi", f = "eerü", p = "eenü"},
impa = {m = "ichi", f = "irü", p = "inü"},
sipa = {m = "üi", f = "ürü", p = "inü"},
pape = {m = "atüi", f = "atürü", p = "atünü"},
fuin = {m = "iyachi", f = "iyatü", p = "iyanü"},
fuim = {m = "iyachichi", f = "iyatirü", p = "iyaninü"},
},
{ --second conjugation
curr = {m = "ei", f = "oü", p = "ein"},
ncur = {m = "eechi", f = "eerü", p = "eenü"},
impa = {m = "eichi", f = "eirü", p = "einü"},
sipa = {m = "oüi", f = "oürü", p = "oünü"},
pape = {m = "aatüi", f = "aatürü", p = "aatünü"},
fuin = {m = "eyachi", f = "eyatü", p = "eyanü"},
fuim = {m = "eyachichi", f = "eyatirü", p = "eyaninü"},
}
}
local this_conj_suf = suffixes
local function generate_form(g, t)
form = root .. this_conj_suf
return form
end
local genders = {"m", "f", "p"}
local tenses = {"curr", "ncur", "impa", "sipa", "pape", "fuin", "fuim"}
for _, g in ipairs(genders) do
for _, t in ipairs(tenses) do
data.forms = {generate_form(g, t)}
end
end
--create the table
data.info = "Conjugation of " .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " (" .. conjugation .. " conjugation)"
return make_table(data)
end
return export