Module:RootFinder
From The Seven Sages of Rome
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)
-- Query to get the "Is Variety Of" property for the given language
local query = '[[' .. language .. ']]|?Is Variety Of'
local result = mw.ext.SemanticMediaWiki.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 wrapped in frame:preprocess
return mw.ext.SemanticMediaWiki.framePreprocess('{{#ask:' .. query .. '}}')
end
return p