Module:RootFinder: Difference between revisions
From The Seven Sages of Rome
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
function p.getRootLanguage(frame) | function p.getRootLanguage(frame) | ||
local | local title = mw.title.getCurrentTitle().fullText | ||
local prop = "Is Variety Of" | local prop = "Is Variety Of" | ||
while true do | while true do | ||
local | -- Perform a semantic query to get the parent language | ||
local result = mw.smw.ask{ "[[" .. title .. "]]|?" .. prop } | |||
-- Extract the first result | |||
local parent | |||
for _, data in pairs(result) do | |||
parent = data[prop] | |||
break -- Only need the first value | |||
end | |||
-- If there is no parent, return the current language as root | |||
if not parent or parent == "" then | if not parent or parent == "" then | ||
return | return title | ||
end | end | ||
-- Move up the hierarchy | |||
title = parent | |||
end | end | ||
end | end | ||
return p | return p | ||
Revision as of 08:06, 26 March 2025
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 result
local parent
for _, data in pairs(result) do
parent = data[prop]
break -- Only need the first value
end
-- If there is no parent, 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