Module:oyen-contionary-utils: Difference between revisions

From Linguifex
Jump to navigation Jump to search
(creation)
 
No edit summary
 
(28 intermediate revisions by the same user not shown)
Line 1: Line 1:
--Broken as templates don't invoke from lua module
local m_args = require("Module:Arguments")
local m_args = require("Module:Arguments")
local m_languages = require("Module:languages")
local m_languages = require("Module:languages")
Line 4: Line 6:
local m = {}
local m = {}


function m.setup_entry(lang_code)
function m.latin(frame)
  local args = m_args.getArgs(frame)
 
  local v,c = args[1]:gsub("[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZḿńŕĺĹ]+", "")
 
  return v
end
 
function m.setup_entry(frame)
  local args = m_args.getArgs(frame)
 
  local lang_code = args[1]
 
   local lang = m_languages.getByCode(lang_code, nil, false, false)
   local lang = m_languages.getByCode(lang_code, nil, false, false)


   if not lang then
   if not lang then
     error(string.format("Invalid language code '[%s]'"), lang_code)
     error(string.format("Invalid language code '%s'"), lang_code)
   end
   end


Line 15: Line 29:
   local mw_src = ""
   local mw_src = ""


   mw_src = mw_src + string.format("==[%s]==", lang:getCanonicalName())
   mw_src = mw_src .. string.format("<h2>%s</h2>", lang:getCanonicalName())


   if reconstructed then
   if reconstructed then
     mw_src = mw_src + "{{Reconstructed}}"
     mw_src = mw_src .. "{{Reconstructed}}"
   end
   end


Line 24: Line 38:
end
end


function m.entry(word_type)
function m.entry(frame)
   local mw_src = ""
   local args = m_args.getArgs(frame)


   mw_src = mw_src + string.format("===[%s]===", word_type)
   local word_type = args[1]


   mw_src = mw_src + "<b>{{PAGENAME}}</b><br>"
   local mw_src = ""
 
  return mw_src
end
 
