Jump to content

Module:Labels

From Yezur Wiki

This is the documentation for Module:Labels, the sense-label renderer for the Yezur wiki's Dictionary. It is not called directly: Template:Lb invokes it as {{#invoke:Labels|lb|CODE|label1|label2|…}}, passing a language code and up to seven labels. The module returns those labels comma-joined, italicised and parenthesised, in the order given — {{lb|YAP-XX|by extension}} renders (by extension) at the head of a definition line — and appends a per-language category for each label it recognises. When no label survives trimming it returns nothing at all.

Parameters

Parameter Purpose
1 The language code, such as YBS-PJ. It is trimmed and matched without regard to case in Module:Languages, which supplies the display name used in the category titles; the code itself is never shown.
2, 3, … The labels, in display order. Each is trimmed, and empty values are skipped. Reading stops at the first argument that is absent altogether, which only affects direct invocation: Template:Lb always supplies slots 2 to 8, so unfilled slots between filled ones do no harm.

Categorising labels

A label in the table below files the page into a category named after the language, written Lang here: under YBS-PJ, transitive adds Category:Pjany transitive verbs. Recognition ignores case, but only a shorthand is rewritten — the shorthands in the second column are replaced by the canonical label before display, whereas a canonical label is shown exactly as typed, so Transitive renders (Transitive) and categorises all the same.

Label Shorthand Category
Verbs
transitive tr Lang transitive verbs
intransitive intr Lang intransitive verbs
ambitransitive Lang ambitransitive verbs
ditransitive ditr Lang ditransitive verbs
ergative Lang ergative verbs
reflexive Lang reflexive verbs
impersonal Lang impersonal verbs
copulative Lang copulative verbs
auxiliary Lang auxiliary verbs
modal Lang modal verbs
causative Lang causative verbs
deponent Lang deponent verbs
pronominal Lang pronominal verbs
reciprocal Lang reciprocal verbs
Nouns
countable count Lang countable nouns
uncountable uncount Lang uncountable nouns
collective Lang collective nouns
singular only Lang singular-only nouns
plural only Lang plural-only nouns
attributive Lang attributive terms
Adjectives
comparable Lang comparable adjectives
not comparable Lang uncomparable adjectives
predicative Lang predicative-only terms
Register and usage
slang Lang slang
colloquial colloq Lang colloquialisms
informal Lang informal terms
formal Lang formal terms
vulgar Lang vulgarities
derogatory derog Lang derogatory terms
offensive Lang offensive terms
slur Lang slurs
euphemistic euph Lang euphemisms
dysphemistic Lang dysphemisms
humorous hum Lang humorous terms
endearing Lang terms of endearment
familiar Lang familiar terms
childish Lang childish terms
honorific Lang honorifics
humble Lang humble terms
polite Lang polite terms
solemn Lang solemn terms
poetic Lang poetic terms
literary Lang literary terms
journalistic Lang journalistic terms
technical Lang technical terms
rustic Lang rustic terms
proscribed Lang proscribed terms
nonstandard Lang nonstandard terms
dialectal Lang dialectal terms
Temporal
archaic arch Lang archaic terms
dated Lang dated terms
obsolete obs Lang obsolete terms
historical Lang historical terms
rare Lang rare terms
uncommon Lang uncommon terms
neologism Lang neologisms
Word formation
abbreviation Lang abbreviations
acronym Lang acronyms
initialism Lang initialisms
contraction Lang contractions
onomatopoeia Lang onomatopoeias
misspelling Lang misspellings
eye dialect Lang eye dialect

One further shorthand, fig, expands to figurative, which is not a categorising label.

A label absent from the table is shown exactly as typed and adds no category, so domain tags such as nautical or botany and semantic qualifiers such as figurative or idiomatic work without any entry here. The categorising set is deliberately partial and is meant to grow as the category scheme is settled; it is curated from Wiktionary's label data, keeping the universal linguistic labels — valency, register, temporal, word formation — and leaving out the topical and regional domains.

Categories are added only when the code resolves in Module:Languages; an unknown or missing code still displays the labels, uncategorised. The module adds membership only — it does not create the category description pages, and most of the categories above are as yet empty.

For the division of labour between a per-sense label and the per-word register field of {{head}}, see Template:Lb.


-- Module:Labels — inline sense labels for Dictionary definitions, after the
-- fashion of Wiktionary's {{lb}}. Renders italic, parenthesised context /
-- register / domain labels immediately before a sense, and (for labels it
-- knows) files the page into a per-language maintenance category. Backs {{lb}}.
--
-- The categorising vocabulary below is curated from Wiktionary's own label set
-- (Module:labels/data), keeping the universal linguistic labels — valency,
-- register, temporal, word-formation — and dropping everything Earth-specific
-- (named real-world slangs, scripts, places, religions, and all 900+ topical /
-- regional domains). Any label NOT listed still displays, verbatim, with no
-- category — so domain tags (nautical, law, botany, …) and semantic qualifiers
-- (figurative, idiomatic, by extension, …) just work as plain text. Grow the
-- categorising set here as the category scheme is decided.

local Languages = require('Module:Languages')

