10,731
edits
TheNightAvl (talk | contribs) m (Optimisation) |
TheNightAvl (talk | contribs) No edit summary |
||
Line 4: | Line 4: | ||
local m_languages = require("Module:languages") | local m_languages = require("Module:languages") | ||
local m_inline = require("Module:inline") | local m_inline = require("Module:inline") | ||
local m_table = require("Module:table") | |||
local see_further_text = "see there for further descendants" | |||
function export.descendant(frame) | function export.descendant(frame) | ||
Line 42: | Line 44: | ||
end | end | ||
out = out .. table.concat(terms, ", ") | out = out .. table.concat(terms, ", ") | ||
if see_desc then out = out .. " ('' | if see_desc then out = out .. " (''" .. see_further_text .. "'')" end | ||
else | else | ||
out = out .. "— (''" .. lostcap .. "'')" | out = out .. "— (''" .. lostcap .. "'')" | ||
Line 55: | Line 57: | ||
local ancestors = {} | local ancestors = {} | ||
for _, lang in ipairs(list) do | for _, lang in ipairs(list) do | ||
local function mismatch_check(base, test) -- function for processing doublets | |||
for _, test_index in ipairs(list) do | |||
if mw.ustring.find(test_index, "[0-9]+$") and mw.ustring.gsub(test_index, "[0-9]+$", "") == test and not m_table.contains(list, base .. mw.ustring.match(test_index, "[0-9]+$")) then | |||
mw.addWarning("Multiple possible ancestors found for [" .. lang .. "] and mismatch of corresponding descendants detected ([" .. test_index .. "] but no [" .. base .. mw.ustring.match(test_index, "[0-9]+$") .. "]); please double-check numbering and identical code calls, as these may not have been properly triaged.") | |||
end | |||
end | |||
end | |||
-- process ancestors | |||
ancestors[lang] = {} | ancestors[lang] = {} | ||
-- process ad hoc ancestors | |||
local ancestor_path = "" | |||
for piece, delim in mw.ustring.gmatch(lang, "([^%>%_]*)([%>%_])") do | |||
ancestor_path = ancestor_path .. piece | |||
table.insert(ancestors[lang], ancestor_path) | |||
end | ancestor_path = ancestor_path .. delim | ||
end | |||
if #ancestor_path < 1 then | |||
if mw.ustring.find(lang, "[0-9]+$") then | |||
local lang_temp, index = mw.ustring.match(lang, "^([^0-9]+)([0-9]+)$") | |||
for _, test in ipairs(list) do | |||
if mw.ustring.find(test, "[^0-9]" .. index .. "$") then -- matches existing historical doublets with identical, e.g. rad-o2, if rad2 is present | |||
local test_temp = mw.ustring.gsub(test, index .. "$", "") | |||
if m_languages.get_by_code(lang_temp).lineage[test_temp] then | |||
table.insert(ancestors[lang], test) | |||
end | |||
elseif m_languages.get_by_code(lang_temp).lineage[test] then -- if test is still an ancestor to current language, e.g. rad-o, if rad2 is present | |||
mismatch_check(lang_temp, test) | |||
table.insert(ancestors[lang], test) | table.insert(ancestors[lang], test) | ||
end | end | ||
end | |||
else | |||
for _, test in ipairs(list) do | |||
if m_languages.get_by_code(lang).lineage[test] then | |||
mismatch_check(lang, test) | |||
table.insert(ancestors[lang], test) | |||
end | end | ||
end | end | ||
end | end | ||
Line 137: | Line 151: | ||
code, lang_args = m_inline.parse(lang_change) | code, lang_args = m_inline.parse(lang_change) | ||
-- if new language, build table | -- if new language, build table | ||
if terms[code] == | if terms[code] then | ||
terms[code | local base_code, old_i = mw.ustring.match(code, "^(.*[^0-9])([0-9]*)$") | ||
local new_i = 2 | |||
while terms[base_code .. new_i] do | |||
new_i = new_i + 1 | |||
end | |||
code = base_code .. new_i | |||
mw.log("Duplicate code detected: converted [" .. base_code .. (old_i or "") .. "] to [" .. code .. "]") | |||
end | end | ||
terms[code] = {} | |||
table.insert(langs, code) | |||
current_lang = code | current_lang = code | ||
Line 218: | Line 239: | ||
Debug console test string: | Debug console test string: | ||
=p.descendant(mw.getCurrentFrame():newChild{title="whatever",args={"rad"}}) | =p.descendant(mw.getCurrentFrame():newChild{title="whatever",args={"rad"}}) | ||
=p.desctree(mw.getCurrentFrame():newChild{title="whatever",args={"ryn>rad-o:1", "aeg:2", "3", "ryn:4", "ryn>rad-o_rad:5", ">rad-pro:6", "hrd-pro:7", "ryn-o:8", "lfv-pro:9", "lfv-o:10", "lfv:11", "rad-pro:12", "kil<lost:oh no>:", "bal< | =p.desctree(mw.getCurrentFrame():newChild{title="whatever",args={"ryn>rad-o:1", "aeg:2", "3", "ryn:4", "ryn>rad-o_rad:5", ">rad-pro:6", "hrd-pro:7", "ryn-o:8", "lfv-pro:9", "lfv-o:10", "lfv:11", "rad-pro:12", "kil<lost:oh no>:", "bal<see>:13"}}) | ||
mw.logObject(p.langtree({"rad", "rad-o", "ryn", "hrd-pro", "lfv"})) | |||
]]-- | ]]-- |