Module:qlu-nouns: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 143: Line 143:
   table.insert(out, '<table class="inflection-table" style="border-collapse:collapse; width:40%; font-size:90%;">')
   table.insert(out, '<table class="inflection-table" style="border-collapse:collapse; width:40%; font-size:90%;">')


   -- Header row
   -- Header row (without thead)
   table.insert(out, "<thead><tr>")
   table.insert(out, "<tr>")
   table.insert(out, cell("", true, "background:#444; color:#fff; padding:4px;"))
   table.insert(out, cell("", true, "background:#444; color:#fff; padding:4px;"))
   table.insert(out, cell("singular", true, "background:#444; color:#fff; padding:4px;"))
   table.insert(out, cell("singular", true, "background:#444; color:#fff; padding:4px;"))
   table.insert(out, cell("plural", true, "background:#444; color:#fff; padding:4px;"))
   table.insert(out, cell("plural", true, "background:#444; color:#fff; padding:4px;"))
   table.insert(out, "</tr></thead>")
   table.insert(out, "</tr>")


   -- Body rows
   -- Body rows (without tbody)
  table.insert(out, "<tbody>")
   for _, row in ipairs(rows) do
   for _, row in ipairs(rows) do
     table.insert(out, "<tr>")
     table.insert(out, "<tr>")
    -- Case name column with light gray background
     table.insert(out, cell(row.label, false, "background:#ddd; padding:4px; font-weight:bold; white-space:nowrap;"))
     table.insert(out, cell(row.label, false, "background:#ddd; padding:4px; font-weight:bold; white-space:nowrap;"))
    -- Singular form
     table.insert(out, cell(row.sg, false, "background:#fff; padding:4px; text-align:center;"))
     table.insert(out, cell(row.sg, false, "background:#fff; padding:4px; text-align:center;"))
    -- Plural form
     table.insert(out, cell(row.pl, false, "background:#fff; padding:4px; text-align:center;"))
     table.insert(out, cell(row.pl, false, "background:#fff; padding:4px; text-align:center;"))
     table.insert(out, "</tr>")
     table.insert(out, "</tr>")
   end
   end
  table.insert(out, "</tbody>")


   table.insert(out, "</table>")
   table.insert(out, "</table>")


  -- Append footnotes if any
   if data.footnotes and data.footnotes ~= "" then
   if data.footnotes and data.footnotes ~= "" then
     table.insert(out, '<div class="footnotes" style="font-size:80%; margin-top:0.5em;">' .. data.footnotes .. "</div>")
     table.insert(out, '<div class="footnotes" style="font-size:80%; margin-top:0.5em;">' .. data.footnotes .. "</div>")
Line 172: Line 166:


   return table.concat(out, "\n")
   return table.concat(out, "\n")
end
-- Main show function: receives root and declension type, outputs full table HTML
function export.show(frame)
  local args = frame.args
  local root = args[1] or error("No root provided.")
  local decltype = args["type"] or error("No declension type provided.")
  local decl = decls[decltype]
  if not decl then
    error("Unknown declension type: " .. decltype)
  end
  local data = { forms = {} }
  decl({ root }, data)
  return export.make_table(data)
end
end


return export
return export

Revision as of 19:29, 29 June 2025

Documentation for this module may be created at Module:qlu-nouns/doc

local Array = require 'Module:array'

local export = {}

-- Declension paradigms for your conlang
local decls = {}

-- a-stem
decls["a"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "a"
  data.forms["nom_pl"] = r .. "e"
  data.forms["gen_sg"] = r .. "e"
  data.forms["gen_pl"] = r .. "aro"
  data.forms["dat_sg"] = r .. "a"
  data.forms["dat_pl"] = r .. "evo"
  data.forms["acc_sg"] = r .. "a"
  data.forms["acc_pl"] = r .. "as"
end})

-- o-stem masculine
decls["o"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "u"
  data.forms["nom_pl"] = r .. "i"
  data.forms["gen_sg"] = r .. "i"
  data.forms["gen_pl"] = r .. "oro"
  data.forms["dat_sg"] = r .. "a"
  data.forms["dat_pl"] = r .. "evo"
  data.forms["acc_sg"] = r .. "o"
  data.forms["acc_pl"] = r .. "os"
end})

-- o-stem neuter
decls["o-N"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "o"
  data.forms["nom_pl"] = r .. "a"
  data.forms["gen_sg"] = r .. "i"
  data.forms["gen_pl"] = r .. "oro"
  data.forms["dat_sg"] = r .. "a"
  data.forms["dat_pl"] = r .. "evo"
  data.forms["acc_sg"] = r .. "o"
  data.forms["acc_pl"] = r .. "a"
end})

