jcramalho

Serviço SPARQL em PHP

Mar 23rd, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2. require_once( "sparqllib.php" );
  3.  
  4. $db = sparql_connect( 'http://dbpedia.org/sparql' );
  5.  
  6. if( !$db )
  7. { print sparql_errno() . ": " . sparql_error(). "\n"; exit; }
  8.  
  9. # Vamos recuperar os URIs dos compositores do barroco
  10. $myquery = "select ?pessoa, ?nome where {
  11. ?pessoa dcterms:subject category:Baroque_composers.
  12. ?pessoa dbpprop:name ?nome.
  13. }
  14. ORDER BY ASC(?nome)";
  15.  
  16. $result = sparql_query( $myquery );
  17. if( !$result )
  18. { print sparql_errno() . ": " . sparql_error(). "\n"; exit; }
  19.  
  20. print "<table class='example_table' border='1'>\n";
  21. print " <tr><th>URI</th></tr>\n";
  22.  
  23. while( $row = sparql_fetch_array( $result ) )
  24. {
  25. print " <tr><td><a href='composer-pag.php?uri=".$row['pessoa']. "'>".$row['nome']."</a></td></tr>\n";
  26. }
  27. print "</table>";
  28.  
  29. print "<p>Number of rows: ".sparql_num_rows( $result )." results.</p>";
  30.  
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment