Module:RootFinder
From The Seven Sages of Rome
Documentation for this module may be created at Module:RootFinder/doc
local p = {}
function p.getRootLanguage(frame)
local title = mw.title.getCurrentTitle().fullText
local prop = "Is Variety Of"
while true do
-- Perform a semantic query to get the parent language
local result = mw.smw.ask{ "[[" .. title .. "]]|?" .. prop }
-- Extract the first available parent
local parent = nil
for _, data in pairs(result) do
if type(data[prop]) == "table" then
parent = data[prop][1] -- Take the first parent if multiple values exist
else
parent = data[prop]
end
break -- Only need the first result
end
-- If no parent is found, return the current language as root
if not parent or parent == "" then
return title
end
-- Move up the hierarchy
title = parent
end
end
return p