Differenze tra le versioni di "Modulo:Headword/templates"

Da Dialetto Metaurense.
m (174 versioni importate)
 
(144 versioni intermedie di 9 utenti non mostrate)
Riga 1: Riga 1:
 
local export = {}
 
local export = {}
  
−
local lemmas = {
+
-- Part of speech types that should not be pluralized.
−
["acronym"] = true,
+
local invariable = mw.loadData("Module:headword/data").invariable
−
["adjective"] = true,
 
−
["adverb"] = true,
 
−
["article"] = true,
 
−
["circumfix"] = true,
 
−
["circumposition"] = true,
 
−
["conjunction"] = true,
 
−
["determiner"] = true,
 
−
["gismu"] = true,
 
−
["Han tu"] = true,
 
−
["hanzi"] = true,
 
−
["hanja"] = true,
 
−
["idiom"] = true,
 
−
["interjection"] = true,
 
−
["kanji"] = true,
 
−
["letter"] = true,
 
−
["noun"] = true,
 
−
["numeral"] = true,
 
−
["phrase"] = true,
 
−
["postposition"] = true,
 
−
["prefix"] = true,
 
−
["preposition"] = true,
 
−
["prepositional phrase"] = true,
 
−
["pronoun"] = true,
 
−
["proverb"] = true,
 
−
["proper noun"] = true,
 
−
["root"] = true,
 
−
["suffix"] = true,
 
−
["symbol"] = true,
 
−
["verb"] = true,
 
−
}
 
−
 
 
−
local nonlemmas = {
 
−
["adjective form"] = true,
 
−
["adjective comparative form"] = true,
 
−
["adjective superlative form"] = true,
 
−
["adverb form"] = true,
 
−
["adverb comparative form"] = true,
 
−
["adverb superlative form"] = true,
 
−
["determiner form"] = true,
 
−
["jyutping"] = true,
 
−
["kanji reading"] = true,
 
−
["noun form"] = true,
 
−
["numeral form"] = true,
 
−
["participle"] = true,
 
−
["participle form"] = true,
 
−
["past participle"] = true,
 
−
["past participle form"] = true,
 
−
["pinyin"] = true,
 
−
["plural"] = true,
 
−
["present participle"] = true,
 
−
["pronoun form"] = true,
 
−
["rafsi"] = true,
 
−
["romanization"] = true,
 
−
["romaji"] = true,
 
−
["verb form"] = true,
 
−
}
 
−
 
 
−
local invariable = {
 
−
["gismu"] = true,
 
−
["Han tu"] = true,
 
−
["hanzi"] = true,
 
−
["hanja"] = true,
 
−
["jyutping"] = true,
 
−
["kanji"] = true,
 
−
["phrasebook"] = true,
 
−
["pinyin"] = true,
 
−
["punctuation"] = true,
 
−
["rafsi"] = true,
 
−
["romaji"] = true,
 
−
}
 
  
 
function export.head_t(frame)
 
function export.head_t(frame)
−
local args = frame:getParent().args
+
local plain_param = {}
 +
local list_with_holes = {list = true, allow_holes = true}
 +
local params = {
 +
[1] = {required = true, default = "und"},
 +
["sc"] = plain_param,
 +
["cat sc"] = plain_param,
 +
["sort"] = plain_param,
 +
 +
[2] = {required = true, default = "nouns"},
 +
["cat2"] = plain_param,
 +
["cat3"] = plain_param,
 +
["cat4"] = plain_param,
 +
 +
["head"] = {list = true, allow_holes = true, default = ""},
 +
["id"] = plain_param,
 +
["tr"] = list_with_holes,
 +
-- See also "ts" at bottom.
 +
["g"] = {list = true},
 +
 +
[3] = list_with_holes,
 +
 +
["f=accel"]  = list_with_holes,
 +
["f=request"] = list_with_holes,
 +
["f=alt"]    = list_with_holes,
 +
["f=sc"]      = list_with_holes,
 +
["f=id"]      = list_with_holes,
 +
["f=tr"]      = list_with_holes,
 +
["f=g"]      = list_with_holes,
 +
["f=qual"]    = list_with_holes,
 +
["f=nolink"]  = {list = true, allow_holes = true, type = "boolean"},
 +
["f=lang"]    = list_with_holes,
 +
 +
-- Belongs after "tr", but has to be placed here, or args["falt"] will vanish.
 +
["ts"] = list_with_holes,
 +
}
 +
 +
