Module:siwa-headword: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local export = {}
local export = {}
function full_headword(data)
 
local tracking_categories = {}
local lang = require("Module:languages").getByCode("gem-pro")
 
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local args = frame:getParent().args
SUBPAGENAME = mw.title.getCurrentTitle().subpageText
-- Script-tags the topmost header.
local head = args["head"]; if head == "" then head = nil end
local pagename = mw.title.getCurrentTitle().text
local fullPagename = mw.title.getCurrentTitle().fullText
-- The part of speech. This is also the name of the category that
local namespace = mw.title.getCurrentTitle().nsText
-- entries go in. However, the two are separate (the "cat" parameter)
-- because you sometimes want something to behave as an adjective without
-- putting it in the adjectives category.
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local displayTitle
local postype = args["type"]; if postype == "" then postype = nil end
if (namespace == "" and data.sc and toBeTagged[data.sc:getCode()]
and not pagename:find "^[%z\1-\127]+$")
local data = {lang = lang, pos_category = (postype and postype .. " " or "") .. poscat, categories = {}, heads = {head}, genders = {}, inflections = {}}
or (data.sc:getCode() == "Jpan" and (test_script(pagename, "Hira") or test_script(pagename, "Kana"))) then
displayTitle = '<span class="' .. data.sc:getCode() .. '">' .. pagename .. '</span>'
if poscat == "adjectives" then
elseif namespace == "Reconstruction" then
if SUBPAGENAME:find("^-") then
displayTitle, matched = mw.ustring.gsub(
data.pos_category = "suffixes"
fullPagename,
data.categories = {"Proto-Germanic adjective-forming suffixes"}
"^(Reconstruction:[^/]+/)(.+)$",
function(before, term)
return before ..
require("Module:script utilities").tag_text(
term,
data.lang,
data.sc
)
end
)
if matched == 0 then
displayTitle = nil
end
end
end
if displayTitle then
adjective(args, data)
local frame = mw.getCurrentFrame()
elseif poscat == "adverbs" then
frame:callParserFunction(
if SUBPAGENAME:find("^-") then
"DISPLAYTITLE",
data.pos_category = "suffixes"
displayTitle
data.categories = {"Proto-Germanic adverb-forming suffixes"}
)
end
end
if data.force_cat_output then
adverb(args, data)
--[=[
elseif poscat == "determiners" then
[[Special:WhatLinksHere/Template:tracking/headword/force cat output]]
adjective(args, data)
]=]
elseif poscat == "nouns" then
require("Module:debug").track("headword/force cat output")
if SUBPAGENAME:find("^-") then
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic noun-forming suffixes"}
end
end
if data.getCanonicalName then
noun_gender(args, data)
error('The "data" variable supplied to "full_headword" should not be a language object.')
elseif poscat == "proper nouns" then
noun_gender(args, data)
elseif poscat == "verbs" then
if SUBPAGENAME:find("^-") then
data.pos_category = "suffixes"
data.categories = {"Proto-Germanic verb-forming suffixes"}
end
end
end
-- Were any categories specified?
if data.categories and #data.categories > 0 then
return require("Module:headword").full_headword(data)
local lang_name = require("Module:string").pattern_escape(data.lang:getCanonicalName())
end
for _, cat in ipairs(data.categories) do
 
-- Does the category begin with the language name? If not, tag it with a tracking category.
-- Display information for a noun's gender
if not mw.ustring.find(cat, "^" .. lang_name) then
-- This is separate so that it can also be used for proper nouns
mw.log(cat, data.lang:getCanonicalName())
function noun_gender(args, data)
table.insert(tracking_categories, "head tracking/no lang category")
local valid_genders = {
["m"] = true,
--[=[
["f"] = true,
[[Special:WhatLinksHere/Template:tracking/head tracking/no lang category]]
["n"] = true,
]=]
["m-p"] = true,
require("Module:debug").track{
["f-p"] = true,
"headword/no lang category",
["n-p"] = true}
"headword/no lang category/lang/" .. data.lang:getCode()
}
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
end
local g = args[1] or ""; if g == "" then g = "?" end
end
local i = 2
if not data.pos_category
while g ~= "" do
and mw.ustring.find(data.categories[1], "^" .. data.lang:getCanonicalName())
if not valid_genders[g] then
then
g = "?"
data.pos_category = mw.ustring.gsub(data.categories[1], "^" .. data.lang:getCanonicalName() .. " ", "")
table.remove(data.categories, 1)
end
end
end
if not data.pos_category then
-- If any of the specifications is a "?", add the entry
error(
-- to a cleanup category.
'No valid part-of-speech categories were found in the list '
if g == "?" then
.. 'of categories passed to the function "full_headword". '
table.insert(data.categories, "Requests for gender in Proto-Germanic entries")
.. 'The part-of-speech category should consist of a language\'s '
elseif g == "m-p" or g == "f-p" or g == "n-p" then
.. 'canonical name plus a part of speech.'
table.insert(data.categories, "Proto-Germanic pluralia tantum")
)
end
-- Categorise for unusual characters
local standard = data.lang:getStandardCharacters()
if standard then
if mw.ustring.len(title.subpageText) ~= 1 and not non_categorizable() then
for character in mw.ustring.gmatch(title.subpageText, "([^" .. standard .. "])") do
local upper = mw.ustring.upper(character)
if not mw.ustring.find(upper, "[" .. standard .. "]") then
character = upper
end
table.insert(
data.categories,
data.lang:getCanonicalName() .. " terms spelled with " .. character
)
end
end
end
-- Categorise for palindromes
if title.nsText ~= "Reconstruction" and mw.ustring.len(title.subpageText)>1
and require('Module:palindromes').is_palindrome(
title.subpageText, data.lang, data.sc
) then
table.insert(data.categories, data.lang:getCanonicalName() .. " palindromes")
end
end
table.insert(data.genders, g)
g = args["g" .. i] or ""
i = i + 1
end
end
function adjective(args, data)
local adverb = args["adv"]; if adverb == "" then adverb = nil end
local comparative = args[1]; if comparative == "" then comparative = nil end
local superlative = args[2]; if superlative == "" then superlative = nil end
if adverb then
table.insert(data.inflections, {label = "adverb", adverb})
end
if comparative then
table.insert(data.inflections, {label = "comparative", comparative})
end
if superlative then
table.insert(data.inflections, {label = "superlative", superlative})
end
end
function adverb(args, data)
local adjective = args["adj"]; if adjective == "" then adjective = nil end
local comparative = args[1]; if comparative == "" then comparative = nil end
local superlative = args[2]; if superlative == "" then superlative = nil end
if adjective then
table.insert(data.inflections, {label = "adjective", adjective})
end
if comparative then
table.insert(data.inflections, {label = "comparative", comparative})
end
-- This may add more categories (e.g. gender categories), so make sure it gets
if superlative then
-- evaluated first.
table.insert(data.inflections, {label = "superlative", superlative})
local text = show_headword_line(data)
return
text ..
require("Module:utilities").format_categories(
data.categories, data.lang, data.sort_key, nil,
data.force_cat_output or test_force_categories, data.sc
) ..
require("Module:utilities").format_categories(
tracking_categories, data.lang, data.sort_key, nil,
data.force_cat_output or test_force_categories, data.sc
)
end
end
end


return export
return export