Modul:etymology/templates

Üdvözlöm, Ön a Modul:etymology/templates szó jelentését keresi. A DICTIOUS-ban nem csak a Modul:etymology/templates szó összes szótári jelentését megtalálod, hanem megismerheted az etimológiáját, a jellemzőit és azt is, hogyan kell a Modul:etymology/templates szót egyes és többes számban mondani. Minden, amit a Modul:etymology/templates szóról tudni kell, itt található. A Modul:etymology/templates szó meghatározása segít abban, hogy pontosabban és helyesebben fogalmazz, amikor beszélsz vagy írsz. AModul:etymology/templates és más szavak definíciójának ismerete gazdagítja a szókincsedet, és több és jobb nyelvi forráshoz juttat.

This module generates content for several etymology templates:


local export = {}

local m_languages = require("Module:languages")

local rsplit = mw.text.split
local rsubn = mw.ustring.gsub

-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
	local retval = rsubn(term, foo, bar)
	return retval
end

local function fetch_lang(lang, parameter)
	return m_languages.getByCode(lang) or m_languages.err(lang, parameter)
end


local function fetch_source(code, disallow_family)
	local source =
		m_languages.getByCode(code)
		or require("Module:etymology languages").getByCode(code)
		or not disallow_family and require("Module:families").getByCode(code)
	
	if source then
		return source
	else
		error("The language" .. (not disallow_family and ", family" or "") .. " or etymology language code \"" .. code .. "\" is not valid.")
	end
end


local function fetch_script(sc)
	if sc then
		return require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
	else
		return nil
	end
end