local args = require("Module:parameters").process(frame:getParent().args, params)
 
 
 
-- Get language and script information
 
-- Get language and script information
−
local lang = args[1] or (mw.title.getCurrentTitle().nsText == "Template" and "und") or error("Language code has not been specified. Please pass parameter 1 to the template.")
+
local data = {}
−
local sc = args["sc"] or ""; if sc == "" then sc = nil end
+
data.lang = require("Module:languages").getByCode(args[1]) or require("Module:languages").err(args[1], 1)
−
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
+
data.sort_key = args["sort"]
−
sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
+
data.heads = args["head"]
 +
data.id = args["id"]
 +
data.translits = args["tr"]
 +
data.transcriptions = args["ts"]
 +
data.genders = args["g"]
 +
 +
-- Script
 +
local cat_sc
 
 
−
-- Gather basic parameters
+
if args["cat sc"] then
−
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
+
data.sc = (args["cat sc"] and (require("Module:scripts").getByCode(args["cat sc"]) or error("The script code \"" .. args["cat sc"] .. "\" is not valid.")) or nil)
−
local pos = args[2]; if pos == "" then pos = nil end
+
cat_sc = cat_sc
−
local cat = args["cat"]; if cat == "" then cat = nil end
+
else
−
local cat2 = args["cat2"]; if cat2 == "" then cat2 = nil end
+
data.sc = (args["sc"] and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. args["sc"] .. "\" is not valid.")) or nil)
−
local cat3 = args["cat3"]; if cat3 == "" then cat3 = nil end
+
end
−
local tr = args["tr"]; if tr == "" then tr = nil end
 
 
 
−
-- Gather headwords
+
-- Part-of-speech category
−
local head = args["head"]
+
data.pos_category = args[2]
−
local heads = {head or ""}
 
−
local i = 2
 
−
head = args["head" .. i]
 
 
 
−
while head do
+
if not data.pos_category:find("s$") and not invariable[data.pos_category] then
−
if head ~= "" then
+
-- Make the plural form of the part of speech
−
table.insert(heads, head)
+
if data.pos_category:find("x$") then -- prefix, suffix, confix, infix, circumfix, affix, interfix, transfix
 +
data.pos_category = data.pos_category .. "es"
 +
else
 +
data.pos_category = data.pos_category .. "s"
 
end
 
end
−
 
−
i = i + 1
 
−
head = args["head" .. i]
 
 
end
 
end
 
 
−
-- Gather gender and number specifications
+
if cat_sc then
−
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
+
data.pos_category = data.pos_category .. " in " .. cat_sc:getCategoryName()
−
local genders = {}
+
end
−
local g = args["g"]; if g == "" then g = nil end
+
−
local i = 2
+
-- Additional categories
 +
data.categories = {}
 
 
−
while g do
+
if args["cat2"] then
−
table.insert(genders, g)
+
table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat2"])
−
g = args["g" .. i]; if g == "" then g = nil end
 
−
i = i + 1
 
 
end
 
end
 
 
−
-- Gather inflected forms
+
if args["cat3"] then
−
local inflections = {}
+
table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat3"])
 +
end
 
 
−
local i = 1
+
if args["cat4"] then
−
local label = args[i * 2 + 1]
+
table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat4"])
−
local accel = args["f" .. i .. "accel"]; if accel == "" then accel = nil end
+
end
−
local nolink = args["f" .. i .. "nolink"]; if nolink == "" then nolink = nil end
 
−
local parts = {label = label, accel = accel, nolink = nolink}
 
 
 
−
local m_scripts = nil
+
-- Inflected forms
 +
