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 = {}
local mw = require('mw')


function p.getVariety(frame)
function p.getRootLanguage(frame)
     local page = frame.args[1]  -- Extract the first argument from the frame
     local lang = mw.title.getCurrentTitle().text
    local prop = "Is Variety Of"
      
      
     if not page or page == "" then
     while true do
         return "Error: No page name provided."
         local parent = mw.smw.getProperty(lang, prop)
    end
        if not parent or parent == "" then
   
            return lang
    -- Query Semantic MediaWiki for the property "Is Variety Of"
    local result = mw.smw.ask{"[[" .. page .. "]] |?Is Variety Of"}
   
    if result then
        for _, data in pairs(result) do
            if data["Is Variety Of"] then
                return "Is Variety Of: " .. data["Is Variety Of"]
            end
         end
         end
        lang = parent
     end
     end
   
    return "No 'Is Variety Of' property found for " .. page
end
end


return p
return p

Revision as of 08:02, 26 March 2025

Documentation for this module may be created at Module:RootFinder/doc

local p = {}

function p.getRootLanguage(frame)
    local lang = mw.title.getCurrentTitle().text
    local prop = "Is Variety Of"
    
    while true do
        local parent = mw.smw.getProperty(lang, prop)
        if not parent or parent == "" then
            return lang
        end
        lang = parent
    end
end

return p