-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfallback-matchers.ttl
181 lines (174 loc) · 7.26 KB
/
fallback-matchers.ttl
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
@base <http://zazukoians.org/2016/generic-rdf2h-matchers/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix r2h: <http://rdf2h.github.io/2015/rdf2h#> .
@prefix dc: <http://purl.org/dc/elements/1.1/>.
@prefix s: <http://schema.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix zzm: <http://zz2h.zazukoians.org/modes/> .
@prefix zz2h: <http://zz2h.zazukoians.org/ontology/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix r2hp: <http://rdf2h.github.io/2015/rdf2h-points/> .
r2hp:fallback r2h:before <header> .
<header> a r2h:Matcher ;
r2h:template [
r2h:context r2h:Default;
r2h:mustache '''
<div id="sticky-anchor"></div>
<div id="sticky" class="list-group" style="width: 100%;">
<h4 class="list-group-item-heading">Resource: <a href="{{.}}">{{.}}</a></h4>
</div>
{{{:continue}}}'''
];
r2h:before <rdfTypes>.
<rdfTypes> a r2h:Matcher ;
r2h:triplePattern [
r2h:subject r2h:this;
r2h:predicate rdf:type;
];
r2h:template [
r2h:context r2h:Default;
r2h:mustache '''
<div id="sticky-anchor"></div>
<div id="sticky" class="list-group" style="width: 100%;">
<p class="list-group-item-text">is a {{#rdf:type}}<a href="{{.}}">{{.}}</a> {{/rdf:type}}</p>
<hr>
</div>
{{{:continue}}}'''
];
r2h:before <catchall>.
<catchall> a r2h:Matcher ;
r2h:template [
rdfs:comment '''Renders a full page, delegating to matchers in the default
context for the body, and to zzm:HtmlHead for things like the html title''';
r2h:context zzm:FullPage;
r2h:mustache '''
{{{@prefix r2h: <http://rdf2h.github.io/2015/rdf2h#>}}}
{{{@prefix zzm: <http://zz2h.zazukoians.org/modes/>}}}
<head>
{{{:render . zzm:HtmlHead}}}
</head>
<body>
{{{:render . zzm:HtmlBody}}}
</body>
'''
];
r2h:template [
r2h:context zzm:HtmlBody;
r2h:mustache '''<div id="header"></div>
{{{:render . r2h:Default}}}<div id="footer">
</div>'''
];
r2h:template [
r2h:context zzm:HtmlHead;
r2h:mustache '''
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
{{{:render . zzm:HtmlTitle}}}
'''
];
r2h:template [
r2h:context zzm:HtmlTitle;
r2h:mustache '''
<title>Resource {{.}}</title>
'''
];
r2h:template [
r2h:context r2h:Default;
r2h:javaScript '''function(n) {
var prefixes = [{url: "http://schema.org/", shortcut: "s:"},
{url: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", shortcut: "rdf:"},
{url: "https://gont.ch/", shortcut: "gont:"},
{url: "http://www.w3.org/2004/02/skos/core#", shortcut: "skos:"},
{url: "http://www.w3.org/2002/07/owl#", shortcut: "owl:"},
{url: "http://dbpedia.org/resource/", shortcut: "dbr:"},
{url: "http://dbpedia.org/class/yago/", shortcut: "yago:"},
{url: "http://xmlns.com/foaf/0.1/", shortcut: "foaf:"},
{url: "http://www.wikidata.org/entity/", shortcut: "wikidata:"},
{url: "http://dbpedia.org/ontology/", shortcut: "dbo:"},
{url: "http://purl.org/dc/terms/", shortcut: "dct:"},
{url: "http://www.w3.org/2000/01/rdf-schema#", shortcut: "rdfs:"}];
var result = "";
var predicatesArray = [];
var nodesToRender = [];
if (!n.rdf2h.renderedNodesToId) {
n.rdf2h.renderedNodesToId = new Object();
}
var node = n.node;
var s = n.graph.filter(function(t) {return t.subject.equals(node)}).toArray();
if (s.length > 0) {
n.rdf2h.renderedNodesToId[node.toString()] = true;
result += '<div class="container" id="'+node+'"><table id="tt" width="100%">';
s.forEach(function(t) {
var objectHtml;
var prefix = "";
var predicate = t.predicate.toString();
var link = predicate;
prefixes.forEach(function(p) {
var predicateHtml = predicate.split(p.url);
if (predicateHtml[0] === "") {
prefix = p.shortcut;
predicate = predicateHtml[1];
}
});
if (t.object.interfaceName != "Literal") {
nodesToRender.push(t.object);
if (t.object.interfaceName == "BlankNode") {
objectHtml = '<div class="moving"></div><a onclick=\\'$("#'+
t.object+'")[0].scrollIntoView( true );\\'>'+t.object+'</a>';
} else {
var objectPrefix = "";
var object = t.object.toString().replace(/&/g,"&");
var objectLink = object;
prefixes.forEach(function(p) {
var objectSplit = object.split(p.url);
if (objectSplit[0] === "") {
objectPrefix = p.shortcut;
object = objectSplit[1];
}
});
if (objectPrefix === "") {
objectHtml = '<a href="'+objectLink+'" title="'+object+'">'+object+'</a>';
} else {
objectHtml = '<a href="'+objectLink+'" title="'+object+
'" style="color:#000000;text-decoration:none">'+
objectPrefix+'<b>'+object+'</b></a>';
}
}
} else {
objectHtml = t.object;
}
var isNew = true;
for (var i = 0; i < predicatesArray.length; i++) {
if (predicatesArray[i] === predicate) {
isNew = false;
break;
}
}
predicatesArray.push(predicate);
result += '<tr><td width="35%" cellpadding=".1em" valign="top" id="sticky">'+
'<a href="'+link+'" title="'+link+'" style="color:#000000;text-decoration:none">'+
prefix+'<b>'+predicate+'</b></a></td><td width="65%" cellpadding=".1em">'+
objectHtml+'<hr /></td>';
});
result += '</table></div>';
};
while (nodesToRender.length > 0) {
var subNode = nodesToRender.pop();
if ((n.graph.filter(function(gt) {return gt.subject.equals(subNode)}).toArray().length > 0) &&
(!n.rdf2h.renderedNodesToId[subNode.toString()])) {
result += n.rdf2h.render(n.graph, subNode, n.context);
}
}
console.log("getting subjects for"+node);
var backwardLinks = n.graph.filter(function(t) {return t.object.equals(node)}).toArray();
backwardLinks.forEach(function(t) {
var subjectNode = t.subject;
console.log(subjectNode);
if (!n.rdf2h.renderedNodesToId[subjectNode.toString()]) {
result += n.rdf2h.render(n.graph, subjectNode, n.context);
}
})
return result;
}'''
].