function export.etyl(frame)
	local params = {
		 = {required = true, default = "und"},
		 = {},
		 = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local source = fetch_source(args)
	local lang = args
	local sort_key = args
	
	-- Empty language means English, but "-" means no language. Yes, confusing...
	if not lang then
		lang = "en"
	elseif lang == "-" then
		lang = nil
	end
	if lang then
		lang = fetch_lang(lang, 2)
	end
	if lang and (lang:getCode() == "la" or lang:getCode() == "nl") then
		require("Module:debug").track("etyl/" .. lang:getCode())
		require("Module:debug").track("etyl/" .. lang:getCode() .. "/" .. source:getCode())
	end
	
	return require("Module:etymology").format_etyl(lang, source, sort_key)
end


function export.cognate(frame)
	local args = frame:getParent().args
	
	if args.gloss then
		require("Module:debug").track("cognate/gloss param")
	end
	
	local params = {
		 = {required = true, default = "und"},
		 = {},
		 = {alias_of = "alt"},
		 = {alias_of = "t"},
		
		 = {},
		 = {list = true},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {alias_of = "t"},
		 = {},
		 = {},
		 = {},
		
		 = {},
	}
	
	args = require("Module:parameters").process(args, params)
	
	local source = fetch_source(args)
	local sc = fetch_script(args)

	return require("Module:etymology").format_cognate(
		{
			lang = source,
			sc = sc,
			term = args,
			alt = args,
			id = args,
			genders = args,
			tr = args,
			ts = args,
			gloss = args,
			pos = args,
			lit = args
		},
		args)
end


function export.noncognate(frame)
	return export.cognate(frame)
end

local function parse_2_lang_args(frame, has_text, no_family)
	local params = {
		 = {required = true, default = "und"},
		 = {required = true, default = "und"},
		 = {},
		 = {alias_of = "alt"},
		 = {alias_of = "t"},
		
		 = {},
		 = {list = true},
		 = {alias_of = "t"},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
		
		 = {},
	}

	if has_text then
		params = {type = "boolean"}
		params = {type = "boolean"}
	end

	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = fetch_lang(args, 1)
	local source = fetch_source(args, no_family)
	local sc = fetch_script(args)

	return args, lang, {
		lang = source,
		sc = sc,
		term = args,
		alt = args,
		id = args,
		genders = args,
		tr = args,
		ts = args,
		gloss = args,
		pos = args,
		lit = args
	}
end
	

function export.derived(frame)
	local args, lang, term = parse_2_lang_args(frame)
	return require("Module:etymology").format_derived(lang, term, args)
end

function export.inherited(frame)
	local args, lang, term = parse_2_lang_args(frame, nil, "no family")
	return require("Module:etymology").format_inherited(lang, term, args)
end

function export.borrowed(frame)
	local args, lang, term = parse_2_lang_args(frame)
	return require("Module:etymology").format_borrowed(lang, term, args,
		false, true, "plain")
end

function export.learned_borrowing(frame)
	if frame:getParent().args.gloss then
		require("Module:debug").track("learned_borrowing/gloss param")
	end

	local args, lang, term = parse_2_lang_args(frame, "has text")
	return require("Module:etymology").format_borrowed(lang, term, args,
		args, args, "learned")
end

function export.semi_learned_borrowing(frame)
	if frame:getParent().args.gloss then
		require("Module:debug").track("semi_learned_borrowing/gloss param")
	end

	local args, lang, term = parse_2_lang_args(frame, "has text")
	return require("Module:etymology").format_borrowed(lang, term, args,
		args, args, "semi-learned")
end

function export.orthographic_borrowing(frame)
	if frame:getParent().args.gloss then
		require("Module:debug").track("orthographic_borrowing/gloss param")
	end

	local args, lang, term = parse_2_lang_args(frame, "has text")
	return require("Module:etymology").format_borrowed(lang, term, args,
		args, args, "orthographic")
end

function export.unadapted_borrowing(frame)
	if frame:getParent().args.gloss then
		require("Module:debug").track("unadapted_borrowing/gloss param")
	end

	local args, lang, term = parse_2_lang_args(frame, "has text")
	return require("Module:etymology").format_borrowed(lang, term, args,
		args, args, "unadapted")
end

function export.calque(frame)
	local args = frame:getParent().args
	
	-- More informative error message.
	if args or args or args or args then
		error("{{]}} no longer supports parameters beginning with etyl. " ..
			"The parameters supported are similar to those used by " ..
			"{{]}}, {{]}}, " ..
			"{{]}}. See ] for more.")
	end
	
	local args, lang, term = parse_2_lang_args(frame, "has text")
	return require("Module:etymology").calque(lang, term, args,
		args, args)
end

function export.partial_calque(frame)
	if frame:getParent().args.gloss then
		require("Module:debug").track("partial_calque/gloss param")
	end

	local args, lang, term = parse_2_lang_args(frame, "has text")
	return require("Module:etymology").partial_calque(lang, term, args,
		args, args)
end

function export.semantic_loan(frame)
	local args, lang, term = parse_2_lang_args(frame, "has text")
	return require("Module:etymology").format_semantic_loan(lang, term, args,
		args, args)
end

function export.psm(frame)
	local args, lang, term = parse_2_lang_args(frame, "has text")
	return require("Module:etymology").psm(lang, term, args,
		args, args)
end

local function qualifier(content)
	if content then
		return table.concat{
			'<span class="ib-brac qualifier-brac">(</span>',
			'<span class="ib-content qualifier-content">',
			content,
			'</span>',
			'<span class="ib-brac qualifier-brac">)</span>'
		}
	end
end

local function desc_or_desc_tree(frame, desc_tree)
	local params
	if desc_tree then
		params = {
			 = {required = true, default = "gem-pro"},
			 = {required = true, default = "*fuhsaz"},
			 = { type = "boolean" },
			 = { type = "boolean" },
			 = { type = "boolean" },
		}
	else
		params = {
			 = { required = true },
			 = {},
			 = { type = "boolean" }
		}
	end

	for k, v in pairs({
		 = {},
		 = { alias_of = "gloss" },
		 = {list = true},
		 = {},
		 = {},
		 = {},
		 = {},
		 = { alias_of = "gloss" },
		 = {},
		 = {},
		 = {},
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = { alias_of = "clq" },
		 = { alias_of = "clq" },
		 = { alias_of = "clq" },
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = {},
		 = { type = "boolean" },
	}) do
		params = v
	end

	local namespace = mw.title.getCurrentTitle().nsText

	local args
	if frame.args then
		args = require("Module:parameters").process(frame.args, params)
	else
		args = require("Module:parameters").process(frame:getParent().args, params)
	end

	if args.sandbox then
		if namespace == "" or namespace == "Reconstruction" then
			error('The sandbox module, Module:descendants tree/sandbox, should not be used in entries.')
		end
	end
	
	local lang = args
	local term = args
	local alt = args
	local gloss = args
	local tr = args
	local ts = args
	local sc = args
	local id = args
	
	if namespace == "Sablon" then
		if not ( sc or lang ) then
			sc = "Latn"
		end
		if not lang then
			lang = "en"
		end
		if not term then
			term = "word"
		end
	end
	
	lang = m_languages.getByCode(lang)
		or require("Module:etymology languages").getByCode(lang)
		or m_languages.err(lang, 1)
		
	local entryLang = require("Module:etymology").getNonEtymological(lang)
	
	if not desc_tree and entryLang:getType() == "family" then
		error("Cannot use language family code in ].")
	end
	
	if lang:getCode() ~= entryLang:getCode() then
		-- ]
		require("Module:debug").track("descendant/etymological")
		require("Module:debug").track("descendant/etymological/" .. lang:getCode())
	end
	
	if sc then
		sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
	end
	
	local languageName = lang:getCanonicalName()
	languageName = mw.ustring.gsub(languageName, "^Proto%-", "")

	local link = ""
	
	if term ~= "-" then
		link = require("Module:links").full_link(
			{
				lang = entryLang,
				sc = sc,
				term = term,
				alt = alt,
				id = id,
				tr = tr,
				ts = ts,
				genders = args,
				gloss = gloss,
				pos = args,
				lit = args,
			},
			nil,
			true)
	elseif ts or gloss or #args > 0 then
		-- ]
		require "Module:debug".track("descendant/no term")
		link = require("Module:links").full_link(
			{
				lang = entryLang,
				sc = sc,
				ts = ts,
				gloss = gloss,
				genders = args,
			},
			nil,
			true)
		link = link
			:gsub("<small>%</small> ", "")
			:gsub("<small>%</small>&nbsp;", "")
			:gsub("%]+ term requests%]%]", "")
	else -- display no link at all
		-- ]
		require "Module:debug".track("descendant/no term or annotations")
	end
	
	local function add_tooltip(text, tooltip)
		return '<span class="desc-arr" title="' .. tooltip .. '">' .. text .. '</span>'
	end
	
	local label, arrow, descendants, alts, semi_learned, calque, partial_calque, semantic_loan, qual
	
	if args then
		if sc then
			label = sc:getCanonicalName()
		else
			label = require("Module:scripts").findBestScript(term, lang):getCanonicalName()
		end
	else
		label = languageName
	end
	
	if args then
		arrow = add_tooltip("→", "borrowed")
	elseif args then
		arrow = add_tooltip("→", "learned borrowed")
	elseif args then
		arrow = add_tooltip("→", "semi-learned borrowing")
	elseif args then
		arrow = add_tooltip("→", "calque")
	elseif args then
		arrow = add_tooltip("→", "partial calque")
	elseif args then
		arrow = add_tooltip("→", "semantic loan")
	elseif args and not args then
		arrow = add_tooltip(">", "inherited")
	else
		arrow = ""
	end
	-- allow der=1 in conjunction with bor=1 to indicate e.g. English "pars recta"
	-- derived and borrowed from Latin "pars".
	if args then
		arrow = arrow .. add_tooltip("⇒", "reshaped by analogy or addition of morphemes")
	end
	
	if argsthen
		arrow = arrow .. add_tooltip("?", "uncertain")
	end

	local m_desctree
	if desc_tree or args then
		if args.sandbox or require("Module:yesno")(frame.args.sandbox, false) then
			m_desctree = require("Module:descendants tree/sandbox")
		else
			m_desctree = require("Module:descendants tree")
		end
	end

	if desc_tree then
		descendants = m_desctree.getDescendants(entryLang, term, id)
	end
	
	if desc_tree and not args or not desc_tree and args then
		-- ]
		require("Module:debug").track("desc/alts")
		alts = m_desctree.getAlternativeForms(entryLang, term)
	end
	
	if args then
		learned = " " .. qualifier("learned")
	else
		learned = ""
	end
	
	if args then
		semi_learned = " " .. qualifier("semi-learned")
	else
		semi_learned = ""
	end
	
	if args then
		calque = " " .. qualifier("calque")
	else
		calque = ""
	end
	
	if args then
		partial_calque = " " .. qualifier("partial calque")
	else
		partial_calque = ""
	end

	if args then
		semantic_loan = " " .. qualifier("semantic loan")
	else
		semantic_loan = ""
	end
	
	if args then
		qual = " " .. require("Module:qualifier").format_qualifier(args)
	else
		qual = ""
	end

	if args then
		return descendants
	end
	
	if arrow and arrow ~= "" then
		arrow = arrow .. " "
	end
	
	local linktext = table.concat{link, alts or "", learned, semi_learned, calque,
		partial_calque, semantic_loan, qual, descendants or ""}
	if args then
		return linktext
	elseif args then
		return arrow .. linktext
	else
		return table.concat{arrow, label, ":", linktext ~= "" and " " or "", linktext}
	end
