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

Da Dialetto Metaurense.
m (174 versioni importate)
 
(61 versioni intermedie di 8 utenti non mostrate)
Riga 2: Riga 2:
  
 
-- Part of speech types that should not be pluralized.
 
-- Part of speech types that should not be pluralized.
−
local invariable = {
+
local invariable = mw.loadData("Module:headword/data").invariable
−
["cmavo"] = true,
 
−
["cmene"] = true,
 
−
["fu'ivla"] = true,
 
−
["gismu"] = true,
 
−
["Han tu"] = true,
 
−
["hanzi"] = true,
 
−
["hanja"] = true,
 
−
["jyutping"] = true,
 
−
["kanji"] = true,
 
−
["lujvo"] = true,
 
−
["phrasebook"] = true,
 
−
["pinyin"] = true,
 
−
["rafsi"] = true,
 
−
["romaji"] = true,
 
−
}
 
  
−
local params = {
+
function export.head_t(frame)
−
[1] = {required = true},
+
local plain_param = {}
−
["sc"] = {},
+
local list_with_holes = {list = true, allow_holes = true}
−
["cat sc"] = {},
+
local params = {
−
["sort"] = {},
+
[1] = {required = true, default = "und"},
−
+
["sc"] = plain_param,
−
[2] = {},
+
["cat sc"] = plain_param,
−
["cat2"] = {},
+
["sort"] = plain_param,
−
["cat3"] = {},
+
−
+
[2] = {required = true, default = "nouns"},
−
["head"] = {},
+
["cat2"] = plain_param,
−
["head2"] = {},
+
["cat3"] = plain_param,
−
["head3"] = {},
+
["cat4"] = plain_param,
−
["head4"] = {},
+
−
["head5"] = {},
+
["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,
 +
}
 
 
−
["tr"] = {},
 
−
["tr2"] = {},
 
−
["tr3"] = {},
 
−
["tr4"] = {},
 
−
["tr5"] = {},
 
−
 
−
["g"] = {},
 
−
["g2"] = {},
 
−
["g3"] = {},
 
−
["g4"] = {},
 
−
["g5"] = {},
 
−
 
−
[3]  = {allow_empty = true}, [4]  = {}, ["f1accel"]  = {}, ["f1request"]  = {}, ["f1alt"]  = {}, ["f1sc"]  = {}, ["f1id"]  = {}, ["f1tr"]  = {}, ["f1g"]  = {}, ["f1qual"]  = {}, ["f1nolink"]  = {type = "boolean"}, ["f1lang"]  = {},
 
−
[5]  = {allow_empty = true}, [6]  = {}, ["f2accel"]  = {}, ["f2request"]  = {}, ["f2alt"]  = {}, ["f2sc"]  = {}, ["f2id"]  = {}, ["f2tr"]  = {}, ["f2g"]  = {}, ["f2qual"]  = {}, ["f2nolink"]  = {type = "boolean"}, ["f2lang"]  = {},
 
−
[7]  = {allow_empty = true}, [8]  = {}, ["f3accel"]  = {}, ["f3request"]  = {}, ["f3alt"]  = {}, ["f3sc"]  = {}, ["f3id"]  = {}, ["f3tr"]  = {}, ["f3g"]  = {}, ["f3qual"]  = {}, ["f3nolink"]  = {type = "boolean"}, ["f3lang"]  = {},
 
−
[9]  = {allow_empty = true}, [10] = {}, ["f4accel"]  = {}, ["f4request"]  = {}, ["f4alt"]  = {}, ["f4sc"]  = {}, ["f4id"]  = {}, ["f4tr"]  = {}, ["f4g"]  = {}, ["f4qual"]  = {}, ["f4nolink"]  = {type = "boolean"}, ["f4lang"]  = {},
 
−
[11] = {allow_empty = true}, [12] = {}, ["f5accel"]  = {}, ["f5request"]  = {}, ["f5alt"]  = {}, ["f5sc"]  = {}, ["f5id"]  = {}, ["f5tr"]  = {}, ["f5g"]  = {}, ["f5qual"]  = {}, ["f5nolink"]  = {type = "boolean"}, ["f5lang"]  = {},
 
−
[13] = {allow_empty = true}, [14] = {}, ["f6accel"]  = {}, ["f6request"]  = {}, ["f6alt"]  = {}, ["f6sc"]  = {}, ["f6id"]  = {}, ["f6tr"]  = {}, ["f6g"]  = {}, ["f6qual"]  = {}, ["f6nolink"]  = {type = "boolean"}, ["f6lang"]  = {},
 
−
[15] = {allow_empty = true}, [16] = {}, ["f7accel"]  = {}, ["f7request"]  = {}, ["f7alt"]  = {}, ["f7sc"]  = {}, ["f7id"]  = {}, ["f7tr"]  = {}, ["f7g"]  = {}, ["f7qual"]  = {}, ["f7nolink"]  = {type = "boolean"}, ["f7lang"]  = {},
 
−
[17] = {allow_empty = true}, [18] = {}, ["f8accel"]  = {}, ["f8request"]  = {}, ["f8alt"]  = {}, ["f8sc"]  = {}, ["f8id"]  = {}, ["f8tr"]  = {}, ["f8g"]  = {}, ["f8qual"]  = {}, ["f8nolink"]  = {type = "boolean"}, ["f8lang"]  = {},
 
−
[19] = {allow_empty = true}, [20] = {}, ["f9accel"]  = {}, ["f9request"]  = {}, ["f9alt"]  = {}, ["f9sc"]  = {}, ["f9id"] =  {}, ["f9tr"]  = {}, ["f9g"]  = {}, ["f9qual"]  = {}, ["f9nolink"]  = {type = "boolean"}, ["f9lang"]  = {},
 
−
[21] = {allow_empty = true}, [22] = {}, ["f10accel"] = {}, ["f10request"] = {}, ["f10alt"] = {}, ["f10sc"] = {}, ["f10id"] = {}, ["f10tr"] = {}, ["f10g"] = {}, ["f10qual"] = {}, ["f10nolink"] = {type = "boolean"}, ["f10lang"] = {},
 
−
[23] = {allow_empty = true}, [24] = {}, ["f11accel"] = {}, ["f11request"] = {}, ["f11alt"] = {}, ["f11sc"] = {}, ["f11id"] = {}, ["f11tr"] = {}, ["f11g"] = {}, ["f11qual"] = {}, ["f11nolink"] = {type = "boolean"}, ["f11lang"] = {},
 
−
[25] = {allow_empty = true}, [26] = {}, ["f12accel"] = {}, ["f12request"] = {}, ["f12alt"] = {}, ["f12sc"] = {}, ["f12id"] = {}, ["f12tr"] = {}, ["f12g"] = {}, ["f12qual"] = {}, ["f12nolink"] = {type = "boolean"}, ["f12lang"] = {},
 
−
[27] = {allow_empty = true}, [28] = {}, ["f13accel"] = {}, ["f13request"] = {}, ["f13alt"] = {}, ["f13sc"] = {}, ["f13id"] = {}, ["f13tr"] = {}, ["f13g"] = {}, ["f13qual"] = {}, ["f13nolink"] = {type = "boolean"}, ["f13lang"] = {},
 
−
[29] = {allow_empty = true}, [30] = {}, ["f14accel"] = {}, ["f14request"] = {}, ["f14alt"] = {}, ["f14sc"] = {}, ["f14id"] = {}, ["f14tr"] = {}, ["f14g"] = {}, ["f14qual"] = {}, ["f14nolink"] = {type = "boolean"}, ["f14lang"] = {},
 
−
[31] = {allow_empty = true}, [32] = {}, ["f15accel"] = {}, ["f15request"] = {}, ["f15alt"] = {}, ["f15sc"] = {}, ["f15id"] = {}, ["f15tr"] = {}, ["f15g"] = {}, ["f15qual"] = {}, ["f15nolink"] = {type = "boolean"}, ["f15lang"] = {},
 
−
[33] = {allow_empty = true}, [34] = {}, ["f16accel"] = {}, ["f16request"] = {}, ["f16alt"] = {}, ["f16sc"] = {}, ["f16id"] = {}, ["f16tr"] = {}, ["f16g"] = {}, ["f16qual"] = {}, ["f16nolink"] = {type = "boolean"}, ["f16lang"] = {},
 
−
}
 
−
 
−
function export.head_t(frame)
 
 
local args = require("Module:parameters").process(frame:getParent().args, params)
 
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 "und"
+
local data = {}
−
local sc = args["sc"]
+
data.lang = require("Module:languages").getByCode(args[1]) or require("Module:languages").err(args[1], 1)
−
local cat_sc = args["cat sc"]
+
data.sort_key = args["sort"]
−
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
+
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 cat_sc then
+
if args["cat sc"] then
−
cat_sc = (cat_sc and (require("Module:scripts").getByCode(cat_sc) or error("The script code \"" .. cat_sc .. "\" is not valid.")) or nil)
+
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)
−
sc = cat_sc
+
cat_sc = cat_sc
 
