Module:RootFinder: Difference between revisions
From The Seven Sages of Rome
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function | -- 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 | ||
end | end | ||
function p. | -- Main function to construct the language tree query | ||
local language = frame.args[1] | function p.languageTree(frame) | ||
return | 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 | end | ||
return p | return p | ||
Revision as of 13:39, 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)
-- 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