Module:MySPARQL: Difference between revisions
From TITAF TANGOWIKI
(Created page with "local sparql = require('SPARQL') -- Load the SPARQL binding local p = {} function p.showFirstValue(frame) local sparqlQuery = frame.args[1] local queryResults = sparql.runQuery(sparqlQuery) -- Use the runQuery method local firstColName = queryResults['head']['vars'][0] return queryResults['results']['bindings'][0][firstColName]['value'] end return p") |
No edit summary |
||
| Line 3: | Line 3: | ||
local p = {} | local p = {} | ||
function p. | function p.debugQuery(frame) | ||
local sparqlQuery = frame.args[1] | |||
local queryResults = sparql.runQuery(sparqlQuery) | |||
-- If queryResults is nil, return an error message | |||
if not queryResults then | |||
return "SPARQL query failed! Check endpoint and extension." | |||
end | |||
-- Return full JSON output to analyze | |||
return mw.text.jsonEncode(queryResults) | |||
end | end | ||
return p | return p | ||
Revision as of 20:13, 21 March 2025
Documentation for this module may be created at Module:MySPARQL/doc
local sparql = require('SPARQL') -- Load the SPARQL binding
local p = {}
function p.debugQuery(frame)
local sparqlQuery = frame.args[1]
local queryResults = sparql.runQuery(sparqlQuery)
-- If queryResults is nil, return an error message
if not queryResults then
return "SPARQL query failed! Check endpoint and extension."
end
-- Return full JSON output to analyze
return mw.text.jsonEncode(queryResults)
end
return p