Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SPARQLによる可視化 / sparql visualization

fumi
August 31, 2016

SPARQLによる可視化 / sparql visualization

2016-08-31 に第10回 AIツールセミナー入門で行ったハンズオンの資料

fumi

August 31, 2016
Tweet

More Decks by fumi

Other Decks in Technology

Transcript

  1. 41"32-ͷՄࢹԽ ࣗલ w 41"32-݁Ռ͸ܾ·ͬͨߏ଄ͷ+40/΍9.-ͳͷͰɺ ௚઀)551Ͱ໰͍߹Θͤͯ࢖͑͹ྑ͍ w ଟ͘ͷݴޠͰ͸41"32-ॲཧ༻ͷϥΠϒϥϦ΋͋Δ w දࣔ෦෼͸ࣗલͰ࡞Δඞཁ͕͋Δ function

    query(endpoint, sparql, callback) { var url = endpoint + "?query=" + encodeURIComponent(sparql); $.getJSON(url, function(json){ callback(json) } }
  2. ରԠܗࣜ w $IBSU w #BSDIBSU w 4DBUUFSQMPU w 1JFDIBSU w

    (SBQI w 'PSDFHSBQI w 4BOLFZ w 5SFF w %FOESPHSBN w 5SFFNBQ w 5SFFNBQ;PPN w 3PVOE5SFF w $JSDMFQBDL w 4VOCVSTU w .BQ w $PPSENBQ w /BNFENBQ w 5BCMF w )5.-5BCMF w )5.-)BTI 9
  3. 10

  4. PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX yago: <http://dbpedia.org/class/yago/> PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> SELECT

    ?label ?size WHERE { ?s a yago:PrefecturesOfJapan ; rdfs:label ?label; dbpedia-owl:areaTotal ?area_total . FILTER (lang(?label) = 'ja') BIND ((?area_total / 1000000) AS ?size) } ORDER BY DESC(?size)
  5. function exec() { var endpoint = d3.select("#endpoint").property("value") var sparql =

    d3.select("#sparql").property("value") d3sparql.query(endpoint, sparql, render) } function render(json) { var config = { "label_x": "౎ಓ෎ݝ", "label_y": "໘ੵ", "var_x": "label", "var_y": "size", "width": 800, "height": 400, "margin": 100, "selector": "#result" } d3sparql.barchart(json, config) } ର৅ͷม਺໊ΛDPOpHͰࢦఆ #BSDIBSUͷݺͼग़͠
  6. 16

  7. function render(json) { var config = { "label": "label", "size":

    "size", "width": 600, "height": 600, "margin": 10, "hole": 200, // doughnut hole: 0 for pie, r > 0 for doughnut "selector": "#result" } d3sparql.piechart(json, config) }
  8. PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX yago: <http://dbpedia.org/class/yago/> PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> SELECT

    DISTINCT ?s ?label ?population ?area ?density WHERE { ?s a yago:PrefecturesOfJapan ; rdfs:label ?label ; dbpedia-owl:populationTotal ?population ; dbpedia-owl:areaTotal ?area . BIND (xsd:float(?population)/xsd:float(?area/1000000) AS ?density) FILTER (lang(?label) = 'ja' ) } ORDER BY DESC(?density) ಛఆͷม਺໊ΛOBNFENBQͷDPOpHͰࢦఆ
  9. function exec() { var endpoint = d3.select("#endpoint").property("value") var sparql =

    d3.select("#sparql").property("value") d3sparql.query(endpoint, sparql, render) } function render(json) { var config = { "label": "label", "value": "density", "topojson": "https://gist.githubusercontent.com/fumi/ 521c759efe0648b3c1296c5a869b3406/raw/ 39e94dae1c46ed71d88529038f3ff45e681b257c/japan.topojson", "mapname": "japan", "color_max": "red", "color_min": "white", "center_lat": 34, "center_lng": 137, "scale": 1500, "selector": "#result" } d3sparql.namedmap(json, config) }
  10. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> PREFIX

    prop-ja: <http://ja.dbpedia.org/property/> SELECT ?root_name ?parent_name ?child_name WHERE { VALUES ?root_name { "౦ژӺ"@ja } ?root rdfs:label ?root_name . ?root prop-ja:࣍ͷӺ{1,5} ?child . ?parent prop-ja:࣍ͷӺ ?child . MINUS { ?child prop-ja:࣍ͷӺ ?parent . } ?parent rdfs:label ?parent_name . ?child rdfs:label ?child_name . FILTER (LANG(?parent_name) = 'ja') FILTER (LANG(?child_name) = 'ja') } GROUP BY ?root_name ?parent_name ?child_name
  11. <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/ libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css"/> <script src="https://d3js.org/d3.v3.min.js"></script> <link rel="stylesheet" type="text/css"

    href="lib/bootstrap/css/bootstrap.css"/> <script src="lib/d3/d3.v3.min.js"></script> (JU)VCͷίʔυΛͱΓ͋͑ͣϩʔΧϧͰ࣮ߦ ͢ΔͨΊʹ͸ҎԼͷมߋΛ͢Δ