10,731
edits
TheNightAvl (talk | contribs) No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
Line 47: | Line 47: | ||
-- build in-set ancestry | -- build in-set ancestry | ||
local ancestors = {} | local ancestors = {} | ||
for _, lang in ipairs(list) do | for _, lang in ipairs(list) do | ||
ancestors[lang] = {} | ancestors[lang] = {} | ||
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 | ||
local structure = {} | local structure = {} | ||
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 | ||
end | end | ||
end | end | ||
local swept = {} | local swept = {} | ||
local function search_and_sort(superordinate) | local function search_and_sort(superordinate) | ||
for mother, it in pairs(superordinate) do | |||
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 | |||
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 | ||
end | end | ||
end | end | ||
search_and_sort(it) | |||
end | end | ||
end | end | ||
search_and_sort(structure) | search_and_sort(structure) | ||
return 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 | ||
-- BEGIN TRIAGE -- | |||
local structure = export.langtree(langs) | |||
-- | 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) | |||
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"}}) | ||
]]-- | ]]-- |