Module:pollasena-roots: Difference between revisions

No edit summary
No edit summary
 
(37 intermediate revisions by the same user not shown)
Line 1: Line 1:
local m_put = require("Module:parse utilities")
local m_put = require("Module:parse utilities")
local m_families = require("Module:families")
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 gsub = mw.ustring.gsub
Line 9: 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 23: Line 32:
-- true if the language declaration has a wikidata item, a marginal amount of conlangs have it
-- true if the language declaration has a wikidata item, a marginal amount of conlangs have it
if lang:hasType("reconstruced") and not term:match("^%*") then
if lang:hasType("reconstructed") and not term:match("^%*") then
term = "*" .. term
term = "*" .. term
end
end
local data = {term = term, alt = alt or term, lang = lang, to_wikt = natlang}
local data = {term = term, alt = alt or term, lang = lang, to_wikt = natlang}
return require('Module:links').full_link(data)
return m_links.full_link(data, "term")
end
end


Line 34: Line 43:
local a = 0
local a = 0
if frame.args["older"] then
if frame.args["offset"] or (frame.args["old"] or frame.args["older"]) then
params[1] = {}
local offset = frame.args["old"] and 1 or frame.args["older"] and 2 or tonumber(frame.args["offset"])
params[2] = {list = true}
a = 2
for i=1,offset do
params[i] = {}
end
params[offset+1] = {list = true}
a = offset + 1
else
else
params[1] = {list = true}
params[1] = {list = true}
a = 1
a = 1
end
end
-- exceptions
params["and"], params["see"] = {}, {}
local args = require("Module:parameters").process(frame:getParent().args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)
Line 91: Line 107:
end
end
if i~=1 and links[i-1] == "-" then links[i] = links[i]:gsub("%|%*","|") 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("%|%*%-","|-") 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
--if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end
end
end
Line 99: Line 115:
end
end


local function get_single_args(args, index)
local single = {}
for k, v in pairs(args) do
if type(v) == "table" and v.maxindex then
if v[index] ~= nil then
single[k] = v[index]
end
else
single[k] = v
end
end
return single
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 {}
if lang_options.roots then
params[termarg_index] = {
required = not lang_options.optional,
list = true,
allow_holes = true,
}
else
params[termarg_index] = {
required = not lang_options.optional,
}
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 = m_lang.getByCode(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 = m_lang.getByCode(code)
local terms
local separator = ""
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 = {}
local root_index = 1
for _, item in ipairs(items) do
if item.term == "-" or item.term == "+" then
separator = item.term
elseif item.term then
if root_index > 1 and separator == "-" then -- no asterisk after hyphen
if not item.alt then
item.alt = item.term:gsub("^%*", "")
else
item.alt = item.alt:gsub("^%*", "")
end
item.no_alt_ast = true
end
table.insert(terms, item)
root_index = root_index + 1
end
end
else
local single_args = get_single_args(args, termarg_index)
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
processed_args = single_args,
param_mods = param_mods,
termarg = termarg_index,
lang = ancestor_lang,
})
terms = parsed.terms or {}
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,
conj = lang_options.roots and separator or nil,
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" },
{ code = "wasc", options = {optional = true, roots = true } }
}
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
return export