Module:HelperMethods: Difference between revisions
From MaRDI portal
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local M = {} | |||
-- Required modules for SPARQL queries and HTML table generation | -- Required modules for SPARQL queries and HTML table generation |
Revision as of 09:42, 13 December 2023
Documentation for this module may be created at Module:HelperMethods/doc
local M = {}
-- 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 M.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 M.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
return M