Module:form of: Difference between revisions

From Laenkea
Jump to navigation Jump to search
(Created page with "local export = {} local m_links = require("Module:links") local labels = { ["1"] = {label = "first-person", glossary = "first person"}, ["2"] = {label = "second-person", glossary = "second person"}, ["3"] = {label = "third-person", glossary = "third person"}, ["singular"] = {label = "singular", glossary = true}, ["dual"] = {label = "dual", glossary = true}, ["plural"] = {label = "plural", glossary = true}, ["inclusive"] = {label = "inclusive", glossary = "clusiv...")
 
No edit summary
 
(30 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local export = {}
local export = {}


local m_labels = require("Module:labels")
local m_links = require("Module:links")
local m_links = require("Module:links")
local m_data = mw.loadData("Module:form of/data")


local labels = {
local function pluralize(word)
["1"] = {label = "first-person", glossary = "first person"},
local ending = mw.ustring.sub(word, -1)
["2"] = {label = "second-person", glossary = "second person"},
if ending == "h" and mw.ustring.sub(word, -2, -1) == "s" then ending = "sh" end
["3"] = {label = "third-person", glossary = "third person"},
if ending == "s" or ending == "z" or ending == "x" or ending == "sh" then
["singular"] = {label = "singular", glossary = true},
return word .. "es"
["dual"] = {label = "dual", glossary = true},
end
["plural"] = {label = "plural", glossary = true},
return word .. "s"
["inclusive"] = {label = "inclusive", glossary = "clusivity"},
end
["exclusive"] = {label = "exclusive", glossary = "clusivity"},
["impersonal"] = {label = "impersonal", glossary = true},
["depersonal"] = {label = "depersonal", glossary = true},
["active"] = {label = "active", glossary = "active voice"},
["passive"] = {label = "passive", glossary = "passive voice"},
["mediopassive"] = {label = "mediopassive", glossary = "mediopassive voice"},
["indicative"] = {label = "indicative", glossary = "indicative mood"},
["subjunctive"] = {label = "subjunctive", glossary = "subjunctive mood"},
["conditional"] = {label = "conditional", glossary = "conditional mood"},
["optative"] = {label = "optative", glossary = "optative mood"},
["imperative"] = {label = "imperative", glossary = "imperative mood"},
["past"] = {label = "past", glossary = "past tense"},
["nonpast"] = {label = "non-past", glossary = "non-past tense"},
["future"] = {label = "future", glossary = "future tense"},
["aorist"] = {label = "aorist", glossary = "aorist tense"},
["negative"] = {label = "negative", glossary = true},
["interrogative"] = {label = "interrogative", glossary = true},
["perfective"] = {label = "perfective", glossary = "perfective aspect"},
["imperfective"] = {label = "imperfective", glossary = "imperfective aspect"},
["habitual"] = {label = "habitual", glossary = "habitual aspect"},
["humble"] = {label = "humble", glossary = true},
["animate"] = {label = "animate", glossary = true},
["inanimate"] = {label = "inanimate", glossary = true},
["nominative"] = {label = "nominative", glossary = "nominative case"},
["accusative"] = {label = "accusative", glossary = "accusative case"},
}
local aliases = {
["sg"] = "singular",
["s"] = "singular",
["du"] = "dual",
["d"] = "du",
["pl"] = "plural",
["p"] = "pl",
["inc"] = "inclusive",
["incl"] = "inclusive",
["exc"] = "exclusive",
["excl"] = "exclusive",
["impers"] = "impersonal",
["impr"] = "impersonal",
["deper"] = "depersonal",
["depers"] = "depersonal",
["act"] = "active",
["pass"] = "passive",
["ind"] = "indicative",
["subj"] = "subjunctive",
["sbj"] = "subjunctive",
["sjv"] = "subjunctive",
["cond"] = "conditional",
["opt"] = "optative",
["imp"] = "imperative",
["pst"] = "past",
["npst"] = "nonpast",
["fut"] = "future",
["aor"] = "aorist",
["neg"] = "negative",
["interr"] = "interrogative",
["intrg"] = "interrogative",
["anim"] = "animate",
["an"] = "animate",
["in"] = "inanimate",
["inan"] = "inanimate",
["nom"] = "nominative",
["acc"] = "accusative",
}


local function make_labels(inflections)
local function make_labels(inflections, language)
local out = {}
local out = {}
for _, inflection in ipairs(inflections) do
if aliases[inflection] then inflection = aliases[inflection] end
if inflections[1] == nil then return "inflection" end
local l = labels[inflection]
 
-- split parameters at / and ,
local it = 1
while inflections[it] do
if mw.ustring.find(inflections[it], "^[^,]+,%s.+") then
local before = mw.ustring.gsub(inflections[it], "^([^,]+),%s*(.+)", "%1")
local after = mw.ustring.gsub(inflections[it], "^([^,]+),%s*(.+)", "%2")
inflections[it] = before
table.insert(inflections, it + 1, after)
end
if mw.ustring.find(inflections[it], "^[^/]+/.+") then
local before = mw.ustring.gsub(inflections[it], "^([^/]+)/(.+)", "%1")
local after = mw.ustring.gsub(inflections[it], "^([^/]+)/(.+)", "%2")
inflections[it] = before
table.insert(inflections, it + 1, after)
table.insert(inflections, it + 1, "/")
end
it = it + 1
end
for i, inflection in ipairs(inflections) do
if m_data.aliases[inflection] then inflection = m_data.aliases[inflection] end
local l = m_data.labels[inflection]
if l then
if l then
local text = l.label or inflection
local text = l.label or inflection
if l.glossary then
if l.glossary then
table.insert(out, "[[Appendix:Glossary#" .. (type(l.glossary) == "string" and l.glossary or text) .. "]]")
glosslink = "[[Appendix:Glossary#" .. (type(l.glossary) == "string" and l.glossary or text) .. "|" .. text .. "]]"
if text == "verbal noun" then
glosslink = glosslink .. "[[Category:" .. language.name .. " verbal nouns]]"
end
table.insert(out, glosslink)
else
else
table.insert(out, text)
table.insert(out, text)
Line 90: Line 54:
else
else
table.insert(out, inflection)
table.insert(out, inflection)
end
if inflection ~= "/" and inflections[i+1] ~= "/" and inflections[i+1] then
table.insert(out, " ")
end
end
end
end
return table.concat(out, " ")
return table.concat(out)
end
end


Line 98: Line 65:
local label
local label
local link = m_links.full_link(data, "term")
local link = m_links.full_link(data, "term")
local note = data.note
if note then
if mw.ustring.find(note, "^%P") then
note = " " .. note
end
else
note = ""
end
if data.inflection then
label = make_labels(data.inflection, data.language)
else
label = m_labels.make_labels(data.language, {[1] = data.form or "alternative form"}, data.nocat, true)
end
return '<span class="form-of">' .. label .. ((data.post and (" ".. data.post)) or "") .. ' of ' .. link .. note .. '</span>'
end
function export.list_form(data)
local label
if data.inflection then
if data.inflection then
label = make_labels(data.inflection)
label = make_labels(data.inflection, data.language)
else
else
label = data.form or "alternative form"
label = data.form or "alternative form"
end
end
return "''" .. label .. " of " .. link .. "''"
return '<span class="form-of">' .. label .. '</span>'
end
end


return export
return export

Latest revision as of 12:24, 17 August 2024

local export = {}

local m_labels = require("Module:labels")
local m_links = require("Module:links")
local m_data = mw.loadData("Module:form of/data")

local function pluralize(word)
	local ending = mw.ustring.sub(word, -1)
	if ending == "h" and mw.ustring.sub(word, -2, -1) == "s" then ending = "sh" end
	if ending == "s" or ending == "z" or ending == "x" or ending == "sh" then
		return word .. "es"
	end
	return word .. "s"
end

local function make_labels(inflections, language)
	local out = {}
	
	if inflections[1] == nil then return "inflection" end

	-- split parameters at / and ,
	local it = 1
	while inflections[it] do
		if mw.ustring.find(inflections[it], "^[^,]+,%s.+") then
			local before = mw.ustring.gsub(inflections[it], "^([^,]+),%s*(.+)", "%1")
			local after = mw.ustring.gsub(inflections[it], "^([^,]+),%s*(.+)", "%2")
			inflections[it] = before
			table.insert(inflections, it + 1, after)
		end
		if mw.ustring.find(inflections[it], "^[^/]+/.+") then
			local before = mw.ustring.gsub(inflections[it], "^([^/]+)/(.+)", "%1")
			local after = mw.ustring.gsub(inflections[it], "^([^/]+)/(.+)", "%2")
			inflections[it] = before
			table.insert(inflections, it + 1, after)
			table.insert(inflections, it + 1, "/")
		end
		it = it + 1
	end
	
	for i, inflection in ipairs(inflections) do
		if m_data.aliases[inflection] then inflection = m_data.aliases[inflection] end
		local l = m_data.labels[inflection]
		if l then
			local text = l.label or inflection
			if l.glossary then
				glosslink = "[[Appendix:Glossary#" .. (type(l.glossary) == "string" and l.glossary or text) .. "|" .. text .. "]]"
				if text == "verbal noun" then
					glosslink = glosslink .. "[[Category:" .. language.name .. " verbal nouns]]"
				end
				table.insert(out, glosslink)
			else
				table.insert(out, text)
			end
		else
			table.insert(out, inflection)
		end
		if inflection ~= "/" and inflections[i+1] ~= "/" and inflections[i+1] then
			table.insert(out, " ")
		end
	end
	return table.concat(out)
end

function export.make_form_of(data)
	local label
	local link = m_links.full_link(data, "term")
	local note = data.note
	if note then
		if mw.ustring.find(note, "^%P") then
			note = " " .. note
		end
	else
		note = ""
	end
	if data.inflection then
		label = make_labels(data.inflection, data.language)
	else
		label = m_labels.make_labels(data.language, {[1] = data.form or "alternative form"}, data.nocat, true)
	end
	return '<span class="form-of">' .. label .. ((data.post and (" ".. data.post)) or "") .. ' of ' .. link .. note .. '</span>'
end

function export.list_form(data)
	local label
	if data.inflection then
		label = make_labels(data.inflection, data.language)
	else
		label = data.form or "alternative form"
	end
	return '<span class="form-of">' .. label .. '</span>'
end

return export