« XSLT Date and Time Processing Examples | Main | SPARQL Toot »

October 26, 2010

PHP script to run SPARQL queries against a 4store triple store

<?php

error_reporting(E_ERROR | E_PARSE);

require_once "HTTP/Request.php";

if($_GET['format']){

	header('Content-type: text/plain');

	} else { 

	header('Content-type: text/xml');

	}

$sparql = sprintf("PREFIX rss: <http://purl.org/rss/1.0/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dubco: <http://purl.org/dc/elements/1.1/>
PREFIX ev: <http://purl.org/rss/1.0/modules/event/>

select * { 
        ?item rss:title ?title . 
        ?item rss:link ?link . 
        ?item dc:date ?date .
        ?item dubco:description ?description .
	?item ev:location ?location .
        FILTER regex(str(?title), \"%s?\", 'i') . 
        } ORDER BY ?title", $_GET['query']);

$req = &new HTTP_Request('http://172.20.36.113:8080/sparql/'); 

if($_GET['format']){ $req->addHeader("Accept", "application/".$_GET['format']); }

$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addPostData("query", $sparql);
$req->sendRequest();

$response = $req->getResponseBody();

print $response;

print '<!--'.$sparql.'-->';

?>

 

Posted by pj at October 26, 2010 03:46 PM

Comments