SlideShare a Scribd company logo
Visualizing Web Data
    Query Results




     Pablo N. Mendes
pablo.mendes@fu-berlin.de

   WWW2012 Tutorial
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!
Preliminaries
●   Querying from Javascript                                                        $.ajax({
                                                                                         “type”: “POST”,
                                                                                         “url”: endpoint,
                                                                                         “data”: data,
                                                                                         “success”: update,
                                                                                         “dataType”: “json”
                                                                                      });

●   Same origin policy



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




●   Cross-origin resource sharing (CORS)                                                                          http://www.w3.org/TR/cors/


           Access­Control­Allow­Origin: *
            The Access-Control-Allow-Origin header should contain the value that was sent in the request's Origin header.
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"
  });
}
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" }} ] } }
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
Parsing the results...
              Generating a table body.
var body = "<tbody>";
$.each(json.results.bindings, 
       function(index, element) {
       function(index, element) {
         body += "<tr>";
        $.each(json.head.vars, 
                function (vIndex,v) {
                  body += "<td>"+element[v].value+"</td>";
               });
       }
         body += "</tr>";
       });                                      ?place
body += "</tbody>";             http://dbpedia.org/resource/Puerto_Williams

// insert a table               http://dbpedia.org/resource/Bouvet_Island
$('#view').html(header+body);

                                http://dbpedia.org/resource/Puerto_Cisnes
                                http://dbpedia.org/resource/Puerto_Chacabuco
Debugging Javascript
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
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
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"
     >
Spark (rendering)




http://km.aifb.kit.edu/sites/spark/docs/example/simpletable.html
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
Sgvizler (more)




     All the major chart types offered by the
Google Visualization API are supported by Sgvizler.
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>
Sgvizler (rendering)
Sgvizler (Designing Queries)
                                 http://code.google.com/p/sgvizler/wiki/DesigningQueries



●   Each type expects the SPARQL results to be in
    a specific format, e.g.
    ●
        1st column = labels,
    ●   other columns = series
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
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
In Practice
●   http://www2012.pablomendes.com/
Hands on!
http://www2012.pablomendes.com/handson/
Visualizing Web Data Query Results

More Related Content

PDF
d3sparql.js demo at SWAT4LS 2014 in Berlin
PPT
Introduction to couch_db
PDF
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
PDF
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
PDF
Hotcode 2013: Javascript in a database (Part 1)
KEY
dojo.data, stores and widgets
PDF
An introduction to MongoDB
PDF
mongodb-introduction
d3sparql.js demo at SWAT4LS 2014 in Berlin
Introduction to couch_db
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
Hotcode 2013: Javascript in a database (Part 1)
dojo.data, stores and widgets
An introduction to MongoDB
mongodb-introduction

What's hot (17)

ODP
2011 Mongo FR - Indexing in MongoDB
KEY
An introduction to CouchDB
PDF
Elastify you application: from SQL to NoSQL in less than one hour!
PPT
Mongo-Drupal
ODP
Terms of endearment - the ElasticSearch Query DSL explained
KEY
Mongo db presentation
ODP
DrupalCon Chicago Practical MongoDB and Drupal
PDF
MongoDB and RDBMS
PDF
10gen Presents Schema Design and Data Modeling
PDF
Full metal mongo
KEY
Schema Design with MongoDB
PPTX
PPTX
JSON-LD update DC 2017
PPTX
Mongo db
PPTX
MongoDB (Advanced)
PDF
Building Apps with MongoDB
PDF
DBIx::Class walkthrough @ bangalore pm
2011 Mongo FR - Indexing in MongoDB
An introduction to CouchDB
Elastify you application: from SQL to NoSQL in less than one hour!
Mongo-Drupal
Terms of endearment - the ElasticSearch Query DSL explained
Mongo db presentation
DrupalCon Chicago Practical MongoDB and Drupal
MongoDB and RDBMS
10gen Presents Schema Design and Data Modeling
Full metal mongo
Schema Design with MongoDB
JSON-LD update DC 2017
Mongo db
MongoDB (Advanced)
Building Apps with MongoDB
DBIx::Class walkthrough @ bangalore pm
Ad

Similar to Visualizing Web Data Query Results (20)

