-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
244 lines (208 loc) · 7.24 KB
/
index.php
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
# calculate base path
$path = explode("/", __FILE__);
array_pop( $path ); # lose filename
$base_dir = join( "/", $path );
require_once( "$base_dir/lib/TripleChecker.php" );
$prefs = array(
"cache"=>"$base_dir/cache",
"namespaces"=>"$base_dir/etc/namespaces.tsv",
"cacheUnknownNamespaces"=>false,
"reloadCache"=>false,
"cacheAge"=>14*24*60*60, # seconds,
);
require_once( "$base_dir/etc/template.php" );
#$_GET['uri'] = 'https://raw.github.com/structureddynamics/Bibliographic-Ontology-BIBO/1.3/bibo.xml.owl';
if( !isset( $_GET['uri'] ) )
{
render_header("front","RDF Triple-Checker");
print "<h1>RDF Triple-Checker</h1>";
?>
<p>This tool helps find typos and common errors in RDF data.</p>
<p>Enter a URI or URL which will resolve to some RDF Triples.</p>
<form>
<table width='80%' style='margin:auto'>
<tr>
<td align='right'>URI/URL:</td><td width='100%'><input id='uri' name='uri' value='' style='width:100%' /></td></tr>
</table>
<div style='margin-top:0.5em'>Output: <label><input checked='checked' type='radio' name='output' value='html' /> HTML</label> <label><input type='radio' name='output' value='json'/> JSON</label></div>
<div><input style='margin-top:0.5em' value='Check' type='submit' /></div>
</form>
<p>Drag this <a class="bookmarklet" href="javascript:window.location = "http://graphite.ecs.soton.ac.uk/checker/?uri="+encodeURIComponent(window.location.href);">3-Check</a> bookmarklet to your bookmarks to create a quick button for sending your current URL to triple-checker.</p>
<?php
render_footer();
# lazy but workable solution to autoselect the input form, and if it doesn't work it's
# nott he end of the world, just the end of this HTML document.
print "<script type='text/javascript'>document.getElementById('uri').focus()</script>";
exit;
}
$check_uri = $_GET["uri"];
$tc = new TripleChecker($prefs);
$result = $tc->checkURI( $check_uri );
if( @$_GET["output"]=="json" )
{
header( "Content-type: application/json" );
#print json_encode( $result, JSON_PRETTY_PRINT );
print json_encode( $result );
exit;
}
render_header( "results", htmlspecialchars( $result["uri"] )." - RDF Triple-Checker");
print "<h1>RDF Triple-Checker</h1>";
print "<form>
<table width='80%' style='margin:auto'>
<tr>
<td align='right'>URI/URL:</td><td width='100%'><input id='uri' name='uri' value='".htmlspecialchars($result["uri"])."' style='width:100%' /></td></tr>
</table>
<div style='margin-top:0.5em'>Output: <label><input checked='checked' type='radio' name='output' value='html' /> HTML</label> <label><input type='radio' name='output' value='json'/> JSON</label></div>
<div><input style='margin-top:0.5em' value='Check Again' type='submit' /></div>
</form>";
if( !$result["loaded"] )
{
print "<div class='error'><h3>Error loading: ".htmlspecialchars($result["uri"])."</h3><ul><li>".join( "</li><li>",$result["load_errors"])."</li></ul></div>";
render_footer();
exit;
}
print "<div class='message'>Loaded ".$result["triples_count"]." triples</div>";
######################################################
# Compare namespaces to dictionary
######################################################
print "<h2>Namespaces</h2>";
print "<table class='results'>";
print "<tr>";
print "<th>Namespace</th>";
print "<th>Looks Legit?</th>";
print "</tr>";
foreach ( $result["namespaces"] as $ns=>$info )
{
$nscell = "<td><a href='$ns'>".htmlspecialchars( $ns )."</a></td>";
if( $info["found"] )
{
print "<tr class='good'>";
print $nscell;
print "<td>Matched common namespace. Prefix <strong>".$info["prefix"]."</strong></td>";
print "</tr>";
continue;
}
$nearest = $info["nearest"];
if( $nearest["distance"] <= 3 )
{
print "<tr class='bad'>";
print $nscell;
print "<td>VERY close match to <".$nearest["namespace"]."> .. probable typo? <span class='diff'>[diff=".$nearest["distance"]."]</span></td>";
print "</tr>";
continue;
}
if( $nearest["distance"] <= 8 )
{
print "<tr class='bad'>";
print $nscell;
print "<td>Somewhat similar to <".$nearest["namespace"]."> .. possible typo? <span class='diff'>[diff=".$nearest["distance"]."]</span></td>";
print "</tr>";
continue;
}
print "<tr class='unknown'>";
print $nscell;
print "<td>No match to common namespaces</td>";
print "</tr>";
}
print "</table>";
######################################################
# Check terms in namespaces
######################################################
print "<h2>Terms</h2>";
print "<table class='results'>";
print "<tr>";
print "<th>Count</th>";
print "<th>Type</th>";
print "<th style='text-align:right'>Namespace</th>";
print "<th>Term</th>";
print "<th colspan='2'>Looks Legit?</th>";
print "</tr>";
foreach ( $result["namespaces"] as $ns=>$nsinfo )
{
foreach( $nsinfo["terms"] as $term=>$terminfo )
{
if( !$nsinfo["loaded"] )
{
print "<tr class='unknown'>";
}
elseif( $terminfo["found"] )
{
print "<tr class='good'>";
}
else
{
print "<tr class='bad'>";
}
print "<td class='count'>".$terminfo["count"]."</td>";
print "<td class='type'>".$terminfo["type"]."</td>";
print "<td class='ns' style='text-align:right;font-size:80%'>".$ns."</td>";
print "<td class='term'><a href='$ns$term'>$term</a></td>";
if( !$nsinfo["loaded"] )
{
print "<td class='legit'>?</td>";
print "<td class='comment'> - Namespace not loaded</td>";
}
elseif( $terminfo["found"] )
{
print "<td class='legit'>OK</td>";
print "<td class='comment'> - Looks good.</td>";
}
elseif( $terminfo["nearest"]["distance"] <= 3 )
{
print "<td class='legit'>ERROR</td>";
print "<td class='comment'> - VERY close match to "".$terminfo["nearest"]["term"]."" .. probable typo? <span class='diff'>[diff=".$terminfo["nearest"]["distance"]."]</span></td>";
}
elseif( $terminfo["nearest"]["distance"] <= 8 )
{
print "<td class='legit'>ERROR</td>";
print "<td class='comment'> - Possible match to "".$terminfo["nearest"]["term"]."" .. probable typo? <span class='diff'>[diff=".$terminfo["nearest"]["distance"]."]</span></td>";
}
else
{
print "<td class='legit'>ERROR</td>";
print "<td class='comment'> - No near matches found</td>";
}
print "</tr>";
}
}
print "</table>";
#print "<pre style='text-align:left'>".htmlspecialchars( print_r( $result ,true))."</pre>";
if( sizeof( $result["datatype_errors"] ) )
{
print "<h2>Literals</h2>";
print "<table class='results'>";
print "<tr>";
print "<th>Datatype</th>";
print "<th>Value</th>";
print "<th>Issues</th>";
print "</tr>";
foreach( $result["datatype_errors"] as $datatype=>$datatype_errors )
{
$rows = 0;
foreach( $datatype_errors as $literal=>$issues ) { $rows+=sizeof($issues); }
print "<tr class='bad'>";
print "<td class='datatype' rowspan='$rows'>".$datatype."</td>";
$first_value = true;
foreach( $datatype_errors as $literal=>$issues )
{
if( !$first_value ) { print "</tr><tr class='bad'>"; }
print "<td rowspan='".sizeof($issues)."'>\"".htmlspecialchars($literal)."\"</td>";
$first_issue = true;
foreach( $issues as $issue=>$count )
{
if( !$first_issue ) { print "</tr><tr class='bad'>"; }
print "<td>";
print $issue;
if( $count > 1 ) { print " ($count counts)"; }
print "</td>";
print "</tr>";
$first_issue = false;
}
$first_value = false;
}
}
print "</table>";
}
render_footer();
exit;