Module:pollasena-roots: Difference between revisions

No edit summary
No edit summary
 
(43 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_etym_specialized = require("Module:etymology/specialized")
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
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local match = mw.ustring.match
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch


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", "-kan",
end
"-la", "-osc", "-otl", "-que", "-scati", "-si", "-tl",
}


local function ncategories(categories)
local function get_single_args(args, index)
local out_categories = {}
local single = {}
for key, cat in ipairs(categories) do
for k, v in pairs(args) do
out_categories[key] = "[[Category:" .. cat .. "]]"
if type(v) == "table" and v.maxindex then
if v[index] ~= nil then
single[k] = v[index]
end
else
single[k] = v
end
end
end
 
return single
return NAMESPACE == "Template" and "" or table.concat(out_categories, "")
end
end


local function link(lang, term, alt)
function export.parse_args(parent_args, dest_code, ancestor_codes, extra_params)
local natlang = lang:getWikidataItem() or false
local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}})
-- 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
local params = extra_params or {}
term = "*" .. term
params.nocap = {type = "boolean"} -- no capital letter
end
params.nocat = {type = "boolean"} -- no categories
local data = {term = term, alt = alt or term, lang = lang, to_wikt = natlang}
params.p = {} -- borrowing process
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 termarg_index
local offset = frame.args["old"] and 1 or frame.args["older"] and 2 or tonumber(frame.args["offset"])
if parent_args.borrowing then
termarg_index = 2
for i=1,offset do
params[1] = {
params[i] = {}
type = "language",
end
required = true,
params[offset+1] = {list = true}
}
a = offset + 1
else
else
params[1] = {list = true}
termarg_index = 1
a = 1
end
end
-- exceptions
for _, ancestor in ipairs(ancestor_codes) do
params["and"], params["see"] = {}, {}
local lang_options = ancestor.options or {}
local args = require("Module:parameters").process(frame:getParent().args, params)
if lang_options.roots then
params[termarg_index] = {
local fam, lang = m_families.getByCode(frame.args[1]), require("Module:languages").getByCode(frame.args[2])
required = not lang_options.optional,
local proto = fam:getProtoLanguage()
list = true,
 
}
local links = {}; local categories = {}; local alts = {};
params["c"] = {
-- WIP
list = true,
for i, item in ipairs(args[a]) do
allow_holes = true,
if item == "+" then
}
table.insert(links," ")
else
elseif item == "-" then
params[termarg_index] = {
table.insert(links, item)
required = not lang_options.optional,
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
if lang_options.annotated then
local function parse_err(msg)
params["parts"] = {
error(msg .. ": " .. orig_param .. "= " .. table.concat(run))
sublist = true,
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
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
end
if i~=1 and links[i-1] == "-" then alts[i] = links[i]:gsub("^%*","") end
termarg_index = termarg_index + 1
--if i~=1 and links[i-1] ~= "&nbsp;" then links[i] = links[i]:gsub("(%|?)%*%-","%1-") end
--if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end
end
end
return table.concat(links) .. ncategories(categories)
m_param_utils.augment_params_with_modifiers(params, param_mods)
end
local args = m_param.process(parent_args, params)


local function parse_args(parent_args, dest_code, ancestor_codes, extra_params)
local dest_lang = m_lang.getByCode(dest_code)
local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}})
local dest_lang = lang_from_code(dest_code)
local etymologies = {}
local etymologies = {}
local termarg_index = 1
termarg_index = parent_args.borrowing and 2 or 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 terms
local raw_val = parent_args[termarg_index] or parent_args[tostring(termarg_index)]
if lang_options.optional and (raw_val == nil or raw_val == "") then
termarg_index = termarg_index + 1
else
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
local last_term = ""
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
separator = item.term
elseif item.term then
if root_index > 1 and last_term ~= "+" then -- only subsequent asterisks afer space
item.alt = gsub(item.alt or item.term, "^%*", "")
end
table.insert(terms, item)
local function one_asterisk(str)
return "*" .. gsub(str, "^*+", "")
end
local cat_term = one_asterisk(args.c[root_index] or item.term)
if code == "wasc" 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 derived from the " .. ancestor_lang:getCanonicalName() .. " root " .. cat_term)
root_index = root_index + 1
end
last_term = item.term
end
if not terms[1] then
terms[1] = { lang = ancestor_lang }
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,
})


if lang_options.roots then
terms = parsed.terms or {}
-- 1. Setup params specifically for this list argument
if not terms[1] then
local list_params = {
if parsed.term then
[termarg_index] = {
terms[1] = parsed
required = not lang_options.optional,
else
list = true,
terms[1] = { lang = ancestor_lang }
allow_holes = true,
end
default = lang_options.default,
}
}
-- Let the utility re-parse the raw arguments for this specific list
local items = m_param_utils.parse_list_with_inline_modifiers_and_separate_params({
raw_args = parent_args,
params = list_params,
param_mods = param_mods,
termarg = termarg_index,
lang = ancestor_lang,
})
-- Filter out any literal hyphens passed as terms
terms = {}
for _, item in ipairs(items) do
if item.term and item.term ~= "-" then
table.insert(terms, item)
end
end
end
end
else
-- 2. Setup params specifically for this single term argument
local etymology
local term_params = {
if lang_options.borrowed then
[termarg_index] = {
etymology = m_etym_specialized.specialized_borrowing{
required = not lang_options.optional,
bortype = args.p or "b",
default = lang_options.default,
lang = dest_lang,
sources = {ancestor_lang},
terms = terms,
sort_key = args.sort,
nocat = args.nocat,
conj = lang_options.roots and separator or nil,
nocap = args.mid or args.old or args.nocap,
}
else
etymology = m_etym.format_inherited{
lang = dest_lang,
terms = terms,
sort_key = args.sort,
nocat = args.nocat,
conj = lang_options.roots and separator or nil,
}
}
}
etymology = "from " .. etymology
end
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
if lang_options.annotated and args.parts then
raw_args = parent_args,
local referrals = {}
params = term_params,
for _, part in ipairs(args.parts) do
param_mods = param_mods,
local referral = m_links.full_link({
termarg = termarg_index,
lang = ancestor_lang,
lang = ancestor_lang,
term = part,
})
}, "term")
 
terms = parsed.terms or {}
table.insert(referrals, referral)
if not terms[1] then
if parsed.term then
terms[1] = parsed
else
terms[1] = { lang = ancestor_lang }
end
end
etymology = etymology .. " (see " .. m_table.serialCommaJoin(referrals) .. ")"
end
end
table.insert(etymologies, etymology)
termarg_index = termarg_index + 1
end
end
local etymology = m_etym.format_derived({
lang = dest_lang,
sources = { ancestor_lang },
terms = terms,
conj = lang_options.roots and "-" or nil, -- Use our newly added hyphen conjunction!
nocat = parent_args.nocat,
template_name = "derived",
})
table.insert(etymologies, etymology)
termarg_index = termarg_index + 1
end
end
return etymologies
end
local function concat_etymologies(parent_args, etymologies)
local capital = parent_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 = parse_args(parent_args, "qsc", ancestor_codes)
return concat_etymologies(parent_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 evolution = parse_args(parent_args, "lyti", ancestor_codes)
local categories = m_utils.format_categories(cats, dest_lang)
return concat_etymologies(parent_args, evolution)
return etymologies, args, parent_args.nocat and "" or categories
end
end


return export
return export