Module:descendants: Difference between revisions

ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
m (Optimisation)
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 .. " (''see there for further descendants'')" end
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] = {}
if mw.ustring.find(lang, "[%>%_]") then
local ancestor_temp = ""
-- process ad hoc ancestors
for piece in mw.ustring.gmatch(lang, "([^%>%_]+[%>%_])") do
local ancestor_path = ""
ancestor_temp = ancestor_temp .. piece
for piece, delim in mw.ustring.gmatch(lang, "([^%>%_]*)([%>%_])") do
ancestor_add = mw.ustring.gsub(ancestor_temp, "[%>%_]$", "")
ancestor_path = ancestor_path .. piece
table.insert(ancestors[lang], ancestor_add)
table.insert(ancestors[lang], ancestor_path)
end
ancestor_path = ancestor_path .. delim
elseif mw.ustring.find(lang, "[0-9]+$") then
end
local lang_temp, index = mw.ustring.match(lang, "^([^0-9]+)([0-9]+)$")
for _, test in ipairs(list) do
if #ancestor_path < 1 then
if mw.ustring.find(test, index .. "$") then
if mw.ustring.find(lang, "[0-9]+$") then
local test_temp = mw.ustring.gsub(test, index .. "$", "")
local lang_temp, index = mw.ustring.match(lang, "^([^0-9]+)([0-9]+)$")
if m_languages.get_by_code(lang_temp).lineage[test_temp] then
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
elseif m_languages.get_by_code(lang_temp).lineage[test] then
end
local nope = false
else
for _, contain_test in ipairs(list) do
for _, test in ipairs(list) do
if contain_test == test .. index then nope = true end
if m_languages.get_by_code(lang).lineage[test] then
mismatch_check(lang, test)
table.insert(ancestors[lang], test)
end
end
if not nope then 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
table.insert(ancestors[lang], test)
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] == nil then
if terms[code] then
terms[code] = {}
local base_code, old_i = mw.ustring.match(code, "^(.*[^0-9])([0-9]*)$")
table.insert(langs, code)
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<bor>:13"}})
=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"}))
]]--
]]--