data.inflections = {}
 
 
−
while label do
+
for i = 1, math.ceil(args[3].maxindex / 2) do
−
local term = args[i * 2 + 2]; if term == "" then term = nil end
+
local infl_part = {
−
local alt = args["f" .. i .. "alt"]; if alt == "" then alt = nil end
+
label    = args[3][i * 2 - 1],
−
local sc = args["f" .. i .. "sc"]; if sc == "" then sc = nil end
+
accel    = args["faccel"][i],
−
local id = args["f" .. i .. "id"]; if id == "" then id = nil end
+
request  = args["frequest"][i],
−
local gender = args["f" .. i .. "g"]; if gender == "" then gender = nil end
+
}
 
 
−
if term or alt then
+
local form = {
−
if sc then
+
term       =  args[3][i * 2],
−
m_scripts = m_scripts or require("Module:scripts")
+
alt       =  args["falt"][i],
−
sc = (sc and (m_scripts.getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
+
genders    = {args["fg"][i]},
−
end
+
id        =  args["fid"][i],
−
+
lang      =  args["flang"][i],
−
table.insert(parts, {term = term, alt = alt, sc = sc, id = id, genders = {gender}})
+
nolink    =  args["fnolink"][i],
 +
qualifiers = {args["fqual"][i]},
 +
sc        =  args["fsc"][i],
 +
translit  =  args["ftr"][i],
 +
}
 +
 +
if form.lang then
 +
form.lang = require("Module:languages").getByCode(form.lang) or require("Module:languages").err(form.lang, "f" .. i .. "lang")
 
end
 
end
 
 
−
i = i + 1
+
if form.sc then
−
label = args[i * 2 + 1]
+
form.sc = require("Module:scripts").getByCode(form.sc) or error("The script code \"" .. form.sc .. "\" is not valid.")
−
accel = args["f" .. i .. "accel"]; if accel == "" then accel = nil end
 
−
nolink = args["f" .. i .. "nolink"]; if nolink == "" then nolink = nil end
 
−
 
−
-- If the next label is not "or" then insert the previous one and create a new one.
 
−
if label ~= "or" then
 
−
-- Only insert if the previous label is not empty.
 
−
if (parts.label or "") ~= "" then
 
−
table.insert(inflections, parts)
 
−
end
 
−
 
−
parts = {label = label, accel = accel, nolink = nolink}
 
 
end
 
end
−
end
 
−
 
−
-- Get/set categories
 
−
local categories = {}
 
−
 
−
if cat then
 
−
table.insert(categories, lang:getCanonicalName() .. " " .. cat)
 
 
 
−
if pos then
+
-- If no term or alt is given, then the label is shown alone.
−
table.insert(categories, "head tracking/with cat/with pos")
+
if form.term or form.alt then
−
else
+
table.insert(infl_part, form)
−
table.insert(categories, "head tracking/with cat/no pos")
 
−
require("Module:debug").track("head tracking/no pos/lang/" .. lang:getCode())
 
−
end
 
−
elseif pos then
 
−
if lemmas[pos] then
 
−
table.insert(categories, lang:getCanonicalName() .. " lemmas")
 
−
elseif not nonlemmas[pos] then
 
−
table.insert(categories, "head tracking/unrecognized pos")
 
−
require("Module:debug").track("head tracking/unrecognized pos/pos/" .. pos)
 
−
require("Module:debug").track("head tracking/unrecognized pos/lang/" .. lang:getCode())
 
 
end
 
end
 
 
−
-- Make the plural form of the part of speech
+
if infl_part.label == "or" then
−
if pos:find("x$") then
+
-- Append to the previous inflection part, if one exists
−
pos = pos .. "es"
+
if #infl_part > 0 and data.inflections[1] then
−
elseif not invariable[pos] then
+
table.insert(data.inflections[#data.inflections], form)
−
pos = pos .. "s"
+
end
 +
elseif infl_part.label then
 +
-- Add a new inflection part
 +
table.insert(data.inflections, infl_part)
 
end
 
end
−
 
−
table.insert(categories, lang:getCanonicalName() .. " " .. pos)
 
−
else
 
−
table.insert(categories, "head tracking/no pos")
 
−
require("Module:debug").track("head tracking/no pos/lang/" .. lang:getCode())
 
−
end
 
−
 
−
if cat2 then
 
−
table.insert(categories, lang:getCanonicalName() .. " " .. cat2)
 
−
end
 
−
 
−
if cat3 then
 
−
table.insert(categories, lang:getCanonicalName() .. " " .. cat3)
 
 
end
 
end
 
 
−
return
+
return require("Module:headword").full_headword(data)
−
require("Module:headword").full_headword(lang, sc, heads, tr, genders, inflections, categories, sort_key) ..
 
−
require("Module:utilities").format_categories(categories, lang, sort_key)
 
 
end
 
end
  
 
return export
 
return export

Versione attuale delle 05:12, 5 set 2018

La documentazione per questo modulo può essere creata in Modulo:Headword/templates/man

local export = {}

-- Part of speech types that should not be pluralized.
local invariable = mw.loadData("Module:headword/data").invariable

function export.head_t(frame)
	local plain_param = {}
	local list_with_holes = {list = true, allow_holes = true}
	local params = {
		[1] = {required = true, default = "und"},
		["sc"] = plain_param,
		["cat sc"] = plain_param,
		["sort"] = plain_param,
		
		[2] = {required = true, default = "nouns"},
		["cat2"] = plain_param,
		["cat3"] = plain_param,
		["cat4"] = plain_param,
		
		["head"] = {list = true, allow_holes = true, default = ""},
		["id"] = plain_param,
		["tr"] = list_with_holes,
		-- See also "ts" at bottom.
		["g"] = {list = true},
		
		[3] = list_with_holes,
		
		["f=accel"]   = list_with_holes,
		["f=request"] = list_with_holes,
		["f=alt"]     = list_with_holes,
		["f=sc"]      = list_with_holes,
		["f=id"]      = list_with_holes,
		["f=tr"]      = list_with_holes,
		["f=g"]       = list_with_holes,
		["f=qual"]    = list_with_holes,
		["f=nolink"]  = {list = true, allow_holes = true, type = "boolean"},
		["f=lang"]    = list_with_holes,
		
		-- Belongs after "tr", but has to be placed here, or args["falt"] will vanish.
		["ts"] = list_with_holes,
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	-- Get language and script information
	local data = {}
	data.lang = require("Module:languages").getByCode(args[1]) or require("Module:languages").err(args[1], 1)
	data.sort_key = args["sort"]
	data.heads = args["head"]
	data.id = args["id"]
	data.translits = args["tr"]
	data.transcriptions = args["ts"]
	data.genders = args["g"]
	
	-- Script
	local cat_sc
	
	if args["cat sc"] then
		data.sc = (args["cat sc"] and (require("Module:scripts").getByCode(args["cat sc"]) or error("The script code \"" .. args["cat sc"] .. "\" is not valid.")) or nil)
		cat_sc = cat_sc
	else
		data.sc = (args["sc"] and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. args["sc"] .. "\" is not valid.")) or nil)
	end
	
	-- Part-of-speech category
	data.pos_category = args[2]
	
	if not data.pos_category:find("s$") and not invariable[data.pos_category] then
		-- Make the plural form of the part of speech
		if data.pos_category:find("x$") then -- prefix, suffix, confix, infix, circumfix, affix, interfix, transfix
			data.pos_category = data.pos_category .. "es"
		else
			data.pos_category = data.pos_category .. "s"
		end
	end
	
	if cat_sc then
		data.pos_category = data.pos_category .. " in " .. cat_sc:getCategoryName()
	end
	
	-- Additional categories
	data.categories = {}
	
	if args["cat2"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat2"])
	end
	
	if args["cat3"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat3"])
	end
	
	if args["cat4"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat4"])
	end
	
	-- Inflected forms
	data.inflections = {}
	
	for i = 1, math.ceil(args[3].maxindex / 2) do
		local infl_part = {
			label    = args[3][i * 2 - 1],
			accel    = args["faccel"][i],
			request  = args["frequest"][i],
			}
		
		local form = {
			term       =  args[3][i * 2],
			alt        =  args["falt"][i],
			genders    = {args["fg"][i]},
			id         =  args["fid"][i],
			lang       =  args["flang"][i],
			nolink     =  args["fnolink"][i],
			qualifiers = {args["fqual"][i]},
			sc         =  args["fsc"][i],
			translit   =  args["ftr"][i],
			}
		
		if form.lang then
			form.lang = require("Module:languages").getByCode(form.lang) or require("Module:languages").err(form.lang, "f" .. i .. "lang")
		end
		
		if form.sc then
			form.sc = require("Module:scripts").getByCode(form.sc) or error("The script code \"" .. form.sc .. "\" is not valid.")
		end
		
		-- If no term or alt is given, then the label is shown alone.
		if form.term or form.alt then
			table.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[1] then
				table.insert(data.inflections[#data.inflections], form)
			end
		elseif infl_part.label then
			-- Add a new inflection part
			table.insert(data.inflections, infl_part)
		end
	end
	
	return require("Module:headword").full_headword(data)
end

return export