Module:RootFinder: Difference between revisions
From The Seven Sages of Rome
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
-- Function to recursively get the "Is Variety Of" property value | -- Function to recursively get the "Is Variety Of" property value | ||
local function getParentLanguage(language) | local function getParentLanguage(language) | ||
-- | -- Use the semantic query function provided by Semantic Scribunto | ||
local query = '[[' .. language .. ']]|?Is Variety Of' | local query = '[[' .. language .. ']]|?Is Variety Of' | ||
local result = mw. | local result = mw.smw.ask(query) | ||
-- If there is a result, return the parent language (i.e., value of "Is Variety Of") | -- If there is a result, return the parent language (i.e., value of "Is Variety Of") | ||
| Line 29: | Line 29: | ||
-- Construct the SMW query to show the tree starting from the root language | -- 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 | local query = '[[' .. language .. ']]|Category:Language|format=tree|parent=Is Variety Of|limit=5000|root=' .. language | ||
-- Execute the query and return the result | -- Execute the query and return the result | ||
return mw. | return mw.smw.query(query) | ||
end | end | ||
return p | return p | ||
Revision as of 13:41, 25 March 2025
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