Using TWC LOGD SparqlProxy

Level: 
TWC LOGD Portal
Contributor: 
Contributor: 
Description: 
how to use SparqlProxy to connect RDF files and SPARQL endpoints to visualization tools. Example usage of SparqlProxy is discussed in Web browser and programming languages including javascript and PHP.
Overview
  • What is SparqlProxy?  SparqlProxy is a web service that wraps up SPARQL endpoint by rewriting SPARQL query results to formats (e.g. JSON) that is easy to be consumed Web applications such as Google Visualization API, MIT SIMILE Exhibit.
  • Where is SparqlProxy?
Basic RESTful Parameters
  • query: [required] encoded String of SPARQL query
  • query-uri :[required] URI of SPARQL query (use as an alternative to "query" parameter. These two parameters are mutul-exclusive)
  • service-uri: [required] URI of SPARQL Endpoint
  • output: output format.  ''xml'' - SPARQL/XML (default) : ''exhibit'' - JSON for MIT Exhibit : ''gvds'' - JSON for Google Visualization : ''csv'' - CSV : ''html'' - HTML table
Using SparqlProxy via Web InterfaceThere are two alternative options to specify a query in SparqlProxy (http://logd.tw.rpi.edu/ws/sparqlproxy.php) :
  • Option1 - Specify SPARQL query using "Query Text" : You may write your SPARQL query in the text area right after "Query Text", and execute it on a SPARQL endpoint. Simply click '''query''' button in Option1 area, you will see a sparql query issued to a DBpedia sparql endpoint.
  • Option2 - Specify SPARQL query using "Query URI": the only difference between this option and Option 1 is that you need to save your SPARQL query as a web page, and provide the URI of the query in the value field right after "Query URI".
  Using SparqlProxy in Javascript
Example 1 [query triple store and generate google visualization data]. The following code composes a URI representing a query via SparqlProxy's RESTful service: send a SPARQL query to a specific triple store, and then render results in "gvds" format - Google Visualization Table encoded in JSON.
 
function google_callback(){ 
  var sparqlproxy = "http://logd.tw.rpi.edu/ws/sparqlproxy.php";
  var queryloc = "http://logd.tw.rpi.edu/query/logd-stat-void-source.sparql";    
  var service = "http://logd.tw.rpi.edu/sparql";
  var queryurl = sparqlproxy 
 
                 + "?" + "output=gvds"
                 + "&service-uri=" + encodeURIComponent(service)
                 + "&query-uri=" + encodeURIComponent(queryloc) ;
  var query = new google.visualization.Query(queryurl); // Send the query.
  query.send(handleQueryResponse);
 }
 function  handleQueryResponse(reponse){
   // Check for query response errors.
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
   }
   var data = response.getDataTable();
   ...
}
Using SparqlProxy in PHP (tested in Drupal's "PHP code" input format)
Example 2 [query triple store and generate html fragment]. The following code composes a URI representing a query via SparqlProxy's RESTful service: send a SPARQL query to a specific triple store, and then render results in "tablecol" format - return a fragment of HTML including a table where each SPARQL result corresponds to a column.
 
// compose query 
  $sparqlproxy_uri = "http://logd.tw.rpi.edu/ws/sparqlproxy.php"
  $params = array();
  $params["query-uri"] = "http://logd.tw.rpi.edu/query/logd-stat-void-source.sparql";
  $params["service-uri"] = "http://logd.tw.rpi.edu/sparql";
  $params["output"] =  "tablecol";
  $query= $sparqlproxy_uri."?". http_build_query($params,'','&') ; //specific for Drupal
  
  //show query result
  echo file_get_contents($query);
Your rating: None Average: 4.3 (3 votes)