Module:HelperMethods

From MaRDI portal
Revision as of 09:23, 13 December 2023 by Tconrad (talk | contribs) (Created page with "-- Required modules for SPARQL queries and HTML table generation local sparql = require('SPARQL') local mwHtml = require('mw.html') -- Utility function to trim and lowercase a string function trimAndLower(str) if str == nil then return nil end str = str:gsub("^%s*(.-)%s*$", "%1") return str:lower() end -- Function to convert JSON results into a Lua table function convertJsonToTable(jsonResults) local resultsTable = {} if jsonResults and jsonResults.results a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

-- Required modules for SPARQL queries and HTML table generation
local sparql = require('SPARQL')
local mwHtml = require('mw.html')

-- Utility function to trim and lowercase a string
function trimAndLower(str)
	if str == nil then return nil end
	str = str:gsub("^%s*(.-)%s*$", "%1")
	return str:lower()
end

-- Function to convert JSON results into a Lua table
function convertJsonToTable(jsonResults)
    local resultsTable = {}
    if jsonResults and jsonResults.results and jsonResults.results.bindings then
        local bindings = jsonResults.results.bindings
        for j = 1, #bindings do
            local row = {}
            for key, value in pairs(bindings[j]) do
                table.insert(row, value.value)
            end
            table.insert(resultsTable, row)
        end
    end
    return resultsTable
end