Module:NarratorListModule: Difference between revisions
From The Seven Sages of Rome
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 3: | Line 3: | ||
-- Function to recursively find the root language | -- Function to recursively find the root language | ||
function p.findRootLanguage(language) | function p.findRootLanguage(language) | ||
-- | -- Construct the SMW query to find the parent language | ||
local query | local query = string.format('[[%s]]|?Is Variety Of', language) | ||
-- Execute the query | -- Execute the query | ||
local result = mw.smw. | local result = mw.smw.ask{ query } | ||
-- Debugging: Log the result | -- Debugging: Log the query result | ||
mw. | mw.logObject(result, "Query result") | ||
-- Check if | -- Check if the result contains the 'Is Variety Of' property | ||
if result and result | if result and result[language] and result[language]["Is Variety Of"] then | ||
local parentLanguage = result[language]["Is Variety Of"][1] | |||
-- Recursively find the root language | |||
return p.findRootLanguage(parentLanguage) | |||
end | end | ||
-- If no parent is found, return the current language | -- If no parent language is found, return the current language as the root | ||
return language | return language | ||
end | end | ||
return p | return p | ||
Revision as of 13:16, 25 March 2025
Documentation for this module may be created at Module:NarratorListModule/doc
local p = {}
-- Function to recursively find the root language
function p.findRootLanguage(language)
-- Construct the SMW query to find the parent language
local query = string.format('[[%s]]|?Is Variety Of', language)
-- Execute the query
local result = mw.smw.ask{ query }
-- Debugging: Log the query result
mw.logObject(result, "Query result")
-- Check if the result contains the 'Is Variety Of' property
if result and result[language] and result[language]["Is Variety Of"] then
local parentLanguage = result[language]["Is Variety Of"][1]
-- Recursively find the root language
return p.findRootLanguage(parentLanguage)
end
-- If no parent language is found, return the current language as the root
return language
end
return p