Module:ug-headword/sandbox
Appearance
- This module sandbox lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox of (diff)
local export = {}
local m_com = require("Module:ug-common")
local pos_functions = {}
local lang = require("Module:languages").getByCode("ug")
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
PAGENAME = mw.title.getCurrentTitle().text
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local params = {
["head"] = {list = true, default = ""},
["suff"] = {type = "boolean"},
}
if pos_functions[poscat] then
for key, val in pairs(pos_functions[poscat].params) do
params[key] = val
end
end
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = poscat, categories = {}, heads = args["head"], inflections = {enable_auto_translit = true}}
if args["suff"] then
data.pos_category = "suffixes"
if poscat == "adjectives" then
table.insert(data.categories, lang:getCanonicalName() .. " adjective-forming suffixes")
elseif poscat == "adverbs" then
table.insert(data.categories, lang:getCanonicalName() .. " adverb-forming suffixes")
elseif poscat == "nouns" then
table.insert(data.categories, lang:getCanonicalName() .. " noun-forming suffixes")
elseif poscat == "verbs" then
table.insert(data.categories, lang:getCanonicalName() .. " verb-forming suffixes")
else
error("No category exists for suffixes forming " .. poscat .. ".")
end
end
if pos_functions[poscat] then
pos_functions[poscat].func(args, data)
end
return require("Module:headword").full_headword(data)
end
function export.make_plural_noun(singular, vv)
local base, v, c = m_com.getLast(singular)
if not v then return {} end
--if change == "yes" then
if c == "" and vv ~= nil and vv ~= "" then
v = vv
--else
-- if c == "" and (v == "ا" or v == "ە") then
-- v = "ى"
-- end
end
--end
local term = base .. v .. c
local tongue = m_com.checkTongue(singular)
if tongue == "front" then
return {term .. "لەر"}
elseif tongue == "back" then
return {term .. "لار"}
end
return {}
end
pos_functions["nouns"] = {
params = {
[1] = {list = true, allow_holes = true},
["pl"] = {}, --plural override (Outdated)
["change"] = {}, -- yes or (else:no) (Outdated)
},
func = function(args, data)
-- Gather all the plural parameters from the numbered parameters.
local plurals = {}
for i = 1, args[1].maxindex do
local pl = args[1][i]
if pl then
table.insert(plurals, pl)
end
end
-- Decide what to do next...
local mode = nil
if plurals[1] == "?" or plurals[1] == "!" or plurals[1] == "-" or plurals[1] == "~" then
mode = plurals[1]
table.remove(plurals, 1) -- Remove the mode parameter
end
-- Plural is unknown
if mode == "?" then
table.insert(data.categories, lang:getCanonicalName() .. " nouns with unknown or uncertain plurals")
return
-- Plural is not attested
elseif mode == "!" then
table.insert(data.inflections, {label = "plural not attested"})
table.insert(data.categories, lang:getCanonicalName() .. " nouns with unattested plurals")
return
-- Uncountable noun; may occasionally have a plural
elseif mode == "-" then
table.insert(data.categories, lang:getCanonicalName() .. " uncountable nouns")
-- If plural forms were given explicitly, then show "usually"
--if #plurals > 0 then
table.insert(data.inflections, {label = "usually [[Appendix:Glossary#uncountable|uncountable]]"})
table.insert(data.categories, lang:getCanonicalName() .. " countable nouns")
--else
-- table.insert(data.inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
--end
-- Mixed countable/uncountable noun, always has a plural
elseif mode == "~" then
table.insert(data.inflections, {label = "[[Appendix:Glossary#countable|countable]] and [[Appendix:Glossary#uncountable|uncountable]]"})
table.insert(data.categories, lang:getCanonicalName() .. " uncountable nouns")
table.insert(data.categories, lang:getCanonicalName() .. " countable nouns")
-- The default, always has a plural
else
table.insert(data.categories, lang:getCanonicalName() .. " countable nouns")
end
--change
--local change = args["change"] or "yes"
--if plurals[1] == "no" then
-- change = plurals[1]
-- table.remove(plurals, 1) -- Remove the change parameter
--end
--vowel
local vv = nil
if plurals[1] == "i" or plurals[1] == "ى" then
vv = "ى"
table.remove(plurals, 1) -- Remove the vowel parameter
end
local stem = PAGENAME
-- If no plural was given, add a default one now
if #plurals == 0 then
local pl = args["pl"] or nil
if pl then
plurals = {pl}
else
plurals = export.make_plural_noun(stem, vv, change)
end
if #plurals == 0 then
table.insert(data.categories, lang:getCanonicalName() .. " nouns with unpredictable plurals")
end
end
if #plurals == 0 then
return
end
-- There are plural forms to show, so show them
local pl_parts = {label = "impersonal nominative plural"}
for i, pl in ipairs(plurals) do
if pl == "a" or pl == "ا" or pl == "lar" or pl == "لار" then
pl = stem .. "لار"
elseif pl == "e" or pl == "ە" or pl == "ler" or pl == "لەر" then
pl = stem .. "لەر"
end
table.insert(pl_parts, pl)
if pl and not mw.title.new(pl).exists then
table.insert(data.categories, lang:getCanonicalName() .. " nouns with missing plurals")
end
end
table.insert(data.inflections, pl_parts)
end
}
return export