Modulis:headword/templates

No ''Wiktionary''

Šī moduļa dokumentāciju var izveidot Modulis:headword/templates/doc lapā

local export = {}

local lemmas = {
	["abbreviation"] = true,
	["acronym"] = true,
	["adjective"] = true,
	["adposition"] = true,
	["adverb"] = true,
	["affix"] = true,
	["article"] = true,
	["circumfix"] = true,
	["circumposition"] = true,
	["classifier"] = true,
	["cmavo"] = true,
	["cmavo cluster"] = true,
	["cmene"] = true,
	["saikļ"] = true,
	["contraction"] = true,
	["counter"] = true,
	["determiner"] = true,
	["diacritical mark"] = true,
	["fu'ivla"] = true,
	["gismu"] = true,
	["Han tu"] = true,
	["hanzi"] = true,
	["hanja"] = true,
	["idiom"] = true,
	["infix"] = true,
	["interfix"] = true,
	["initialism"] = true,
	["interjection"] = true,
	["kanji"] = true,
	["letter"] = true,
	["ligature"] = true,
	["lujvo"] = true,
	["morpheme"] = true,
	["non-constituent"] = true,
	["lietvārd"] = true,
	["number"] = true,
	["numeral"] = true,
	["particle"] = true,
	["phrase"] = true,
	["postposition"] = true,
	["predicative"] = true,
	["prefix"] = true,
	["preposition"] = true,
	["prepositional phrase"] = true,
	["preverb"] = true,
	["vietniekvārd"] = true,
	["proverb"] = true,
	["proper noun"] = true,
	["punctuation mark"] = true,
	["root"] = true,
	["suffix"] = true,
	["syllable"] = true,
	["symbol"] = true,
	["darbības vārd"] = true,
}

local nonlemmas = {
	["active participle"] = true,
	["adjectival participle"] = true,
	["adjective form"] = true,
	["adjective comparative form"] = true,
	["adjective superlative form"] = true,
	["adverb form"] = true,
	["adverb comparative form"] = true,
	["adverb superlative form"] = true,
	["adverbial participle"] = true,
	["agent participle"] = true,
	["article form"] = true,
	["circumfix form"] = true,
	["combined form"] = true,
	["comparative adjective"] = true,
	["comparative adverb"] = true,
	["determiner comparative form"] = true,
	["determiner form"] = true,
	["determiner superlative form"] = true,
	["diminutive noun"] = true,
	["gerund"] = true,
	["infinitive"] = true,
	["jyutping"] = true,
	["kanji reading"] = true,
	["misspelling"] = true,
	["negative participle"] = true,
	["nominal participle"] = true,
	["noun case form"] = true,
	["noun form"] = true,
	["noun plural form"] = true,
	["numeral form"] = true,
	["participle"] = true,
	["participle form"] = true,
	["particle form"] = true,
	["passive participle"] = true,
	["past active participle"] = true,
	["past participle"] = true,
	["past participle form"] = true,
	["past passive participle"] = true,
	["perfect active participle"] = true,
	["perfect passive participle"] = true,
	["pinyin"] = true,
	["plural"] = true,
	["postposition form"] = true,
	["prefix form"] = true,
	["preposition contraction"] = true,
	["preposition form"] = true,
	["prepositional pronoun"] = true,
	["present active participle"] = true,
	["present participle"] = true,
	["present passive participle"] = true,
	["pronoun form"] = true,
	["proper noun form"] = true,
	["rafsi"] = true,
	["romanization"] = true,
	["romaji"] = true,
	["singulative"] = true,
	["suffix form"] = true,
	["superlative adjective"] = true,
	["superlative adverb"] = true,
	["verb form"] = true,
	["verbal noun"] = true,
}

local 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,
}

function export.head_t(frame)
	local args = frame:getParent().args
	
	-- 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 sc = args["sc"] or ""; if sc == "" then sc = nil end
	lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	-- Gather basic parameters
	local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
	local pos = args[2]; if pos == "" then pos = nil end
	local cat = args["cat"]; if cat == "" then cat = nil end
	local cat2 = args["cat2"]; if cat2 == "" then cat2 = nil end
	local cat3 = args["cat3"]; if cat3 == "" then cat3 = nil end
	local tr = args["tr"]; if tr == "" then tr = nil end
	
	-- Gather headwords
	local head = args["head"]
	local heads = {head or ""}
	local i = 2
	head = args["head" .. i]
	
	while head do
		if head ~= "" then
			table.insert(heads, head)
		end
		
		i = i + 1
		head = args["head" .. i]
	end
	
	-- Gather gender and number specifications
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	local genders = {}
	local g = args["g"]; if g == "" then g = nil end
	local i = 2
	
	while g do
		table.insert(genders, g)
		g = args["g" .. i]; if g == "" then g = nil end
		i = i + 1
	end
	
	-- Gather inflected forms
	local inflections = {}
	
	local i = 1
	local label = args[i * 2 + 1]
	local accel = args["f" .. i .. "accel"]; if accel == "" then accel = nil 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
	
	while label do
		local term = args[i * 2 + 2]; if term == "" then term = nil end
		local alt = args["f" .. i .. "alt"]; if alt == "" then alt = nil end
		local sc = args["f" .. i .. "sc"]; if sc == "" then sc = nil end
		local id = args["f" .. i .. "id"]; if id == "" then id = nil end
		local gender = args["f" .. i .. "g"]; if gender == "" then gender = nil end
		
		if term or alt then
			if sc then
				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, genders = {gender}})
		end
		
		i = i + 1
		label = args[i * 2 + 1]
		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
	
	-- Get/set categories
	local categories = {}
	
	if cat then
		table.insert(categories, lang:getCanonicalName() .. " " .. cat)
		
		if pos then
			table.insert(categories, "head tracking/with cat/with pos")
			require("Module:debug").track("head tracking/with cat")
		else
			table.insert(categories, "head tracking/with cat/no pos")
			require("Module:debug").track("head tracking/no pos/lang")
			require("Module:debug").track("head tracking/no pos/lang/" .. lang:getCode())
		end
	elseif pos then
		if lemmas[pos] or lemmas[pos:gsub("^reconstructed ", "")] then
			table.insert(categories, lang:getCanonicalName() .. " lemmas")
		elseif nonlemmas[pos] or nonlemmas[pos:gsub("^reconstructed ", "")] or lemmas[pos:gsub("^mutated ", "")] or nonlemmas[pos:gsub("^mutated ", "")] then
			table.insert(categories, lang:getCanonicalName() .. " non-lemma forms")
		else
			table.insert(categories, "head tracking/unrecognized pos")
			require("Module:debug").track("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
		
		-- Make the plural form of the part of speech
		if pos:find("x$") then
			pos = pos .. "es"
		elseif not invariable[pos] then
			pos = pos .. "i"
		end
		
		table.insert(categories, lang:getCanonicalName() .. " " .. pos)
	else
		table.insert(categories, "head tracking/no pos")
		require("Module:debug").track("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
	
	return
		require("Module:headword").full_headword(lang, sc, heads, tr, genders, inflections, categories, sort_key) ..
		require("Module:utilities").format_categories(categories, lang, sort_key)
end

return export