Actions

Module

Module:ancestor tree

From SUALEX

Documentation for this module may be created at Module:ancestor tree/doc

-- Module:ancestor_tree

local p = {}
local lexicon = require("Module:lexicon")
local utilities = require("Module:utilities")
local etymology = require("Module:etymology")
local format = require("Module:format")

function p.invoke(frame)
    local args = frame.args or {}
    local param = args[1] or ""
	local noinh = args.noinh == "1"
	local noder = args.noder == "1"
	local nobor = args.nobor == "1"
	local nounc = args.nounc == "1"

    local parts = utilities.split_string(param, ":")
    local lang_code = utilities.trim_string(parts[1] or "")
    local item = utilities.trim_string(parts[2] or "")
    local homonym = item:match("#(.+)$")
    item = item:gsub("#.+$", "")

    local options = { noinh = noinh, noder = noder, nobor = nobor, nounc = nounc }

    lexicon.preload_all_lexicons()
    local root_line = ": " .. format.language_name(lang_code) .. " " .. format.render_term(lang_code, item, homonym, nil, nil, nil, "en")
    local lines = { root_line }

    local tree = etymology.build_ancestor_tree(lang_code, item, homonym, options, 1)
    for _, node in ipairs(tree) do
        table.insert(lines, node.indent .. " " .. etymology.render_node(node, "ancestor"))
    end
    return utilities.join_strings(lines, "\n")
end

return p