local p = {}

-- convenient shorthands -> canonical label
local ALIASES = {
	["tr"]      = "transitive",
	["intr"]    = "intransitive",
	["ditr"]    = "ditransitive",
	["count"]   = "countable",
	["uncount"] = "uncountable",
	["fig"]     = "figurative",
	["colloq"]  = "colloquial",
	["derog"]   = "derogatory",
	["obs"]     = "obsolete",
	["arch"]    = "archaic",
	["hum"]     = "humorous",
	["euph"]    = "euphemistic",
}

-- canonical label -> category suffix; {lang} is replaced by the language's
-- display name, e.g. "slang" -> "Pjany slang".
local CATS = {
	-- verbs (valency / type)
	["transitive"]     = "{lang} transitive verbs",
	["intransitive"]   = "{lang} intransitive verbs",
	["ambitransitive"] = "{lang} ambitransitive verbs",
	["ditransitive"]   = "{lang} ditransitive verbs",
	["ergative"]       = "{lang} ergative verbs",
	["reflexive"]      = "{lang} reflexive verbs",
	["impersonal"]     = "{lang} impersonal verbs",
	["copulative"]     = "{lang} copulative verbs",
	["auxiliary"]      = "{lang} auxiliary verbs",
	["modal"]          = "{lang} modal verbs",
	["causative"]      = "{lang} causative verbs",
	["deponent"]       = "{lang} deponent verbs",
	["pronominal"]     = "{lang} pronominal verbs",
	["reciprocal"]     = "{lang} reciprocal verbs",
	-- nouns
	["countable"]      = "{lang} countable nouns",
	["uncountable"]    = "{lang} uncountable nouns",
	["collective"]     = "{lang} collective nouns",
	["singular only"]  = "{lang} singular-only nouns",
	["plural only"]    = "{lang} plural-only nouns",
	["attributive"]    = "{lang} attributive terms",
	-- adjectives
	["comparable"]     = "{lang} comparable adjectives",
	["not comparable"] = "{lang} uncomparable adjectives",
	["predicative"]    = "{lang} predicative-only terms",
	-- register / usage
	["slang"]        = "{lang} slang",
	["colloquial"]   = "{lang} colloquialisms",
	["informal"]     = "{lang} informal terms",
	["formal"]       = "{lang} formal terms",
	["vulgar"]       = "{lang} vulgarities",
	["derogatory"]   = "{lang} derogatory terms",
	["offensive"]    = "{lang} offensive terms",
	["slur"]         = "{lang} slurs",
	["euphemistic"]  = "{lang} euphemisms",
	["dysphemistic"] = "{lang} dysphemisms",
	["humorous"]     = "{lang} humorous terms",
	["endearing"]    = "{lang} terms of endearment",
	["familiar"]     = "{lang} familiar terms",
	["childish"]     = "{lang} childish terms",
	["honorific"]    = "{lang} honorifics",
	["humble"]       = "{lang} humble terms",
	["polite"]       = "{lang} polite terms",
	["solemn"]       = "{lang} solemn terms",
	["poetic"]       = "{lang} poetic terms",
	["literary"]     = "{lang} literary terms",
	["journalistic"] = "{lang} journalistic terms",
	["technical"]    = "{lang} technical terms",
	["rustic"]       = "{lang} rustic terms",
	["proscribed"]   = "{lang} proscribed terms",
	["nonstandard"]  = "{lang} nonstandard terms",
	["dialectal"]    = "{lang} dialectal terms",
	-- temporal
	["archaic"]    = "{lang} archaic terms",
	["dated"]      = "{lang} dated terms",
	["obsolete"]   = "{lang} obsolete terms",
	["historical"] = "{lang} historical terms",
	["rare"]       = "{lang} rare terms",
	["uncommon"]   = "{lang} uncommon terms",
	["neologism"]  = "{lang} neologisms",
	-- word-formation / form
	["abbreviation"] = "{lang} abbreviations",
	["acronym"]      = "{lang} acronyms",
	["initialism"]   = "{lang} initialisms",
	["contraction"]  = "{lang} contractions",
	["onomatopoeia"] = "{lang} onomatopoeias",
	["misspelling"]  = "{lang} misspellings",
	["eye dialect"]  = "{lang} eye dialect",
}

local function langname(code)
	local l = Languages._get(code)
	return (l and l.name) or ""
end

-- {{#invoke:Labels|lb|CODE|label1|label2|...}}
function p.lb(frame)
	local a = frame.args
	local lang = langname(a[1])
	local shown, cats = {}, {}
	local i = 2
	while a[i] ~= nil do
		local raw = mw.text.trim(a[i])
		if raw ~= "" then
			local canon = ALIASES[raw:lower()] or raw
			shown[#shown + 1] = canon
			local suffix = CATS[canon:lower()]
			if suffix and lang ~= "" then
				cats[#cats + 1] = "[[Category:" .. suffix:gsub("{lang}", lang) .. "]]"
			end
		end
		i = i + 1
	end
	if #shown == 0 then return "" end
	return "''(" .. table.concat(shown, ", ") .. ")''" .. table.concat(cats)
end

return p