This module serves as the backend for Template:ta-decl.
local export = {}
local m_translit = require("Module:ta-translit")
local m_tamil = require("Module:ta-conj")
local m_string_utilities = require("Module:string utilities")
local agglutinate = m_tamil.agglutinate
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local match = mw.ustring.match
local len = mw.ustring.len
local long_vowels = {
= 'ā',
= 'ī',
= 'ū',
= 'ē',
= 'ō'
}
-- Clone parent’s args while also assigning nil to empty strings.
local function clone_args(frame)
local args = {}
for pname, param in pairs(frame:getParent().args) do
if param == "" then
args = nil
else
args = param
end
end
return args
end
function export.do_generate_forms(args)
local data = {}
local base = args or ""
local PAGENAME = mw.title.getCurrentTitle().text
if base == "" then
base = PAGENAME
end
local type_stem = args.type
data.type_stem = ""
local oblique_sg_base = ""
local plu_base = agglutinate(base, 'கள்', { = true }) --default
local special_vocative = nil
categories = ""
oblique_sg_base = base -- default
if (type_stem == "root" or type_stem == "basic" or type_stem == "none") then
-- do nothing
data.type_stem = "root-stem"
elseif (type_stem == "m" or (type_stem == nil and sub(base, -2) == 'ம்')) then
data.type_stem = "m-stem"
oblique_sg_base = sub(base, 1, -3) .. 'த்து'
plu_base = agglutinate(base, 'கள்') --merge nasals
elseif (type_stem == "i" or (type_stem == nil and sub(base, -1) == 'ி')) then
data.type_stem = "i-stem"
elseif (type_stem == "ai" or (type_stem == nil and sub(base, -1) == 'ை')) then
data.type_stem = "ai-stem"
elseif (type_stem == "y" or (type_stem == nil and sub(base, -2) == 'ய்')) then
data.type_stem = "y-stem"
elseif (type_stem == "ā" or (type_stem == nil and sub(base, -1) == 'ா')) then
data.type_stem = "ā-stem"
plu_base = agglutinate(base, 'க்கள்', {})
elseif (type_stem == "ī" or (type_stem == nil and sub(base, -1) == "ீ")) then
data.type_stem = "ī-stem"
plu_base = agglutinate(base, 'க்கள்', {})
elseif (type_stem == "ṟu" or (type_stem == nil and sub(base, -2) == "று" and sub(base, 3) ~= "ற்று")) then
data.type_stem = "ṟu-stem"
oblique_sg_base = sub(base, 1, -3) .. 'ற்று'
elseif (type_stem == "ṭu" or (type_stem == nil and sub(base, -2) == "டு" and sub(base, 3) ~= "ட்டு")) then
data.type_stem = "ṭu-stem"
oblique_sg_base = sub(base, 1, -3) .. 'ட்டு'
elseif (type_stem == "u" or (type_stem == nil and sub(base, -1) == 'ு')) then
data.type_stem = "u-stem"
elseif (type_stem == "l" or (type_stem == nil and sub(base, -2) == "ல்")) then
data.type_stem = "l-stem"
special_vocative = base .. 'லே'
oblique_sg_base = base .. 'லு'
plu_base = sub(base, 1, -3) .. 'ற்கள்'
elseif (type_stem == "ṉ" or (type_stem == nil and sub(base, -2) == "ன்")) then
data.type_stem = "ṉ-stem"
oblique_sg_base = sub(base, 1, -3) .. 'னு'
plu_base = sub(base, 1, -3) .. "ர்கள்"
elseif (type_stem == "ū" or (type_stem == nil and sub(base, -1) == "ூ")) then
data.type_stem = "ū-stem"
oblique_sg_base = base .. "வு"
plu_base = base .. 'க்கள்'
elseif (type_stem == "ḷ" or (type_stem == nil and sub(base, -2) == "ள்")) then
data.type_stem = "ḷ-stem"
oblique_sg_base = sub(base, 1, -3) .. 'ளு'
plu_base = agglutinate(sub(base, 1, -3), 'ட்கள்', {})
else
data.type_stem = "root-stem"
end
if (data.type_stem ~= "root-stem") then
categories = categories .. "]"
end
if ((args.oblique_sg_base or args) and (args.plu_base or args)) then
oblique_sg_base = args.oblique_sg_base or args
plu_base = args.plu_base or args
end
data.nom_sg = args.nom_s or base
data.voc_sg = args.voc_s or args or special_vocative or
agglutinate(base, "ஏ",
{ = true, = true, = true })
-- mw.log(oblique_sg_base)
data.acc_sg = args.acc_s or
agglutinate(oblique_sg_base, 'ஐ',
{ = true, = true, = true,
= true })
data.dat_sg = args.dat_s or
agglutinate(oblique_sg_base, 'க்கு',
{ = true, = true, = true,
= true })
data.dat_sg_2 = args.ben_s or
agglutinate(oblique_sg_base, 'க்காக',
{ = true, = true, = true,
= true })
if (data.type_stem == "root-stem") then
if not args.dat_s then
data.dat_sg = agglutinate(oblique_sg_base, 'உக்கு',
{ = true, = true, = true,
= true })
end
if not args.ben_s then
data.dat_sg_2 = agglutinate(oblique_sg_base, 'உக்காக',
{ = true, = true, = true,
= true })
end
end
data.gen_sg = args.gen_s or
agglutinate(oblique_sg_base, 'உடைய',
{ = true, = true, = true,
= true })
data.gen_sg_2 = args.gen2_s or
agglutinate(oblique_sg_base, 'இன்',
{ = true, = true, = true,
= true })
data.loc_sg = args.loc_s or
agglutinate(oblique_sg_base, 'இல்',
{ = true, = true, = true,
= true })
data.loc_sg_2 = args.loc2_s or
agglutinate(oblique_sg_base, 'இடம்',
{ = true, = true, = true,
= true })
data.soc_sg = args.soc_s or
agglutinate(oblique_sg_base, 'ஓடு',
{ = true, = true, = true,
= true })
data.soc_sg_2 = args.soc2_s or
agglutinate(oblique_sg_base, 'உடன்',
{ = true, = true, = true,
= true })
data.ins_sg = args.ins_s or
agglutinate(oblique_sg_base, 'ஆல்',
{ = true, = true, = true,
= true })
data.abl_sg = args.abl_s or
agglutinate(oblique_sg_base, 'இலிருந்து',
{ = true, = true, = true,
= true })
data.nom_pl = args.nom_p or plu_base
data.voc_pl = args.voc_p or
agglutinate(plu_base, 'ஏ', { = true, = true })
data.acc_pl = args.acc_p or
agglutinate(plu_base, 'ஐ', { = true, = true })
data.dat_pl = args.dat_p or
agglutinate(plu_base, 'உக்கு', { = true, = true })
data.dat_pl_2 = args.ben_p or
agglutinate(plu_base, 'உக்காக', { = true, = true })
data.gen_pl = args.gen_p or
agglutinate(plu_base, 'உடைய', { = true, = true })
data.gen_pl_2 = args.gen2_p or
agglutinate(plu_base, 'இன்', { = true, = true })
data.loc_pl = args.loc_p or
agglutinate(plu_base, 'இல்', { = true, = true })
data.loc_pl_2 = args.loc2_p or
agglutinate(plu_base, 'இடம்', { = true, = true })
data.soc_pl = args.soc_p or
agglutinate(plu_base, 'ஓடு', { = true, = true })
data.soc_pl_2 = args.soc2_p or
agglutinate(plu_base, 'உடன்', { = true, = true })
data.ins_pl = args.ins_p or
agglutinate(plu_base, 'ஆல்', { = true, = true })
data.abl_pl = args.abl_p or
agglutinate(plu_base, 'இலிருந்து', { = true, = true })
numbers = "both"
if (args.num == "sg") or args == "-" then
numbers = "singular only"
data.nom_pl = "-"
data.voc_pl = "-"
data.acc_pl = "-"
data.dat_pl = "-"
data.dat_pl_2 = "-"
data.gen_pl = "-"
data.gen_pl_2 = "-"
data.loc_pl = "-"
data.loc_pl_2 = "-"
data.soc_pl = "-"
data.soc_pl_2 = "-"
data.ins_pl = "-"
data.abl_pl = "-"
elseif (args.num == "pl") then
numbers = "plural only"
data.nom_sg = args.nom_s or "-"
data.voc_sg = "-"
data.acc_sg = "-"
data.dat_sg = "-"
data.dat_sg_2 = "-"
data.gen_sg = "-"
data.gen_sg_2 = "-"
data.loc_sg = "-"
data.loc_sg_2 = "-"
data.soc_sg = "-"
data.soc_sg_2 = "-"
data.ins_sg = "-"
data.abl_sg = "-"
end
local data_type = data.type_stem
for k, v in pairs(data) do
if type(v) == "table" then
for k1, v1 in pairs(v) do
if (v1 ~= "-") then
data = '<span class="Taml">[[' ..
v1 .. ']]</span> ' .. ' <br/><small style="color: #888">' .. m_translit.tr(v1) .. '</small>'
end
end
else
if (v ~= "-") then
data = '<span class="Taml">[[' ..
v .. ']]</span>' .. ' <br/><small style="color: #888">' .. m_translit.tr(v) .. '</small>'
end
end
end
data.base = base .. ' (' .. m_translit.tr(base) .. ')'
data.type_stem = data_type
data.numbers = numbers
data.categories = categories
return data
end
function export.show(frame)
local args = clone_args(frame)
local data = export.do_generate_forms(args)
if (args.notes) then
if (data.type_stem == "") then
data.type_stem = args.notes
else
data.type_stem = data.type_stem .. ", " .. args.notes
end
end
local header = ""
if (data.type_stem ~= "" and data.type_stem ~= "root-stem") then
header = data.type_stem .. " declension of " .. data.base
else
header = "Declension of " .. data.base
end
if (data.numbers ~= "both") then
header = header .. " " .. "<small>(" .. data.numbers .. ")</small>"
end
local res = {}
local output = frame:expandTemplate {
title = 'inflection-table-top',
args = {
title = header,
palette = 'blue',
tall = 'yes',
class = "tr-alongside"
}
} .. [=[
!
! singular
! plural
|-
! nominative
| {nom_sg}
| {nom_pl}
|-
! vocative
| {voc_sg}
| {voc_pl}
|-
! accusative
| {acc_sg}
| {acc_pl}
|-
! dative
| {dat_sg}
| {dat_pl}
|-
! benefactive
| {dat_sg_2}
| {dat_pl_2}
|-
! genitive 1
| {gen_sg}
| {gen_pl}
|-
! genitive 2
| {gen_sg_2}
| {gen_pl_2}
|-
! locative 1
| {loc_sg}
| {loc_pl}
|-
! locative 2
| {loc_sg_2}
| {loc_pl_2}
|-
! sociative 1
| {soc_sg}
| {soc_pl}
|-
! sociative 2
| {soc_sg_2}
| {soc_pl_2}
|-
! instrumental
| {ins_sg}
| {ins_pl}
|-
! ablative
| {abl_sg}
| {abl_pl}
]=] .. frame:expandTemplate {
title = 'inflection-table-bottom',
}
table.insert(res, m_string_utilities.format(output, data))
if (args.no_categories ~= "true" and mw.title.getCurrentTitle().nsText == "") then
table.insert(res, data.categories)
end
return table.concat(res, "\n")
end
return export