-
Notifications
You must be signed in to change notification settings - Fork 0
/
consulta.php
68 lines (54 loc) · 2.12 KB
/
consulta.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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<title>Estados Brasileiros</title>
</head>
<body>
<h1>Estados Brasileiros</h1>
<h3>Dados trazidos de <a href="http://dbpedia.org/">dbpedia.org</a></h3>
<?php
require_once( "sparqllib.php" );
$db = sparql_connect( "http://dbpedia.org/sparql/" );
if ( !$db )
{
print "<p class=\"error\">" . sparql_errno() . ": " . sparql_error() . "</p>";
exit;
}
sparql_ns( "foaf","http://xmlns.com/foaf/0.1/" );
$sparql = "select distinct ?Estado ?Populacao where {
?estados <http://dbpedia.org/ontology/type> <http://dbpedia.org/resource/States_of_Brazil>.
?estados <http://dbpedia.org/property/name> ?Estado.
?estados <http://dbpedia.org/property/populationTotal> ?Populacao.
} ORDER BY DESC(?Populacao)";
$result = sparql_query( $sparql );
if( !$result )
{
print "<p class=\"error\">" . sparql_errno() . ": " . sparql_error(). "</p>";
exit;
}
$fields = sparql_field_array( $result );
print "<table>";
print "<caption>População dos Estados brasileiros</caption>";
print "<tr>";
foreach( $fields as $field )
{
print "<th scope=\"col\">$field</th>";
}
while( $row = sparql_fetch_array( $result ) )
{
print "<tr>";
foreach( $fields as $field )
{
$uf = str_ireplace("State", "", "$row[$field]");
$uf = str_ireplace(" of", "", "$uf");
$uf = str_ireplace("Brazilian Federal District", "Distrito Federal", "$uf");
print "<td>$uf</td>";
}
print "</tr>";
}
print "</tr>";
print "</table>";
?>
</body>
</html>