PDF
Visualize open data with Plone - eea.daviz PLOG 2013
PPTX
A Real-World Implementation of Linked Data
PDF
Querying Linked Data with SPARQL (2010)
PDF
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...
PDF
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...
PDF
Querying Linked Data with SPARQL
PPTX
APIs and the Semantic Web: publishing information instead of data
PPT
Re-using Media on the Web: Media fragment re-mixing and playout
PDF
MongoDB and Web Scrapping with the Gyes Platform
PDF
Context-Aware Access Control for RDF Graph Stores
PPTX
Semantic Web and Related Work at W3C
PDF
Linking the world with Python and Semantics
KEY
Creating web applications with LODSPeaKr
ODP
SPARQL 1.1 Update (2013-03-05)
PDF
Webinar: Semantic web for developers
PPTX
Triplestore and SPARQL
PDF
SFScon 2020 - Peter Hopfgartner - Open Data de luxe
PPTX
Introduction to SPARQL
PPTX
Introduction to SPARQL
PPTX
Madrid SPARQL handson
Visualize open data with Plone - eea.daviz PLOG 2013
A Real-World Implementation of Linked Data
Querying Linked Data with SPARQL (2010)
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...
Querying Linked Data with SPARQL
APIs and the Semantic Web: publishing information instead of data
Re-using Media on the Web: Media fragment re-mixing and playout
MongoDB and Web Scrapping with the Gyes Platform
Context-Aware Access Control for RDF Graph Stores
Semantic Web and Related Work at W3C
Linking the world with Python and Semantics
Creating web applications with LODSPeaKr
SPARQL 1.1 Update (2013-03-05)
Webinar: Semantic web for developers
Triplestore and SPARQL
SFScon 2020 - Peter Hopfgartner - Open Data de luxe
Introduction to SPARQL
Introduction to SPARQL
Madrid SPARQL handson
Ad

More from Anja Jentzsch (9)

PDF
Wikidata
PDF
Linked Data
PDF
LODOP - Multi-Query Optimization for Linked Data Profiling Queries
PDF
DBpedia Mappings Wiki, SMWCon Fall 2013, Berlin
PDF
Linked Data (1st Linked Data Meetup Malmö)
PDF
Wikidata - The free knowledge base that anyone can edit (1st Linked Data Meet...
PDF
Link Sets And Why They Are Important (EDF2012)
PDF
Finding Data Sets
PDF
Linked Data Basics
Wikidata
Linked Data
LODOP - Multi-Query Optimization for Linked Data Profiling Queries
DBpedia Mappings Wiki, SMWCon Fall 2013, Berlin
Linked Data (1st Linked Data Meetup Malmö)
Wikidata - The free knowledge base that anyone can edit (1st Linked Data Meet...
Link Sets And Why They Are Important (EDF2012)
Finding Data Sets
Linked Data Basics

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Spectroscopy.pptx food analysis technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Cloud computing and distributed systems.
PDF
KodekX | Application Modernization Development
PPTX
sap open course for s4hana steps from ECC to s4
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25 Week I
Spectroscopy.pptx food analysis technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.
KodekX | Application Modernization Development
sap open course for s4hana steps from ECC to s4

Visualizing Web Data Query Results

  • 1. Visualizing Web Data Query Results Pablo N. Mendes [email protected] WWW2012 Tutorial
  • 2. 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!
  • 3. Preliminaries ● Querying from Javascript $.ajax({      “type”: “POST”,      “url”: endpoint,      “data”: data,      “success”: update,      “dataType”: “json”   }); ● Same origin policy http://news.netcraft.com/archives/2008/01/08/italian_banks_xss_opportunity_seized_by_fraudsters.html ● Cross-origin resource sharing (CORS) http://www.w3.org/TR/cors/ Access­Control­Allow­Origin: * The Access-Control-Allow-Origin header should contain the value that was sent in the request's Origin header.
  • 4. 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"   }); }
  • 5. 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" }} ] } }
  • 6. 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
  • 7. Parsing the results... Generating a table body. var body = "<tbody>"; $.each(json.results.bindings,   function(index, element) {        function(index, element) { body += "<tr>";         $.each(json.head.vars,                  function (vIndex,v) {                   body += "<td>"+element[v].value+"</td>";                });        }          body += "</tr>";        }); ?place body += "</tbody>"; http://dbpedia.org/resource/Puerto_Williams // insert a table http://dbpedia.org/resource/Bouvet_Island $('#view').html(header+body); http://dbpedia.org/resource/Puerto_Cisnes http://dbpedia.org/resource/Puerto_Chacabuco
  • 9. 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
  • 10. 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
  • 11. 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" >
  • 13. 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
  • 14. Sgvizler (more) All the major chart types offered by the Google Visualization API are supported by Sgvizler.
  • 15. 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>
  • 17. Sgvizler (Designing Queries) http://code.google.com/p/sgvizler/wiki/DesigningQueries ● Each type expects the SPARQL results to be in a specific format, e.g. ● 1st column = labels, ● other columns = series
  • 18. 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
  • 19. 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
  • 20. In Practice ● http://www2012.pablomendes.com/