Module:RootFinder

From The Seven Sages of Rome
Revision as of 13:41, 25 March 2025 by Noeth (talk | contribs)

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

local p = {}

-- Function to recursively get the "Is Variety Of" property value
local function getParentLanguage(language)
    -- Use the semantic query function provided by Semantic Scribunto
    local query = '[[' .. language .. ']]|?Is Variety Of'
    local result = mw.smw.ask(query)
    
    -- If there is a result, return the parent language (i.e., value of "Is Variety Of")
    if result and result[1] then
        return result[1]['?Is Variety Of']
    else
        -- Return nil if no parent is found (i.e., root language)
        return nil
    end
end

-- Main function to construct the language tree query
function p.languageTree(frame)
    local language = frame.args[1] -- The input language name (e.g., "Südrheinfränkisch")
    local parent = getParentLanguage(language)
    
    -- Traverse up the language tree to find the root language
    while parent do
        language = parent
        parent = getParentLanguage(language)
    end
    
    -- Construct the SMW query to show the tree starting from the root language
    local query = '[[' .. language .. ']]|Category:Language|format=tree|parent=Is Variety Of|limit=5000|root=' .. language
    -- Execute the query and return the result
    return mw.smw.query(query)
end

return p