end
	
function export.descendant(frame)
	return desc_or_desc_tree(frame, false) .. require("Module:TemplateStyles")("Module:etymology/style.css")
end

function export.descendants_tree(frame)
	return desc_or_desc_tree(frame, true)
end

-- Implementation of miscellaneous templates such as {{back-formation}}, {{clipping}},
-- {{ellipsis}}, {{rebracketing}}, and {{reduplication}} that have a single
-- associated term.
function export.misc_variant(frame)
	local params = {
		 = {required = true, default = "und"},
		 = {},
		 = {alias_of = "alt"},
		 = {alias_of = "t"},
		
		 = {},
		 = {alias_of = "t"},
		 = {list = true},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
		
		 = {type = "boolean"}, -- should be processed in the template itself
		 = {type = "boolean"},
		 = {type = "boolean"},
		 = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = fetch_lang(args, 1)
	local sc = fetch_script(args)

	local parts = {}
	if not args then
		table.insert(parts, frame.args)
	end
	if args or args then
		if not args then
			table.insert(parts, " ")
			table.insert(parts, frame.args or "of")
			table.insert(parts, " ")
		end
		table.insert(parts, require("Module:links").full_link(
			{
				lang = lang,
				sc = sc,
				term = args,
				alt = args,
				id = args,
				tr = args,
				ts = args,
				genders = args,
				gloss = args,
				pos = args,
				lit = args,
			},
			"term",
			true))
	end
	if not args and frame.args then
		local categories = {}
		table.insert(categories, lang:getCanonicalName() .. " " .. frame.args)
		table.insert(parts, require("Module:utilities").format_categories(categories, lang, args))
	end

	return table.concat(parts)
end


local function get_parsed_part(template, lang, args, terms, i)
	local term = terms
	local alt = args
	local id = args
	local sc = fetch_script(args)

	local tr = args
	local ts = args
	local gloss = args
	local pos = args
	local lit = args
	local g = args

	if not (term or alt or tr or ts) then
		require("Module:debug").track(template .. "/no term or alt or tr")
		return nil
	else
		return require("Module:links").full_link(
			{ term = term, alt = alt, id = id, lang = lang, sc = sc, tr = tr,
			ts = ts, gloss = gloss, pos = pos, lit = lit,
			genders = g and rsplit(g, ",") or {}
		}, "term", true)
	end
end


local function get_parsed_parts(template, lang, args, terms)
	local parts = {}

	-- Find the maximum index among any of the list parameters.
	local maxmaxindex = 0
	for k, v in pairs(args) do
		if type(v) == "table" and v.maxindex and v.maxindex > maxmaxindex then
			maxmaxindex = v.maxindex
		end
	end

	for index = 1, maxmaxindex do
		table.insert(parts, get_parsed_part(template, lang, args, terms, index))
	end
	
	return parts
end


-- Implementation of miscellaneous templates such as {{doublet}} that can take
-- multiple terms. Doesn't handle {{blend}} or {{univerbation}}, which display
-- + signs between elements and use compound_like in ].
function export.misc_variant_multiple_terms(frame)
	local params = {
		 = {required = true, default = "und"},
		 = {list = true, allow_holes = true},

		 = {list = true, allow_holes = true, require_index = true},
		 = {list = true, allow_holes = true, require_index = true, alias_of = "t"},
		 = {list = true, allow_holes = true, require_index = true},
		 = {list = true, allow_holes = true, require_index = true},
		 = {list = true, allow_holes = true, require_index = true},
		 = {list = true, allow_holes = true, require_index = true},
		 = {list = true, allow_holes = true, require_index = true},
		 = {list = true, allow_holes = true, require_index = true},
		 = {list = true, allow_holes = true, require_index = true},
		 = {list = true, allow_holes = true, require_index = true},

		 = {type = "boolean"}, -- should be processed in the template itself
		 = {type = "boolean"},
		 = {type = "boolean"},
		 = {},
	}

	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = fetch_lang(args, 1)

	local parts = {}
	if not args then
		table.insert(parts, frame.args)
	end
	if #args > 0 or #args > 0 then
		if not args then
			table.insert(parts, " ")
			table.insert(parts, frame.args or "of")
			table.insert(parts, " ")
		end
		local formatted_terms = get_parsed_parts(mw.ustring.lower(
			-- Remove link and convert uppercase to lowercase to get an
			-- approximation of the original template name.
			rsub(rsub(frame.args, "^%%]$", "")),
			lang, args, args)
		table.insert(parts, require("Module:table").serialCommaJoin(formatted_terms))
	end
	if not args and frame.args then
		local categories = {}
		table.insert(categories, lang:getCanonicalName() .. " " .. frame.args)
		table.insert(parts, require("Module:utilities").format_categories(categories, lang, args))
	end

	return table.concat(parts)
end


-- Implementation of miscellaneous templates such as {{unknown}} that have no
-- associated terms.
function export.misc_variant_no_term(frame)
	local params = {
		 = {required = true, default = "und"},

		 = {},
		 = {type = "boolean"}, -- should be processed in the template itself
		 = {type = "boolean"},
		 = {type = "boolean"},
		 = {},
	}

	if frame.args then
		params = {alias_of = "title"}
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = fetch_lang(args, 1)

	local parts = {}
	if not args then
		table.insert(parts, args or frame.args)
	end
	if not args and frame.args then
		local categories = {}
		table.insert(categories, lang:getCanonicalName() .. " " .. frame.args)
		table.insert(parts, require("Module:utilities").format_categories(categories, lang, args))
	end

	return table.concat(parts)
end

return export