10,731
edits
TheNightAvl (talk | contribs) No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
Line 44: | Line 44: | ||
function export.langtree(list) | function export.langtree(list) | ||
-- build in-set ancestry | |||
local ancestors = {} | |||
local ancestors_num = 0 | |||
for _, lang in ipairs(list) do | |||
ancestors[lang] = {} | |||
ancestors_num = ancestors_num + 1 | |||
for _, test in ipairs(list) do | |||
if m_languages.get_by_code(lang).lineage[test] then | |||
table.insert(ancestors[lang], test) | |||
end | |||
end | |||
end | |||
table.sort(ancestors, sort_list) | |||
mw.logObject(ancestors) | |||
local structure = {} | local structure = {} | ||
for _, lang in ipairs( | mw.log("========== LEVEL 1 ==========") | ||
for lang, _ in pairs(ancestors) do | |||
end | if #ancestors[lang] == 0 then | ||
structure[lang] = {} | |||
ancestors[lang] = nil | |||
ancestors_num = ancestors_num - 1 | |||
mw.log("Apex recognised: " .. lang) | |||
end | |||
end | |||
local swept = {} | |||
local its = 2 | |||
local function search_and_sort(superordinate) | |||
mw.log("========== ITERATION " .. its .. " ==========") | |||
mw.log("Remaining data:") | |||
for lang, _ in pairs(ancestors) do | |||
mw.log("· " .. lang) | |||
end | |||
local changes = false | |||
for mother, _ in pairs(superordinate) do | |||
mw.log("————— Testing [" .. mother .. "] —————") | |||
for lang, lang_ancestors in pairs(ancestors) do | |||
if #lang_ancestors == 1 and lang_ancestors[1] == mother then | |||
superordinate[mother][lang] = {} | |||
swept[mother] = true | |||
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 | |||
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 | |||
search_and_sort(structure) | |||
mw.log("=========================") | |||
mw.logObject(structure) | |||
end | end | ||
Line 72: | Line 140: | ||
if terms[current_lang.code] == nil then | if terms[current_lang.code] == nil then | ||
terms[current_lang.code] = {} | terms[current_lang.code] = {} | ||
table.insert(langs, current_lang) | table.insert(langs, current_lang.code) | ||
end | end | ||
end | end | ||
Line 94: | Line 162: | ||
-- BEGIN TRIAGE -- | -- BEGIN TRIAGE -- | ||
export.langtree(langs) | |||
end | end | ||
Line 102: | Line 171: | ||
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. | =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"}}) | ||
]]-- | ]]-- |