11,796
edits
No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 32: | Line 32: | ||
local l = export.get_by_code(code) | local l = export.get_by_code(code) | ||
return l[field] | return l[field] | ||
end | |||
function export.is_ancestor(language, code) | |||
if language.lineage == nil then return false end | |||
return language.lineage[code] ~= nil | |||
end | |||
function export.get_common_ancestors(a, b) | |||
if a.lineage == nil or b.lineage == nil then return {} end | |||
local commons = {} | |||
for ancestor, _ in pairs(a.lineage) do | |||
if b.lineage[ancestor] then | |||
table.insert(commons, ancestor) | |||
end | |||
end | |||
return commons | |||
end | |||
function export.stage_at_split(a, b) | |||
return #export.get_common_ancestors(a, b) | |||
end -- returns stage at which the two languages diverged as an integer; if not related, returns 0 | |||
function export.common_ancestor(a, b) | |||
local ancestors = export.get_common_ancestors(a, b) | |||
table.sort(ancestors, function(a, b) | |||
local al = export.get_by_code(a).lineage or {} | |||
local bl = export.get_by_code(b).lineage or {} | |||
return #al > #bl | |||
end | |||
) | |||
return ancestors[1] | |||
end | end | ||