else
 
else
−
sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
+
data.sc = (args["sc"] and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. args["sc"] .. "\" is not valid.")) or nil)
 
end
 
end
 
 
−
-- Gather basic parameters
+
-- Part-of-speech category
−
local sort_key = args["sort"]
+
data.pos_category = args[2]
−
local pos = args[2]
 
−
local cat2 = args["cat2"]
 
−
local cat3 = args["cat3"]
 
 
 
−
-- Gather headwords and transliterations
+
if not data.pos_category:find("s$") and not invariable[data.pos_category] then
−
local heads = {}
+
-- Make the plural form of the part of speech
−
local translits = {}
+
if data.pos_category:find("x$") then -- prefix, suffix, confix, infix, circumfix, affix, interfix, transfix
−
local head = args["head"] or ""
+
data.pos_category = data.pos_category .. "es"
−
local translit = args["tr"]
+
else
−
local i = 1
+
data.pos_category = data.pos_category .. "s"
 +
end
 +
end
 
 
−
while head do
+
if cat_sc then
−
if head then
+
data.pos_category = data.pos_category .. " in " .. cat_sc:getCategoryName()
−
table.insert(heads, head)
 
−
translits[#heads] = translit
 
−
end
 
−
 
−
i = i + 1
 
−
head = args["head" .. i]
 
−
translit = args["tr" .. i]
 
 
end
 
end
 
 
−
-- Gather gender and number specifications
+
-- Additional categories
−
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
+
data.categories = {}
−
local genders = {}
 
−
local g = args["g"]
 
−
local i = 2
 
 
 
−
while g do
+
if args["cat2"] then
−
table.insert(genders, g)
+
table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat2"])
−
g = args["g" .. i]
 
−
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"]
+
end
−
local request = args["f" .. i .. "request"]
 
−
local parts = {label = label, accel = accel, request = request}
 
 
 
−
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]
+
local infl_part = {
−
local alt = args["f" .. i .. "alt"]
+
label    = args[3][i * 2 - 1],
−
local sc = args["f" .. i .. "sc"]
+
accel    = args["faccel"][i],
−
local id = args["f" .. i .. "id"]
+
request  = args["frequest"][i],
−
local translit = args["f" .. i .. "tr"]
+
}
−
local gender = args["f" .. i .. "g"]
 
