Module:descendants: Difference between revisions

Jump to navigation Jump to search
ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
No edit summary
Line 47: Line 47:
-- build in-set ancestry
-- build in-set ancestry
local ancestors = {}
local ancestors = {}
local ancestors_num = 0
for _, lang in ipairs(list) do
for _, lang in ipairs(list) do
ancestors[lang] = {}
ancestors[lang] = {}
ancestors_num = ancestors_num + 1
for _, test in ipairs(list) do
for _, test in ipairs(list) do
if m_languages.get_by_code(lang).lineage[test] then
if m_languages.get_by_code(lang).lineage[test] then
Line 57: Line 55:
end
end
end
end
table.sort(ancestors, sort_list)
mw.logObject(ancestors)
local structure = {}
local structure = {}
mw.log("========== LEVEL 1 ==========")
for lang, _ in pairs(ancestors) do
for lang, _ in pairs(ancestors) do
if #ancestors[lang] == 0 then
if #ancestors[lang] == 0 then
structure[lang] = {}
structure[lang] = {}
ancestors[lang] = nil
ancestors[lang] = nil
ancestors_num = ancestors_num - 1
mw.log("Apex recognised: " .. lang)
end
end
end
end
local swept = {}
local swept = {}
local its = 2
local function search_and_sort(superordinate)
local function search_and_sort(superordinate)
mw.log("========== ITERATION " .. its .. " ==========")
for mother, it in pairs(superordinate) do
mw.log("Remaining data:")
for lang, lang_ancestors in pairs(ancestors) do
for lang, _ in pairs(ancestors) do
for i, lang_ancestor in ipairs(ancestors[lang]) do
mw.log("· " .. lang)
if swept[lang_ancestor] then table.remove(ancestors[lang], i) end
end
end
local changes = false
end
for mother, _ in pairs(superordinate) do
mw.log("————— Testing [" .. mother .. "] —————")
for lang, lang_ancestors in pairs(ancestors) do
for lang, lang_ancestors in pairs(ancestors) do
if #lang_ancestors == 1 and lang_ancestors[1] == mother then
if #lang_ancestors == 1 and lang_ancestors[1] == mother then
Line 89: Line 77:
swept[mother] = true
swept[mother] = true
ancestors[lang] = nil
ancestors[lang] = nil
ancestors_num = ancestors_num - 1
changes = true
mw.log("Testing [" .. lang .. "] against [" .. mother .. "]: ✓")
else
mw.log("Testing [" .. lang .. "] against [" .. mother .. "]: ×")
end
end
for lang, lang_ancestors in pairs(ancestors) do
for i, lang_ancestor in ipairs(ancestors[lang]) do
if swept[lang_ancestor] then table.remove(ancestors[lang], i) end
end
end
end
end
end
search_and_sort(it)
if changes and ancestors_num > 0 then
its = its + 1
for _, it in pairs(superordinate) do
search_and_sort(it)
end
elseif ancestors_num > 0 then mw.log("PATH EXHAUSTED")
else mw.log("DATA EXHAUSTED")
end
end
end
end
search_and_sort(structure)
search_and_sort(structure)
return structure
mw.log("=========================")
mw.logObject(structure)


end
end
Line 125: Line 94:
local terms = {}
local terms = {}
local langs = {}
local langs = {}
local indenter = args["indent"] or args["in"] or ""
for i, term in ipairs(args) do --ryn:term1|term2|term3|rad:term1|term2 ...
for i, term in ipairs(args) do --ryn:term1|term2|term3|rad:term1|term2 ...
Line 158: Line 128:
end
end
mw.logObject(items)
-- BEGIN TRIAGE --
local structure = export.langtree(langs)
-- BEGIN TRIAGE --
local outs = {}
local it = 0
function process_structure(tab)
it = it + 1
local sorter = {}
local sorter_proto = {}
for key, _ in pairs(tab) do
if mw.ustring.find(key, "%-pro$") then
table.insert(sorter_proto, key)
else
table.insert(sorter, key)
end
end
table.sort(sorter)
table.sort(sorter_proto)
for _, key in ipairs(sorter_proto) do
table.insert(sorter, key)
end
for _, key in ipairs(sorter) do
local out = " " .. items[key]
for i = 1, it do
out = "*" .. out
end
out = indenter .. out
table.insert(outs, out)
process_structure(tab[key])
end
it = it - 1
end
process_structure(structure)
export.langtree(langs)
return table.concat(outs, "\n")
end
end
Line 171: Line 176:
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={"rad:hello", "hi", "ryn:hello", "rad-o:hello", "rad-pro:hello", "hrd-pro:hi", "ryn-o:hihe", "lfv-pro:hihe", "lfv-o:hihe", "lfv:hihe"}})
=p.desctree(mw.getCurrentFrame():newChild{title="whatever",args={"rad<bor>:hello", "aeg:hello", "hi", "ryn:hello", "rad-o:hello", "rad-pro:hello", "hrd-pro:hi", "ryn-o:hihe", "lfv-pro:hihe", "lfv-o:hihe", "lfv:hihe"}})
]]--
]]--

Navigation menu