This module is used by the template {{head}}
to create headwords for entries.
insert = table.insert
local process_params = require("Module:parameters").process
local export = {}
local function get_args(frame)
local boolean = {type = "boolean"}
local boolean_list_allow_holes = {type = "boolean", list = true, allow_holes = true}
local list_allow_holes = {list = true, allow_holes = true}
return process_params(frame:getParent().args, {
= {required = true, type = "language", default = "und"},
= {type = "script"},
= true,
= {required = true, default = "nouns"},
= boolean,
= boolean,
= boolean,
= boolean,
= boolean,
= boolean,
= boolean,
= boolean, -- EXPERIMENTAL: see ]
= true,
= true,
= true,
= list_allow_holes,
= true,
= list_allow_holes,
= list_allow_holes,
= true,
= {list = true},
= list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= boolean_list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= {list = true, allow_holes = true, type = "language"},
= {list = true, allow_holes = true, type = "script"},
= list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= list_allow_holes,
= boolean_list_allow_holes,
= boolean_list_allow_holes,
})
end
function export.head_t(frame)
local m_headword = require("Module:headword")
local function track(page)
require("Module:debug/track")("headword/templates/" .. page)
return true
end
local args = get_args(frame)
-- Get language and script information
local data = {}
data.lang = args
data.sc = args
data.sccat = args
data.sort_key = args
data.heads = args
data.id = args
data.translits = args
data.transcriptions = args
data.gloss = args
data.genders = args
-- This shouldn't really happen.
for i = 1,args.maxindex do
if not args then
track("head-with-holes")
end
end
for k, v in pairs(args) do
if k ~= "maxindex" then
if data.genders then
data.genders = {spec = data.genders, qualifiers = {v}}
else
k = k == 1 and "" or tostring(k)
error(("g%squal= specified without g%s="):format(k, k))
end
end
end
-- EXPERIMENTAL: see ]
data.altform = args
-- Part-of-speech category
local pos_category = args
data.noposcat = args
-- Check for headword aliases and then pluralize if the POS term does not have an invariable plural.
data.pos_category = m_headword.pluralize_pos(
mw.loadData("Module:headword/data").pos_aliases or pos_category
)
-- Additional categories.
data.categories = {}
data.whole_page_categories = {}
data.nomultiwordcat = args
data.nogendercat = args
data.nopalindromecat = args
if args then
insert(data.categories, data.lang:getFullName() .. " " .. args)
end
if args then
insert(data.categories, data.lang:getFullName() .. " " .. args)
end
if args then
insert(data.categories, data.lang:getFullName() .. " " .. args)
end
-- Headword linking
data.nolinkhead = args
-- Inflected forms
data.inflections = {enable_auto_translit = args}
for i = 1, math.ceil(args.maxindex / 2) do
local infl_part = {
label = args,
accel = args and {
form = args,
translit = args,
lemma = args,
lemma_translit = args,
gender = args,
nostore = args,
} or nil,
request = args,
enable_auto_translit = args,
}
local form = {
term = args,
alt = args,
genders = args and mw.text.split(args, ",") or {},
id = args,
lang = args,
nolinkinfl = args,
q = {args},
sc = args,
translit = args,
transcription = args,
}
-- If no term or alt is given, then the label is shown alone.
if form.term or form.alt then
insert(infl_part, form)
end
if infl_part.label == "or" then
-- Append to the previous inflection part, if one exists
if #infl_part > 0 and data.inflections then
insert(data.inflections, form)
end
elseif infl_part.label then
-- Add a new inflection part
insert(data.inflections, infl_part)
end
end
return m_headword.full_headword(data)
end
return export