forked from ktym/d3sparql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3sparql-forcegraph.html
81 lines (78 loc) · 2.78 KB
/
d3sparql-forcegraph.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap.css"/>
<script src="lib/d3/d3.v3.min.js"></script>
<script src="d3sparql.js"></script>
<script>
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 = {
"charge": -500,
"distance": 50,
"width": 1000,
"height": 750,
"selector": "#result"
}
d3sparql.forcegraph(json, config)
}
function exec_offline() {
d3.json("cache/dbpedia/proglang_pair.json", render)
}
function toggle() {
d3sparql.toggle()
}
</script>
</head>
<body>
<div id="query" style="margin: 10px">
<h1>d3forcegraph</h1>
<form class="form-inline">
<label>SPARQL endpoint:</label>
<div class="input-append">
<input id="endpoint" class="span5" value="http://dbpedia.org/sparql" type="text">
<button class="btn" type="button" onclick="exec()">Query</button>
<button class="btn" type="button" onclick="exec_offline()">Use cache</button>
<button class="btn" type="button" onclick="toggle()"><i id="button" class="icon-chevron-up"></i></button>
</div>
</form>
<textarea id="sparql" class="span9" rows=15>
# https://en.wikipedia.org/wiki/History_of_programming_languages
# https://en.wikipedia.org/wiki/Perl
# http://dbpedia.org/page/Perl
# http://dbpedia.org/sparql
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 dbpprop: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT DISTINCT ?lang1 ?lang2 ?lang1label ?lang2label ?lang1value ?lang2value ?lang1year ?lang2year
WHERE {
?lang1 rdf:type dbpedia-owl:ProgrammingLanguage ;
rdfs:label ?lang1name ;
dbpprop:year ?lang1year .
?lang2 rdf:type dbpedia-owl:ProgrammingLanguage ;
rdfs:label ?lang2name ;
dbpprop:year ?lang2year .
?lang1 dbpedia-owl:influenced ?lang2 .
FILTER (?lang1 != ?lang2)
FILTER (LANG(?lang1name) = 'en')
FILTER (LANG(?lang2name) = 'en')
BIND (replace(?lang1name, " .programming language.", "") AS ?lang1label)
BIND (replace(?lang2name, " .programming language.", "") AS ?lang2label)
FILTER (?lang1year > 1950 AND ?lang1year < 2020)
FILTER (?lang2year > 1950 AND ?lang2year < 2020)
# To render older language larger than newer
BIND ((2020 - ?lang1year) AS ?lang1value)
BIND ((2020 - ?lang2year) AS ?lang2value)
}
</textarea>
</div>
<div id="result"></div>
</body>
</html>