Module:MySPARQL: Difference between revisions

From MaRDI portal
No edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 6: Line 6:
   local sparqlQuery = frame.args[1]
   local sparqlQuery = frame.args[1]
   local queryResults = sparql.runQuery(sparqlQuery) -- Use the runQuery method
   local queryResults = sparql.runQuery(sparqlQuery) -- Use the runQuery method
 
  if not queryResults then
    return nil
  end


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


return p
return p

Latest revision as of 11:52, 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
  
  if not queryResults then
    return nil
  end

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

return p