local function inflection(base_form, x_categories, y_categories, stem, collapsed_highlight_coords)
  local wikicode = {}
 
  table.insert(wikicode, "{| class=\"inflection-table vsSwitcher\" data-toggle-category=\"inflection\" style=\"background: #FAFAFA; border: 1px solid #d0d0d0; text-align: left;\" cellspacing=\"1\" cellpadding=\"2\"")
  table.insert(wikicode, "|- style=\"background: #CCCCFF;\"\n! class=\"vsToggleElement\" colspan=\"" .. (#x_categories + 1) .. "\" | " .. stem[1])
 
  table.insert(wikicode, "|- class=\"vsShow\" style=\"background: #CCCCFF;\"")
table.insert(wikicode, "!")
 
  table.insert(wikicode, "! style=\"min-width: 11em; background: #CCCCFF;\" | " .. x_categories[1])
 
  for _, highlight in ipairs(collapsed_highlight_coords) do
    table.insert(wikicode, "|- class=\"vsShow\" style=\"background: #F2F2FF;\"")
  table.insert(wikicode, "! style=\"min-width: 8em; background: #E6E6FF;\" | " .. y_categories[highlight[2]])
 
    table.insert(wikicode, "| style=\"min-width: 11em;\" | " .. string.format(stem[2][highlight[2]][highlight[1]], base_form))
  end
 
  table.insert(wikicode, "|- class=\"vsHide\" style=\"background: #CCCCFF;\"")
  table.insert(wikicode, "!")
 
  for _, x_cat in ipairs(x_categories) do
    table.insert(wikicode, "! style=\"min-width: 11em; background: #CCCCFF;\" | " .. x_cat)
  end
 
  for y_i, y_cat in ipairs(y_categories) do
    table.insert(wikicode, "|- class=\"vsHide\" style=\"background-color: #F2F2FF;\"\n! style=\"min-width: 8em; background-color: #E6E6FF;\" | " .. y_cat)
 
    for x_i, x_cat in ipairs(x_categories) do
      table.insert(wikicode, "| " .. string.format(stem[2][y_i][x_i], base_form))
    end
  end


   table.insert(wikicode, [=[|}]=])
   mw_src = mw_src .. string.format("<h3>%s</h3>", word_type)


   local mw_src = table.concat(wikicode, "\n")
   mw_src = mw_src .. "<b>{{PAGENAME}}</b><br>"


   return mw_src
   return mw_src
end
end


function m.lthm_noun(root, stem_id)
function m.descendant(frame)
  local noun_stems = {
local args = m_args.getArgs(frame)
    ["e-stem"] = {
      "e-stem",
local lang_code = args[1]
      {
local word = args[2]
        {"[%s]et-", "[%s]KL̀t"},
        {"[%s]eĺ-", "[%s]Kỳĺ"},
        {"[%s]ḿeDat-", "[%s]KLeT"},
        {"[%s]oNat-", "[%s]KL̀n"},
        {"[%s]raBet-", "[%s]KRaB"},
      }
    },
    ["e-stem y-var"] = {
      "e-stem y-variation",
      {
        {"[%s]yet-", "[%s]ỳKL̀t"},
        {"[%s]yeĺ-", "[%s]ỳKỳĺ"},
        {"[%s]ỳḿeDat-", "[%s]ỳKLeT"},
        {"[%s]yoNat-", "[%s]ỳKL̀n"},
        {"[%s]ỳraBet-", "[%s]ỳKRaB"},
      }
    },
    ["a-stem"] = {
      "a-stem",
      {
        {"[%s]at-", "[%s]KL̀t"},
        {"[%s]aĺ-", "[%s]Kỳĺ"},
        {"[%s]ḿat-", "[%s]KLaT"},
        {"[%s]oNat-", "[%s]KL̀n"},
        {"[%s]raBat-", "[%s]KRaB"},
      }
    }
  }
 
  local stem = noun_stems[stem_id]
 
  if not stem then
    error(string.format("No stem found with identifier '[%s]'", root))
  end


  return inflection(
local lang = m_languages.getByCode(lang_code, nil, false, false)
    root,
    {"Definite", "Indefinite"},
if not lang then
    {"Nominative", "Objective", "Locative", "Ablative", "Lative"},
error(string.format("Invalid language code '%s'"), lang_code)
    stem,
end
    {{1, 1}, {1, 2}}
  )
local canon_lang_name = lang:getCanonicalName()
return '<span class="desc-arr" title="borrowed">→</span> ' .. canon_lang_name .. ": " .. '<span class="Latn" lang="lthm-pro">[[Contionary:' .. word .. "#" .. canon_lang_name .. "|*" .. word .. "]]</span>"
end
end


return m
return m

Latest revision as of 18:20, 8 December 2024

Documentation for this module may be created at Module:oyen-contionary-utils/doc

--Broken as templates don't invoke from lua module

local m_args = require("Module:Arguments")
local m_languages = require("Module:languages")

local m = {}

function m.latin(frame)
  local args = m_args.getArgs(frame)

  local v,c = args[1]:gsub("[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZḿńŕĺĹ]+", "")

  return v
end

function m.setup_entry(frame)
  local args = m_args.getArgs(frame)

  local lang_code = args[1]

  local lang = m_languages.getByCode(lang_code, nil, false, false)

  if not lang then
    error(string.format("Invalid language code '%s'"), lang_code)
  end

  local reconstructed = lang:getTypes()["reconstructed"]

  local mw_src = ""

  mw_src = mw_src .. string.format("<h2>%s</h2>", lang:getCanonicalName())

  if reconstructed then
    mw_src = mw_src .. "{{Reconstructed}}"
  end

  return mw_src
end

function m.entry(frame)
  local args = m_args.getArgs(frame)

  local word_type = args[1]

  local mw_src = ""

  mw_src = mw_src .. string.format("<h3>%s</h3>", word_type)

  mw_src = mw_src .. "<b>{{PAGENAME}}</b><br>"

  return mw_src
end

function m.descendant(frame)
	local args = m_args.getArgs(frame)
	
	local lang_code = args[1]
	local word = args[2]

	local lang = m_languages.getByCode(lang_code, nil, false, false)
	
	if not lang then
		error(string.format("Invalid language code '%s'"), lang_code)
	end
	
	local canon_lang_name = lang:getCanonicalName()
	
	return '<span class="desc-arr" title="borrowed">→</span> ' .. canon_lang_name .. ": " .. '<span class="Latn" lang="lthm-pro">[[Contionary:' .. word .. "#" .. canon_lang_name .. "|*" .. word .. "]]</span>"
end

return m