Module:pollasena-roots: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 14: | Line 14: | ||
local export = {} | local export = {} | ||
local function lang_from_code(...) | |||
return m_lang.getByCode(...) | |||
end | |||
local function ncategories(categories) | local function ncategories(categories) | ||
| Line 109: | Line 113: | ||
return table.concat(links) .. ncategories(categories) | return table.concat(links) .. ncategories(categories) | ||
end | end | ||
| Line 133: | Line 125: | ||
for _, ancestor in ipairs(ancestor_codes) do | for _, ancestor in ipairs(ancestor_codes) do | ||
local lang_options = ancestor.options or {} | local lang_options = ancestor.options or {} | ||
params[termarg_index] = { | |||
required = not lang_options.optional, | |||
default = lang_options.default, | |||
} | |||
if lang_options.roots then | if lang_options.roots then | ||
params[termarg_index] | params[termarg_index].list = true | ||
params[termarg_index].allow_holes = true | |||
params[termarg_index] | |||
end | end | ||
| Line 155: | Line 143: | ||
local args = m_param.process(parent_args, params) | local args = m_param.process(parent_args, params) | ||
local dest_lang = | local dest_lang = lang_from_code(dest_code) | ||
local etymologies = {} | local etymologies = {} | ||
| Line 162: | Line 150: | ||
local code = ancestor.code | local code = ancestor.code | ||
local lang_options = ancestor.options or {} | local lang_options = ancestor.options or {} | ||
local ancestor_lang = | local ancestor_lang = lang_from_code(code) | ||
local terms | local terms | ||
| Line 174: | Line 162: | ||
terms = items | terms = items | ||
else | else | ||
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({ | local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({ | ||
processed_args = | processed_args = args, | ||
param_mods = param_mods, | param_mods = param_mods, | ||
termarg = termarg_index, | termarg = termarg_index, | ||
Revision as of 22:57, 9 April 2026
- The following documentation is located at Module:pollasena-roots/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module implemented inherited templates for Pollasena languages: {{qsc-inh}}, {{sekh-inh}}, {{gwax-wasc}}, {{soky-inh}}. It was generalized to also include other non-Pollasena languages: {{guim-inh}}.
local m_put = require("Module:parse utilities")
local m_families = require("Module:families")
local m_lang = require("Module:languages")
local m_param = require("Module:parameters")
local m_param_utils = require("Module:parameter utilities")
local m_etym = require("Module:etymology")
local m_links = require("Module:links")
local gsub = mw.ustring.gsub
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local export = {}
local function lang_from_code(...)
return m_lang.getByCode(...)
end
local function ncategories(categories)
local out_categories = {}
for key, cat in ipairs(categories) do
out_categories[key] = "[[Category:" .. cat .. "]]"
end
return NAMESPACE == "Template" and "" or table.concat(out_categories, "")
end
local function link(lang, term, alt)
local natlang = lang:getWikidataItem() or false
-- true if the language declaration has a wikidata item, a marginal amount of conlangs have it
if lang:hasType("reconstructed") and not term:match("^%*") then
term = "*" .. term
end
local data = {term = term, alt = alt or term, lang = lang, to_wikt = natlang}
return m_links.full_link(data, "term")
end
function export.getLink(frame)
local params = {}
local a = 0
if frame.args["offset"] or (frame.args["old"] or frame.args["older"]) then
local offset = frame.args["old"] and 1 or frame.args["older"] and 2 or tonumber(frame.args["offset"])
for i=1,offset do
params[i] = {}
end
params[offset+1] = {list = true}
a = offset + 1
else
params[1] = {list = true}
a = 1
end
-- exceptions
params["and"], params["see"] = {}, {}
local args = require("Module:parameters").process(frame:getParent().args, params)
local fam, lang = m_families.getByCode(frame.args[1]), require("Module:languages").getByCode(frame.args[2])
local proto = fam:getProtoLanguage()
local links = {}; local categories = {}; local alts = {};
-- WIP
for i, item in ipairs(args[a]) do
if item == "+" then
table.insert(links," ")
elseif item == "-" then
table.insert(links, item)
elseif item:find("<") and not item:find("^[^<]*<[a-z]*[^a-z:]") then
local run = m_put.parse_balanced_segment_run(item, "<", ">")
local orig_param = a + i - 1
local function parse_err(msg)
error(msg .. ": " .. orig_param .. "= " .. table.concat(run))
end
local term = run[1]:gsub("%*","")
for j = 2, #run - 1, 2 do
local modtext = run[j]:match("^<(.*)>$")
local prefix, arg = modtext:match("^([a-z]+):(.*)$")
if item:match("><") then
if prefix == "a" then
table.insert(links, link(proto, term, arg))
table.insert(alts, arg)
elseif prefix == "c" then
table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg)
table.insert(alts, term)
end
elseif prefix == "a" then
table.insert(links, link(proto, term, arg))
table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. term)
table.insert(alts, arg)
elseif prefix == "c" then
table.insert(links, link(proto, term))
table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg)
table.insert(alts, term)
end
end
else
table.insert(links, link(proto, args[a][i]))
table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. args[a][i])
table.insert(alts, args[a][i])
end
if i~=1 and links[i-1] == "-" then alts[i] = links[i]:gsub("^%*","") end
--if i~=1 and links[i-1] ~= " " then links[i] = links[i]:gsub("(%|?)%*%-","%1-") end
--if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end
end
return table.concat(links) .. ncategories(categories)
end
local function parse_args(parent_args, dest_code, ancestor_codes, extra_params)
local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}})
local params = extra_params or {}
params.nocap = {type = "boolean"}
params.nocat = {type = "boolean"}
local termarg_index = 1
for _, ancestor in ipairs(ancestor_codes) do
local lang_options = ancestor.options or {}
params[termarg_index] = {
required = not lang_options.optional,
default = lang_options.default,
}
if lang_options.roots then
params[termarg_index].list = true
params[termarg_index].allow_holes = true
end
termarg_index = termarg_index + 1
end
m_param_utils.augment_params_with_modifiers(params, param_mods)
local args = m_param.process(parent_args, params)
local dest_lang = lang_from_code(dest_code)
local etymologies = {}
termarg_index = 1
for _, ancestor in ipairs(ancestor_codes) do
local code = ancestor.code
local lang_options = ancestor.options or {}
local ancestor_lang = lang_from_code(code)
local terms
if lang_options.roots then
local items = m_param_utils.parse_list_with_inline_modifiers_and_separate_params({
processed_args = args,
param_mods = param_mods,
termarg = termarg_index,
lang = ancestor_lang,
})
terms = items
else
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
processed_args = args,
param_mods = param_mods,
termarg = termarg_index,
lang = ancestor_lang,
})
terms = parsed.terms or {}
-- ensure at least one term exists
if not terms[1] then
if parsed.term then
terms[1] = parsed
else
terms[1] = { lang = ancestor_lang }
end
end
end
local etymology = m_etym.format_derived({
lang = dest_lang,
sources = { ancestor_lang },
terms = terms,
nocat = args.nocat,
template_name = "derived",
})
table.insert(etymologies, etymology)
termarg_index = termarg_index + 1
end
return etymologies, args
end
local function concat_etymologies(args, etymologies)
local capital = args.nocap and "f" or "F"
return capital .. "rom " .. table.concat(etymologies, ", from ") .. "."
end
function export.qsc(frame)
local parent_args = frame:getParent().args
local ancestor_codes = {
{ code = "sekh", options = {default = "asʰilavən"} },
{ code = "wasc", options = {optional = true, roots = true, default = "asł-ila"} }
}
local evolution, args = parse_args(parent_args, "qsc", ancestor_codes)
return concat_etymologies(args, evolution)
end
function export.lyti(frame)
local parent_args = frame:getParent().args
local source_code = parent_args.source or "und"
local ancestor_codes = {
{ code = "lyti-mid", options = {optional = not parent_args.mid} },
{ code = "lyti-old", options = {optional = not parent_args.old} },
{ code = source_code, options = {} },
}
local extra_params = {
mid = {type = "boolean"},
old = {type = "boolean"},
source = {},
}
local evolution, args = parse_args(parent_args, "lyti", ancestor_codes, extra_params)
return concat_etymologies(args, evolution)
end
return export