-- i-stem
decls["i"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "e"
  data.forms["nom_pl"] = r .. "i"
  data.forms["gen_sg"] = r .. "i"
  data.forms["gen_pl"] = r .. "e"
  data.forms["dat_sg"] = r .. "i"
  data.forms["dat_pl"] = r .. "evo"
  data.forms["acc_sg"] = r .. "e"
  data.forms["acc_pl"] = r .. "es"
end})

-- r-stem (new)
decls["r"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "ar"
  data.forms["nom_pl"] = r .. "aiu"
  data.forms["gen_sg"] = r .. "eri"
  data.forms["gen_pl"] = r .. "are"
  data.forms["dat_sg"] = r .. "er"
  data.forms["dat_pl"] = r .. "arevo"
  data.forms["acc_sg"] = r .. "ar"
  data.forms["acc_pl"] = r .. "aru"
end})

-- d-stem type 1 (d1)
decls["d1"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "ê"
  data.forms["nom_pl"] = r .. "edi"
  data.forms["gen_sg"] = r .. "edi"
  data.forms["gen_pl"] = r .. "ede"
  data.forms["dat_sg"] = r .. "edi"
  data.forms["dat_pl"] = r .. "edevo"
  data.forms["acc_sg"] = r .. "ede"
  data.forms["acc_pl"] = r .. "edi"
end})

-- d-stem type 2 (d2)
decls["d2"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "â"
  data.forms["nom_pl"] = r .. "adi"
  data.forms["gen_sg"] = r .. "adi"
  data.forms["gen_pl"] = r .. "ade"
  data.forms["dat_sg"] = r .. "adi"
  data.forms["dat_pl"] = r .. "adevo"
  data.forms["acc_sg"] = r .. "ade"
  data.forms["acc_pl"] = r .. "adi"
end})

-- u-stem masculine
decls["u"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "u"
  data.forms["nom_pl"] = r .. "us"
  data.forms["gen_sg"] = r .. "aus"
  data.forms["gen_pl"] = r .. "eve"
  data.forms["dat_sg"] = r .. "au"
  data.forms["dat_pl"] = r .. "evo"
  data.forms["acc_sg"] = r .. "u"
  data.forms["acc_pl"] = r .. "us"
end})

-- u-stem neuter
decls["u-N"] = setmetatable({}, { __call = function(self, args, data)
  local r = args[1]
  data.forms["nom_sg"] = r .. "u"
  data.forms["nom_pl"] = r .. "ua"
  data.forms["gen_sg"] = r .. "aus"
  data.forms["gen_pl"] = r .. "eve"
  data.forms["dat_sg"] = r .. "au"
  data.forms["dat_pl"] = r .. "evo"
  data.forms["acc_sg"] = r .. "u"
  data.forms["acc_pl"] = r .. "ua"
end})

-- Table generator - no external templates needed
function export.make_table(data)
  local forms = data.forms

  local rows = {
    { label = "[[dative case|dative]]", sg = forms["dat_sg"], pl = forms["dat_pl"] },
    { label = "[[genitive case|genitive]]", sg = forms["gen_sg"], pl = forms["gen_pl"] },
    { label = "[[accusative case|accusative]]", sg = forms["acc_sg"], pl = forms["acc_pl"] },
    { label = "[[nominative case|nominative]]", sg = forms["nom_sg"], pl = forms["nom_pl"] },
  }

  local function cell(content, isHeader, extraStyle)
    local tag = isHeader and "th" or "td"
    local style = extraStyle or ""
    return string.format('<%s style="%s">%s</%s>', tag, style, content or "—", tag)
  end

  local out = {}
  table.insert(out, '<table class="inflection-table" style="border-collapse:collapse; width:40%; font-size:90%;">')

  -- Header row (without thead)
  table.insert(out, "<tr>")
  table.insert(out, cell("", true, "background:#444; color:#fff; padding:4px;"))
  table.insert(out, cell("singular", true, "background:#444; color:#fff; padding:4px;"))
  table.insert(out, cell("plural", true, "background:#444; color:#fff; padding:4px;"))
  table.insert(out, "</tr>")

  -- Body rows (without tbody)
  for _, row in ipairs(rows) do
    table.insert(out, "<tr>")
    table.insert(out, cell(row.label, false, "background:#ddd; padding:4px; font-weight:bold; white-space:nowrap;"))
    table.insert(out, cell(row.sg, false, "background:#fff; padding:4px; text-align:center;"))
    table.insert(out, cell(row.pl, false, "background:#fff; padding:4px; text-align:center;"))
    table.insert(out, "</tr>")
  end

  table.insert(out, "</table>")

  if data.footnotes and data.footnotes ~= "" then
    table.insert(out, '<div class="footnotes" style="font-size:80%; margin-top:0.5em;">' .. data.footnotes .. "</div>")
  end

  return table.concat(out, "\n")
end

return export