visualizing web data query results

22
Visualizing Web Data Query Results Pablo N. Mendes [email protected] WWW2012 Tutorial

Upload: anja-jentzsch

Post on 26-Jun-2015

2.008 views

Category:

Technology


1 download

DESCRIPTION

Visualizing Web Data Query Resultsby Pablo N. Mendes

TRANSCRIPT

Page 1: Visualizing Web Data Query Results

Visualizing Web Data Query Results

Pablo N. [email protected]

WWW2012 Tutorial

Page 2: Visualizing Web Data Query Results

Outline

● Preliminaries: ● Javascript, jQuery, same-origin

● Processing query results● A closer look at SPARQL JSON

● Manually parsing and displaying● Build your own table

● Neat toolkits to reuse● Sparqk, Sgvizler

● Hands on!

Page 3: Visualizing Web Data Query Results

Preliminaries● Querying from Javascript

● Same origin policy

● Cross-origin resource sharing (CORS)Access­Control­Allow­Origin: *

$.ajax({     “type”: “POST”,     “url”: endpoint,     “data”: data,     “success”: update,     “dataType”: “json”  });

http://news.netcraft.com/archives/2008/01/08/italian_banks_xss_opportunity_seized_by_fraudsters.html

The Access-Control-Allow-Origin header should contain the value that was sent in the request's Origin header.

http://www.w3.org/TR/cors/

Page 4: Visualizing Web Data Query Results

A simple query via Javascript

function sparql() {    var data =  {"query": $("#query").text(),               "output": "json" };  $.ajax({      type: 'POST',      url: $("#endpoint").text(),,      data: data,      success: update,      dataType: "json"  });}

Page 5: Visualizing Web Data Query Results

SPARQL-JSON

● Raw● Not what you want to visualize● Used to build other points of view

select ?place where { ?place rdf:type dbpedia-owl:PopulatedPlace } limit 5

{ "head": { "link": [], "vars": ["place"] }, "results": { "distinct": false, "ordered": true, "bindings": [ { "place": { "type": "uri", "value": "http://dbpedia.org/resource/Puerto_Williams" }}, { "place": { "type": "uri", "value": "http://dbpedia.org/resource/Bouvet_Island" }}, { "place": { "type": "uri", "value": "http://dbpedia.org/resource/Falkland_Islands" }}, { "place": { "type": "uri", "value": "http://dbpedia.org/resource/Puerto_Chacabuco" }}, { "place": { "type": "uri", "value": "http://dbpedia.org/resource/Puerto_Cisnes" }} ] } }

Page 6: Visualizing Web Data Query Results

Parsing the results...Generating a table header

var header = "<table id='results'><thead>";

$.each(json.head.vars, 

       function (index,v) {

          header += "<th>"+v+"</th>";

       });

header += "</thead>";

?place

Page 7: Visualizing Web Data Query Results

Parsing the results...Generating a table body.

var body = "<tbody>";$.each(json.results.bindings, 

       function(index, element) {

       }

body += "</tbody>";

// insert a table$('#view').html(header+body);

 function(index, element) {body += "<tr>";

        $.each(json.head.vars,                 function (vIndex,v) {                  body += "<td>"+element[v].value+"</td>";               });         body += "</tr>";       }); ?place

http://dbpedia.org/resource/Puerto_Williams

http://dbpedia.org/resource/Bouvet_Island

http://dbpedia.org/resource/Puerto_Cisnes

http://dbpedia.org/resource/Puerto_Chacabuco

Page 8: Visualizing Web Data Query Results

Debugging Javascript

Page 9: Visualizing Web Data Query Results

Spark (intro)

● A library for embedding SPARQL results in HTML

● Created by: ● Denny Vrandečić and Andreas Harth

● Source code:● http://code.google.com/p/rdf-spark/

● License:● New BSD License

Page 10: Visualizing Web Data Query Results

Spark (main elements)

● data-spark-endpoint● where to send queries?● must be CORS-enabled

● data-spark-format● Javascript class to transform results into HTML

● data-spark-query● The SPARQL query to fetch data for you

Page 11: Visualizing Web Data Query Results

Spark (setup)

<div class="spark"data-spark-endpoint="http://dbpedia.org/sparql"data-spark-format="http://km.aifb.kit.edu/sites/spark/src/jquery.spark.simpletable.js"data-spark-query="select distinct ?City ?State ?Population

where {?c dbpedia-owl:federalState ?s .?c rdfs:label ?City .?s rdfs:label ?State .?c dbpedia-owl:populationTotal ?Population .filter(langMatches(lang(?City),&quot;en&quot;)) .filter(langMatches(lang(?State),&quot;en&quot;)) .

}order by desc[?Population]limit 20"

>

Page 12: Visualizing Web Data Query Results

Spark (rendering)

http://km.aifb.kit.edu/sites/spark/docs/example/simpletable.html

Page 13: Visualizing Web Data Query Results

Sgvizler (intro)

● Inspired by Spark, offers prepackaged visualizations

● Created by:● Martin G. Skjæveland

● Source code:● http://code.google.com/p/sgvizler/

● License:● MIT License

Page 14: Visualizing Web Data Query Results

Sgvizler (more)

All the major chart types offered by the Google Visualization API are supported by Sgvizler.

Page 15: Visualizing Web Data Query Results

Sgvizler (setup)

<div id="sgvzl_example1" data-sgvizler-endpoint="http://sws.ifi.uio.no/sparql/npd" data-sgvizler-query="SELECT ?class (count(?instance) AS ?noOfInstances) WHERE{ ?instance a ?class } GROUP BY ?class ORDER BY ?class" data-sgvizler-chart="gPieChart" style="width:800px; height:400px;"></div>

Page 16: Visualizing Web Data Query Results

Sgvizler (rendering)

Page 17: Visualizing Web Data Query Results

Sgvizler (Designing Queries)

● Each type expects the SPARQL results to be in a specific format, e.g.● 1st column = labels, ● other columns = series

http://code.google.com/p/sgvizler/wiki/DesigningQueries

Page 18: Visualizing Web Data Query Results

Good practices

● Display readable things● Prefer labels over qNames over URIs● Ask for an optional rdfs:label. Others:

skos:preferredLabel● If possible, select the label matching language in

the browser

Page 19: Visualizing Web Data Query Results

Good practices

● Paginate results● SPARQL servers have a heart, be gentle with them:

– Watch for unnecessary repeated subsecond requests– use LIMIT, OFFSET

● Many JS libraries include support for pagination– e.g. YUI, Google Charts

Page 20: Visualizing Web Data Query Results

In Practice

● http://www2012.pablomendes.com/

Page 21: Visualizing Web Data Query Results

Hands on!

http://www2012.pablomendes.com/handson/

Page 22: Visualizing Web Data Query Results