« SPARQL Protocol and RDF Query Language/Travail pratique/Faire un serveur SPARQL » : différence entre les versions
Contenu supprimé Contenu ajouté
Ligne 288 :
=== Tests ===
<source lang="bash">
cd ~/projets
mkdir test4store
cd test4store
vim query.php
</source>
<source lang="php">
<?php
require_once('php4store/Endpoint.php');
$graph = "http://www.bordercloud.com";
$endpoint ="http://localhost:8080/sparql/";
// WRITE ******************************************
//put argument false to write
$readonly = false;
$sp_write = new Endpoint('http://localhost:8080/',$readonly);
echo "\nInsert :";
$q = "
PREFIX a: <http://example.com/test/a/>
PREFIX b: <http://example.com/test/b/>
INSERT DATA {
GRAPH <".$graph."> {
a:A b:Name \"Test1\" .
a:A b:Name \"Test2\" .
a:A b:Name \"Test3\" .
}}";
$res = $sp_write->query($q,'raw');
//Search errors
$err = $sp_write->getErrors();
if ($err) {
print_r($err);
throw new Exception(print_r($err,true));
}
//print result
var_dump($res);
// DELETE ******************************************
echo "\nDelete :";
$q = "
PREFIX a: <http://example.com/test/a/>
PREFIX b: <http://example.com/test/b/>
DELETE DATA {
GRAPH <".$graph."> {
a:A b:Name \"Test2\" .
}}";
$res = $sp_write->query($q,'raw');
$err = $sp_write->getErrors();
if ($err) {
print_r($err);
throw new Exception(print_r($err,true));
}
var_dump($res);
// READ ONLY ******************************************
//put argument false to write
$readonly = true;
$sp_readonly = new Endpoint('http://localhost:8080/',$readonly);
echo "\nPrint :";
$q = "select * where { GRAPH <".$graph."> {?x ?y ?z.}} ";
$rows = $sp_readonly->query($q, 'rows');
$err = $sp_readonly->getErrors();
if ($err) {
print_r($err);
throw new Exception(print_r($err,true));
}
var_dump($rows);
echo "\nASK :";
$q = "PREFIX a: <http://example.com/test/a/>
PREFIX b: <http://example.com/test/b/>
ask where { GRAPH <".$graph."> {a:A b:Name \"Test3\" .}} ";
$res = $sp_readonly->query($q, 'raw');
$err = $sp_readonly->getErrors();
if ($err) {
print_r($err);
throw new Exception(print_r($err,true));
}
var_dump($res);
</source>
<source lang="bash">
php query.php
</source>
<source lang="text">
ASK :bool(true)
</source>
<source lang="bash">
tail /var/log/4store/query-test.log
</source>
[[Catégorie:SPARQL Protocol and RDF Query Language]]
|