Module:MySPARQL: Difference between revisions

From MaRDI portal
No edit summary
No edit summary
Line 8: Line 8:


   local firstColName = queryResults['head']['vars'][0]
   local firstColName = queryResults['head']['vars'][0]
   return queryResults['results']['bindings'][0][firstColName]['value']
   if queryResults['results'] then
    return nil
    else
    return queryResults['results']['bindings'][0][firstColName]['value']
end
end
end


return p
return p

Revision as of 11:11, 14 December 2023

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

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]
  if queryResults['results'] then
    	return nil
    else
    	return queryResults['results']['bindings'][0][firstColName]['value']
	end
end

return p