Module:RootFinder

From The Seven Sages of Rome
Revision as of 08:06, 26 March 2025 by Noeth (talk | contribs)

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

local p = {}

function p.getRootLanguage(frame)
    local title = mw.title.getCurrentTitle().fullText
    local prop = "Is Variety Of"

    while true do
        -- Perform a semantic query to get the parent language
        local result = mw.smw.ask{ "[[" .. title .. "]]|?" .. prop }
        
        -- Extract the first result
        local parent
        for _, data in pairs(result) do
            parent = data[prop]
            break -- Only need the first value
        end

        -- If there is no parent, return the current language as root
        if not parent or parent == "" then
            return title
        end

        -- Move up the hierarchy
        title = parent
    end
end

return p