−
local qualifier = args["f" .. i .. "qual"]
 
−
local nolink = args["f" .. i .. "nolink"]
 
−
local lang = args["f" .. i .. "lang"]
 
 
 
−
if lang ~= nil then
+
local form = {
−
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
+
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
 
end
 
 
−
if term or alt then
+
if form.sc then
−
if sc then
+
form.sc = require("Module:scripts").getByCode(form.sc) or error("The script code \"" .. form.sc .. "\" is not valid.")
−
m_scripts = m_scripts or require("Module:scripts")
 
−
sc = (sc and (m_scripts.getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
 
−
end
 
−
 
−
table.insert(parts, {term = term, alt = alt, sc = sc, id = id, translit = translit, genders = {gender}, qualifiers = {qualifier}, nolink = nolink, lang = lang})
 
 
end
 
end
 
 
−
i = i + 1
+
-- If no term or alt is given, then the label is shown alone.
−
label = args[i * 2 + 1]
+
if form.term or form.alt then
−
accel = args["f" .. i .. "accel"]
+
table.insert(infl_part, form)
−
request = args["f" .. i .. "request"]
+
end
 
 
−
-- If the next label is not "or" then insert the previous one and create a new one.
+
if infl_part.label == "or" then
−
if label ~= "or" then
+
-- Append to the previous inflection part, if one exists
−
-- Only insert if the previous label is not empty.
+
if #infl_part > 0 and data.inflections[1] then
−
if (parts.label or "") ~= "" then
+
table.insert(data.inflections[#data.inflections], form)
−
table.insert(inflections, parts)
 
 
end
 
end
−
+
elseif infl_part.label then
−
parts = {label = label, accel = accel, request = request}
+
-- Add a new inflection part
 +
table.insert(data.inflections, infl_part)
 
end
 
end
 
end
 
end
 
 
−
-- Get/set categories
+
return require("Module:headword").full_headword(data)
−
local categories = {}
 
−
local tracking_categories = {}
 
−
 
−
if pos then
 
−
if not pos:find("s$") and not invariable[pos] then
 
−
--require("Module:debug").track("head tracking/singular category")
 
−
 
−
-- Make the plural form of the part of speech
 
−
if pos:find("x$") then
 
−
pos = pos .. "es"
 
−
else
 
−
pos = pos .. "s"
 
−
end
 
−
end
 
−
 
−
table.insert(categories, lang:getCanonicalName() .. " " .. pos .. (cat_sc and " in " .. cat_sc:getCategoryName() or ""))
 
−
end
 
−
 
−
if cat2 then
 
−
table.insert(categories, lang:getCanonicalName() .. " " .. cat2)
 
−
end
 
−
 
−
if cat3 then
 
−
table.insert(categories, lang:getCanonicalName() .. " " .. cat3)
 
−
end
 
−
 
−
return require("Module:headword").full_headword(lang, sc, heads, translits, genders, inflections, categories, sort_key) ..
 
−
require("Module:utilities").format_categories(tracking_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