Module:pollasena-roots: Difference between revisions

No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 4: Line 4:
local m_param = require("Module:parameters")
local m_param = require("Module:parameters")
local m_param_utils = require("Module:parameter utilities")
local m_param_utils = require("Module:parameter utilities")
local m_param_utils = require("Module:parameter utilities")
local m_utils = require("Module:utilities")
local m_etym = require("Module:etymology")
local m_etym = require("Module:etymology")
local m_links = require("Module:links")
local m_links = require("Module:links")
local m_table = require("Module:table")


local gsub = mw.ustring.gsub
local gsub = mw.ustring.gsub
Line 15: Line 18:
local export = {}
local export = {}


local function lang_from_code(...)
local wasc_suffixes = m_table.listToSet {
return m_lang.getByCode(...)
"ati", "cosc", "e", "ekan", "i", "ila",
end
"kan", "la", "osc", "otl", "que", "scati", "si"
}


local function ncategories(categories)
local function ncategories(categories)
Line 143: Line 147:
params[termarg_index] = {
params[termarg_index] = {
required = not lang_options.optional,
required = not lang_options.optional,
list = true,
}
params["c"] = {
list = true,
list = true,
allow_holes = true,
allow_holes = true,
default = lang_options.default,
}
}
else
else
params[termarg_index] = {
params[termarg_index] = {
required = not lang_options.optional,
required = not lang_options.optional,
default = lang_options.default,
}
}
end
end
Line 161: Line 166:
local args = m_param.process(parent_args, params)
local args = m_param.process(parent_args, params)


local dest_lang = lang_from_code(dest_code)
local dest_lang = m_lang.getByCode(dest_code)
local etymologies = {}
local etymologies = {}
termarg_index = 1
termarg_index = 1
local cats = {}
for _, ancestor in ipairs(ancestor_codes) do
for _, ancestor in ipairs(ancestor_codes) do
local code = ancestor.code
local code = ancestor.code
local lang_options = ancestor.options or {}
local lang_options = ancestor.options or {}
local ancestor_lang = lang_from_code(code)
local ancestor_lang = m_lang.getByCode(code)
local raw_val = parent_args[termarg_index] or parent_args[tostring(termarg_index)]
local raw_val = parent_args[termarg_index] or parent_args[tostring(termarg_index)]
Line 176: Line 182:
local terms
local terms
local separator = ""
local separator = ""
 
if lang_options.roots then
if lang_options.roots then
local items = m_param_utils.parse_list_with_inline_modifiers_and_separate_params({
local items = m_param_utils.parse_list_with_inline_modifiers_and_separate_params({
Line 188: Line 194:
local root_index = 1
local root_index = 1
for _, item in ipairs(items) do
for _, item in ipairs(items) do
if item.alt and not match(item.alt, "^%*") and ancestor_lang:hasType("reconstructed") then
item.alt = "*" .. item.alt
end
if item.term == "-" or item.term == "+" then
if item.term == "-" or item.term == "+" then
separator = item.term
separator = item.term
elseif item.term then
elseif item.term then
if root_index > 1 and separator == "-" then -- no asterisk after hyphen
if root_index > 1 and match(items[root_index - 1].term, "%-$") then -- no asterisk after hyphen
if not item.alt then
if not item.alt then
item.alt = item.term:gsub("^%*", "")
item.alt = item.term:gsub("^%*", "")
Line 197: Line 207:
item.alt = item.alt:gsub("^%*", "")
item.alt = item.alt:gsub("^%*", "")
end
end
item.no_alt_ast = true
end
end
table.insert(terms, item)
table.insert(terms, item)
local cat_term = args.c[root_index] or item.term
cat_term = "*" .. gsub(cat_term, "^*+", "") -- ensure only one asterisk
if code == "wasc" and cat_term ~= item.term then -- Wascotl root and suffix handling
local suffix = match(cat_term, "^*%w+%-(%w+)$")
if wasc_suffixes[suffix] then
cat_term = gsub(cat_term, suffix, "")
end
end
table.insert(cats, dest_lang:getCanonicalName() .. " terms from " .. ancestor_lang:getCanonicalName() .. " " .. cat_term)
root_index = root_index + 1
root_index = root_index + 1
end
end
Line 207: Line 229:
terms[1] = { lang = ancestor_lang }
terms[1] = { lang = ancestor_lang }
end
end
else
else
local single_args = get_single_args(args, termarg_index)
local single_args = get_single_args(args, termarg_index)
Line 226: Line 250:
end
end


local etymology = m_etym.format_derived({
local etymology = m_etym.format_inherited{
lang = dest_lang,
lang = dest_lang,
sources = { ancestor_lang },
terms = terms,
terms = terms,
sort_key = args.sort,
nocat = args.nocat,
conj = lang_options.roots and separator or nil,
conj = lang_options.roots and separator or nil,
nocat = args.nocat,
}
template_name = "derived",
})


table.insert(etymologies, etymology)
table.insert(etymologies, etymology)
Line 239: Line 262:
end
end
end
end
 
return etymologies, args
local categories = {}
if not parent_args.nocat then
categories = m_utils.format_categories(cats, dest_lang)
end
return etymologies, args, categories
end
end


Line 256: Line 284:
}
}
local evolution, args = parse_args(parent_args, "qsc", ancestor_codes)
local evolution, args, categories = parse_args(parent_args, "qsc", ancestor_codes)
return concat_etymologies(args, evolution)
return concat_etymologies(args, evolution) .. categories
end
end