Пример #1
0
function getDissertations($what)
{
    $query = '
PREFIX sd: <http://symbolicdata.org/Data/Model#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX dct: <http://purl.org/dc/terms/>
construct {
?a a bibo:Thesis .
?a dct:creator ?c . 
?a dct:title ?title . 
?a bibo:institution ?inst . 
?a dct:date ?year .  
?a dct:abstract ?abstract . 
?a sd:hasSupervisor ?s .
?a sd:hasReviewer ?r . 
?a sd:hasURL ?url . 
}
from <http://symbolicdata.org/Data/Dissertations/>
Where {
?a a bibo:Thesis ; dct:creator ?c ; dct:title ?title; 
dct:date ?year; bibo:degree <http://purl.org/ontology/bibo/degrees/' . $what . '>. 
optional { ?a bibo:institution ?inst .}
optional { ?a sd:hasSupervisor ?s .}
optional { ?a sd:hasReviewer ?r . }
optional { ?a sd:hasURL ?url . }
optional { ?a dct:abstract ?abstract . }
} 
';
    $sparql = new EasyRdf_Sparql_Client('http://symbolicdata.org:8890/sparql');
    $result = $sparql->query($query);
    // a CONSTRUCT query returns an EasyRdf_Graph
    //echo $result->dump("turtle");
    return $result;
}
Пример #2
0
function getPeople($name, $affil)
{
    EasyRdf_Namespace::set('sd', 'http://symbolicdata.org/Data/Model#');
    $query = '
PREFIX sd: <http://symbolicdata.org/Data/Model#>
construct { ?a ?b ?c . }
from <http://symbolicdata.org/Data/People/>
from <http://symbolicdata.org/Data/AuthorIdentification/>
from <http://symbolicdata.org/Data/PersonalProfiles/>
from <http://symbolicdata.org/Data/BenchmarkReferences/>
Where { 
?a a foaf:Person ; ?b ?c; foaf:name $n . 
optional { ?a sd:affiliation $f . } 
filter regex(?n, "' . $name . '","i")
filter regex(?f, "' . $affil . '","i")
}  
LIMIT 100';
    $sparql = new EasyRdf_Sparql_Client('http://symbolicdata.org:8890/sparql');
    $result = $sparql->query($query);
    // a CONSTRUCT query returns an EasyRdf_Graph
    //echo $result->dump("turtle");
    /* generate data structure for output table */
    $s = array();
    foreach ($result->allOfType("foaf:Person") as $v) {
        $a = $v->getUri();
        $label = $v->get('foaf:name');
        $loc = $v->get('sd:affiliation');
        $hp = $v->get('foaf:homepage');
        $zb = $v->get('sd:hasZBMathAuthorID');
        $mr = $v->get('sd:hasMRAuthorID');
        $bs = $v->get('sd:providesDataAt');
        $pp = $v->get('sd:hasPersonalProfile');
        $out = '<p><dl> <dt><strong><a href="' . $a . '">' . $label . '</a></strong></dt>
';
        if (!empty($loc)) {
            $out .= '<dd>Affiliation: ' . $loc . '.</dd>';
        }
        if (!empty($hp)) {
            $out .= '<dd>Homepage: <a href="' . $hp . '">' . $hp . '</a></dd>';
        }
        if (!empty($pp)) {
            $out .= '<dd>Personal FOAF Profile: <a href="' . $pp . '">' . $pp . '</a></dd>';
        }
        if (!empty($zb)) {
            $out .= '<dd>ZBMath Author Code: <a href="' . $zb . '">' . $zb . '</a></dd>';
        }
        if (!empty($mr)) {
            $out .= '<dd>MR Author ID: <a href="' . $mr . '">' . $mr . '</a></dd>';
        }
        if (!empty($bs)) {
            $out .= '<dd>Provides Benchmark References at: <a href="' . $bs . '">' . $bs . '</a></dd>';
        }
        $out .= '</dl></p>';
        $s["{$a}"] = $out;
    }
    ksort($s);
    return '<h4>List of entries with foaf:name containing "' . $name . '" and sd:affiliation containing "' . $affil . '"</h4>' . join($s, "\n");
}
Пример #3
0
function SELECT($Query)
{
    try {
        $client = new EasyRdf_Sparql_Client(QueryEndPoint());
        return $client->query($Query);
    } catch (Exception $ex) {
        return null;
    }
}
Пример #4
0
 public function get_action($data)
 {
     EasyRdf_Namespace::set('o311', 'http://ontology.eil.utoronto.ca/open311.owl#');
     $sparql = new EasyRdf_Sparql_Client('http://localhost:8890/sparql');
     //SAMPLE QUERY: select * where {?sub o311:hasAddress o311:iiitCC3. ?sub o311:has311Subject o311:Waste. ?sub o311:need311Action ?action. ?sub o311:isHandledBy ?authority. ?authority o311:AgencyName ?name. ?authority o311:Phone ?phone. ?authority o311:Email ?email. ?authority o311:AddressType ?address }';
     $str = 'SELECT * WHERE {' . '?sub o311:hasAddress o311:' . $data["where"] . ". " . '?sub o311:has311Subject o311:' . $data["what"] . ". " . '?sub o311:isHandledBy ?authority. ' . '?sub o311:need311Action ?action. ' . '?authority o311:AgencyName ?name.' . '?authority o311:Phone ?phone.' . '?authority o311:Email ?email.' . '?authority o311:AddressType ?address.' . '} ';
     echo "<br><i><font color = 'grey'>{$str}</font></i><br>";
     $result = $sparql->query($str);
     return $result;
 }
Пример #5
0
function Update($Query)
{
    try {
        $client = new EasyRdf_Sparql_Client(UpdateEndPoint());
        $client->update($Query);
        return null;
    } catch (Exception $ex) {
        print $ex;
        return $ex;
    }
}
Пример #6
0
 public function indexAction()
 {
     $foaf = \EasyRdf_Graph::newAndLoad('http://njh.me/foaf.rdf');
     $me = $foaf->primaryTopic();
     \EasyRdf_Namespace::set('category', 'http://dbpedia.org/resource/Category:');
     \EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
     \EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
     \EasyRdf_Namespace::set('dbp', 'http://dbpedia.org/property/');
     $sparql = new \EasyRdf_Sparql_Client('http://dbpedia.org/sparql');
     $result = $sparql->query('SELECT * WHERE {' . '  ?country rdf:type dbo:Country .' . '  ?country rdfs:label ?label .' . '  ?country dc:subject category:Member_states_of_the_United_Nations .' . '  FILTER ( lang(?label) = "en" )' . '} ORDER BY ?label');
     return $this->render('MyAppBlogBundle:Default:index.html.twig', array('name' => $result, 'count' => $result->numRows()));
 }
Пример #7
0
 public function queryPhobias()
 {
     $result = $this->sparqlClient->query('select ?id ?label ?info ?link where{
             ?phobia dct:subject dbc:Phobias .
             ?phobia dbo:wikiPageID ?id .
             ?phobia rdfs:label ?label .
             ?phobia dbo:abstract ?info .
             ?phobia foaf:isPrimaryTopicOf ?link
             filter(lang (?label)="en" and lang(?info)="en")
             }');
     // TODO: remove
     //        var_dump($result);die;
     return $result;
 }
Пример #8
0
function getNews()
{
    EasyRdf_Namespace::set('sd', 'http://symbolicdata.org/Data/Model#');
    EasyRdf_Namespace::set('sioc', 'http://rdfs.org/sioc/ns#');
    $query1 = '
PREFIX sd: <http://symbolicdata.org/Data/Model#>
construct { ?a ?b ?c . }
from <http://symbolicdata.org/Data/News/>
Where { ?a a sioc:BlogPost ; ?b ?c . }
';
    $query2 = '
PREFIX sd: <http://symbolicdata.org/Data/Model#>
construct { ?p foaf:name ?n . }
from <http://symbolicdata.org/Data/News/>
from <http://symbolicdata.org/Data/People/>
Where { ?a a sioc:BlogPost ; dc:publisher ?p . 
  ?p foaf:name ?n . }
';
    $sparql = new EasyRdf_Sparql_Client('http://symbolicdata.org:8890/sparql');
    $result = $sparql->query($query1);
    // a CONSTRUCT query returns an EasyRdf_Graph
    //echo $result->dump("turtle");
    $people = $sparql->query($query2);
    //echo $people->dump("turtle");
    /* generate data structure for output table */
    $s = array();
    foreach ($result->allOfType("sioc:BlogPost") as $v) {
        $a = $v->getUri();
        $label = $v->get('rdfs:label');
        $created = $v->get('dc:created');
        $subject = $v->join('dc:subject');
        $abstract = $v->get('dc:abstract');
        $publisher = $people->get($v->get('dc:publisher'), 'foaf:name');
        $link = $v->get('sioc:link');
        $linksTo = $v->get('sioc:links_to');
        $out = '<p><dl> <dt><strong><a href="' . $a . '">' . $label . '</a></strong></dt>
';
        $out .= addLine($created, "Created");
        $out .= addLine($subject, "Subject");
        $out .= addLine($abstract, "Abstract");
        $out .= addLine($publisher, "Publisher");
        $out .= addLink($link, "More");
        $out .= addLink($linksTo, "Links to");
        $out .= '</dl></p>';
        $s["{$created_}{$a}"] = $out;
    }
    krsort($s);
    return join($s, "\n");
}
Пример #9
0
 public function get()
 {
     // sanitize request input
     $username = filter_input(INPUT_GET, 'username', FILTER_SANITIZE_STRING);
     $password = filter_input(INPUT_GET, 'password', FILTER_SANITIZE_STRING);
     $endpoint = filter_input(INPUT_GET, 'endpoint', FILTER_SANITIZE_URL);
     $query = filter_input(INPUT_GET, 'query', FILTER_UNSAFE_RAW);
     // prepare request content model
     if ($endpoint && $query) {
         HttpClient::useIdentity($username, $password);
         $sparql = new SparqlClient($endpoint);
         $result = $sparql->query($query);
     } else {
         $result = new Graph($_SERVER['REQUEST_URI']);
     }
     return self::stateTransfer($result, WebLink::factory('sparqlForm.php?' . http_build_query($_GET))->rel('edit'));
 }
 protected function linkData()
 {
     // use credential to access SPARQL server, if required
     if ($this->username) {
         HttpClient::useIdentity($this->username, $this->password);
     }
     if (!empty($this->endpoint) && !empty($this->constructor)) {
         // create links to data
         $sparql = new SparqlClient($this->endpoint);
         $endpointQuery = $this->templateEngine->setTemplate($this->constructor . ' LIMIT {limit} OFFSET {offset}')->render();
         $this->resultGraph = $sparql->query($endpointQuery);
         // add queryResource to template vars
         $this->templateEngine->addVar('queryResource', $this->endpoint . '?query=' . urlencode($endpointQuery));
         // calculate if hasNextPage according pagingPolicy
         $this->hasNextPage = $this->pagingPolicy == self::AGGRESSIVE ? $this->resultGraph->countTriples() == $this->context->getPageSize() : !$this->resultGraph->isEmpty();
     }
     return $this;
 }
Пример #11
0
function pastConferences()
{
    EasyRdf_Namespace::set('ical', 'http://www.w3.org/2002/12/cal/ical#');
    EasyRdf_Namespace::set('sd', 'http://symbolicdata.org/Data/Model#');
    $jahr = empty($_GET['year']) ? "2012" : $_GET['year'];
    $query = '
PREFIX sd: <http://symbolicdata.org/Data/Model#>
PREFIX ical: <http://www.w3.org/2002/12/cal/ical#>
construct { ?a ?b ?c . ?a sd:Series ?a2 . }
from <http://symbolicdata.org/Data/PastConferences/>
from <http://symbolicdata.org/Data/ConferenceSeries/>
Where { ?a a sd:Conference ; ?b ?c ; ical:dtstart ?d . 
optional {?a sd:toConferenceSeries ?a1 . ?a1 rdfs:label ?a2 . }
filter regex(?d, "' . $jahr . '")
} ';
    $sparql = new EasyRdf_Sparql_Client('http://symbolicdata.org:8890/sparql');
    $result = $sparql->query($query);
    // a CONSTRUCT query returns an EasyRdf_Graph
    //echo $result->dump("turtle");
    /* generate data structure for output table */
    $s = array();
    foreach ($result->allOfType("sd:Conference") as $v) {
        $a = $v->getUri();
        $label = $v->get('rdfs:label');
        $from = date_format(date_create($v->get('ical:dtstart')), "Y/m/d");
        $to = date_format(date_create($v->get('ical:dtend')), "Y/m/d");
        $loc = $v->get('ical:location');
        $series = $v->get('sd:Series');
        $description = $v->get('ical:description');
        $out = '
<p><dl> <dt><strong><a href="' . $a . '">' . $label . '</a></strong></dt>
<dd>' . $from . ' &ndash; ' . $to . ' in ' . $loc . '.</dd>';
        foreach ($v->all('ical:url') as $url) {
            $out .= '<dd> Conference URL: <a href="' . $url . '">' . $url . '</a></dd>';
        }
        if (!empty($series)) {
            $out .= '<dd> Conference Series: ' . $series . '</dd>';
        }
        $out .= '</dl></p>';
        $s["{$from}.{$a}"] = $out;
    }
    krsort($s);
    return join($s, "\n");
}
Пример #12
0
 public function testQueryEndpointWithParameters()
 {
     $this->sparql = new EasyRdf_Sparql_Client('http://localhost:8080/sparql?a=b');
     $this->client->addMock('GET', '/sparql?a=b&query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D', readFixture('sparql_select_all.xml'), array('headers' => array('Content-Type' => 'application/sparql-results+xml')));
     $result = $this->sparql->query("SELECT * WHERE {?s ?p ?o}");
     $this->assertCount(14, $result);
     $this->assertEquals(new EasyRdf_Resource('_:genid1'), $result[0]->s);
     $this->assertEquals(new EasyRdf_Resource('http://xmlns.com/foaf/0.1/name'), $result[0]->p);
     $this->assertEquals(new EasyRdf_Literal("Joe's Current Project"), $result[0]->o);
 }
Пример #13
0
function getSystems()
{
    $query = '
PREFIX sd: <http://symbolicdata.org/Data/Model#>
PREFIX dct: <http://purl.org/dc/terms/>
construct {
?a ?b ?c . ?d ?e ?f . 
}
from <http://symbolicdata.org/Data/CA-Systems/>
Where {
?a a sd:CAS ; ?b ?c; rdfs:seeAlso ?d .
?d ?e ?f . 
} 
';
    $sparql = new EasyRdf_Sparql_Client('http://symbolicdata.org:8890/sparql');
    $result = $sparql->query($query);
    // a CONSTRUCT query returns an EasyRdf_Graph
    //echo $result->dump("turtle");
    return $result;
}
Пример #14
0
 public function indexAction()
 {
     $product = new Product();
     for ($i = 0; $i < 100; $i++) {
         $product->setName('Foo Bar  : ' . rand(0, 100));
         $product->setPrice(rand(0, 1000));
         $dm = $this->get('doctrine_mongodb')->getManager();
         $dm->persist($product);
         $dm->flush();
     }
     $foaf = \EasyRdf_Graph::newAndLoad('http://njh.me/foaf.rdf');
     $me = $foaf->primaryTopic();
     \EasyRdf_Namespace::set('category', 'http://dbpedia.org/resource/Category:');
     \EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
     \EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
     \EasyRdf_Namespace::set('dbp', 'http://dbpedia.org/property/');
     $sparql = new \EasyRdf_Sparql_Client('http://dbpedia.org/sparql');
     $result = $sparql->query('SELECT * WHERE {' . '  ?country rdf:type dbo:Country .' . '  ?country rdfs:label ?label .' . '  ?country dc:subject category:Member_states_of_the_United_Nations .' . '  FILTER ( lang(?label) = "en" )' . '} ORDER BY ?label');
     $repository = $this->get('doctrine_mongodb')->getManager()->getRepository('MyAppBlogBundle:Product');
     return $this->render('MyAppBlogBundle:Default:index.html.twig', array('name' => $result, 'count' => $result->numRows(), 'products' => $repository->findAll()));
 }
Пример #15
0
 * This example creates a new SPARQL client, pointing at the
 * dbpedia.org endpoint. It then makes a SELECT query that
 * returns all of the countries in DBpedia along with an
 * english label.
 *
 * Note how the namespace prefix declarations are automatically
 * added to the query.
 *
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2013 Nicholas J Humfrey
 * @license    http://unlicense.org/
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
require_once "html_tag_helpers.php";
$sparql = new EasyRdf_Sparql_Client('http://127.0.0.1:3030/ds/query', 'http://127.0.0.1:3030/ds/update');
?>
<html>
<head>
  <title>EasyRdf Basic Sparql Example</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>EasyRdf Basic Sparql Example</h1>

<?php 
print "Count: " . $sparql->countTriples() . "<br />\n";
$result = $sparql->clear('all');
print "Result: " . $result->getMessage() . "<br />\n";
$graph = new EasyRdf_Graph();
$person = $graph->resource('http://example.com/joe', 'foaf:Person');
Пример #16
0
 * 
 * 
 *    
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2013 Nicholas J Humfrey
 * @license    http://unlicense.org/
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../easyrdf/lib/');
require_once "EasyRdf.php";
require_once "../easyrdf/examples/html_tag_helpers.php";
// Setup some additional prefixes
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('thk', 'http://dpch.oss.web.id/Bali/TriHitaKarana.owl#');
$sparql = new EasyRdf_Sparql_Client('http://localhost:3030/thk/query');
?>
<html>
<head>
  <title>List of Villages</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>List of space in Bali</h1>

<h2>Lists of villages in Bali</h2>
<ul>
<?php 
$result = $sparql->query('SELECT * WHERE {' . '  ?Desa rdf:type thk:Desa .' . '} ORDER BY ?Desa');
foreach ($result as $row) {
    $desa_name = explode("#", $row->Desa);
print text_field_tag('endpoint', "http://dbpedia.org/sparql", array('size' => 80)) . '<br />';
print "<code>";
foreach (EasyRdf_Namespace::namespaces() as $prefix => $uri) {
    print "PREFIX {$prefix}: &lt;" . htmlspecialchars($uri) . "&gt;<br />\n";
}
print "</code>";
print text_area_tag('query', "SELECT * WHERE {\n  ?s ?p ?o\n}\nLIMIT 10", array('rows' => 10, 'cols' => 80)) . '<br />';
print check_box_tag('text') . label_tag('text', 'Plain text results') . '<br />';
print reset_tag() . submit_tag();
print form_end_tag();
?>
</div>

<?php 
if (isset($_REQUEST['endpoint']) and isset($_REQUEST['query'])) {
    $sparql = new EasyRdf_Sparql_Client($_REQUEST['endpoint']);
    try {
        $results = $sparql->query($_REQUEST['query']);
        if (isset($_REQUEST['text'])) {
            print "<pre>" . htmlspecialchars($results->dump(false)) . "</pre>";
        } else {
            print $results->dump(true);
        }
    } catch (Exception $e) {
        print "<div class='error'>" . $e->getMessage() . "</div>\n";
    }
}
?>

</body>
</html>
Пример #18
0
 /** A basic HTML response check using curl to check identifier exists
  * @access public
  * @return array
  */
 public function checkType($identifier)
 {
     $key = md5($identifier . 'CheckRrcTypes');
     if (!$this->getCache()->test($key)) {
         $client = new Zend_Http_Client(null, array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'keepalive' => true, 'useragent' => "finds.org.uk/easyrdf"));
         $client->setHeaders(array('accept' => 'application/sparql-results+xml'));
         EasyRdf_Http::setDefaultHttpClient($client);
         EasyRdf_Namespace::set('nm', 'http://nomisma.org/id/');
         EasyRdf_Namespace::set('nmo', 'http://nomisma.org/ontology#');
         EasyRdf_Namespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
         EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
         $sparql = new EasyRdf_Sparql_Client('http://nomisma.org/query');
         $data = $sparql->query('SELECT * WHERE {' . '  ?type ?role nm:' . $identifier . ' ;' . '   a nmo:TypeSeriesItem ;' . '  skos:prefLabel ?label' . '  OPTIONAL {?type nmo:hasStartDate ?startDate}' . '  OPTIONAL {?type nmo:hasEndDate ?endDate}' . '  FILTER(langMatches(lang(?label), "en"))' . ' } ORDER BY ?label');
         $this->getCache()->save($data);
     } else {
         $data = $this->getCache()->load($key);
     }
     return $data;
 }
 * Note how the namespace prefix declarations are automatically
 * added to the query.
 *
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2012 Nicholas J Humfrey
 * @license    http://unlicense.org/
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
require_once "html_tag_helpers.php";
// Setup some additional prefixes for DBpedia
EasyRdf_Namespace::set('category', 'http://dbpedia.org/resource/Category:');
EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
EasyRdf_Namespace::set('dbp', 'http://dbpedia.org/property/');
$sparql = new EasyRdf_Sparql_Client('http://dbpedia.org/sparql');
?>
<html>
<head>
  <title>EasyRdf Basic Sparql Example</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>EasyRdf Basic Sparql Example</h1>

<h2>List of countries</h2>
<ul>
<?php 
$result = $sparql->query('SELECT * WHERE {' . '  ?country rdf:type dbo:Country .' . '  ?country rdfs:label ?label .' . '  ?country dc:subject category:Member_states_of_the_United_Nations .' . '  FILTER ( lang(?label) = "en" )' . '} ORDER BY ?label');
foreach ($result as $row) {
    echo "<li>" . link_to($row->label, $row->country) . "</li>\n";
Пример #20
0
 * 
 * 
 *    
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2013 Nicholas J Humfrey
 * @license    http://unlicense.org/
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../easyrdf/lib/');
require_once "EasyRdf.php";
require_once "../easyrdf/examples/html_tag_helpers.php";
// Setup some additional prefixes
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('thk', 'http://dpch.oss.web.id/Bali/TriHitaKarana.owl#');
$sparql = new EasyRdf_Sparql_Client('http://localhost:3030/thk/query');
?>
<html>
<head>
  <title>List of Villages</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>List of space in Bali</h1>

<h2>Lists of villages in Bali</h2>
<ul>
<?php 
$result = $sparql->query('SELECT * WHERE {' . '  ?Kabupaten rdf:type thk:Kabupaten .' . '} ORDER BY ?Kabupaten');
foreach ($result as $row) {
    $kabupaten_name = explode("#", $row->Kabupaten);
Пример #21
0
 * 
 * 
 *    
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2013 Nicholas J Humfrey
 * @license    http://unlicense.org/
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../easyrdf/lib/');
require_once "EasyRdf.php";
require_once "../easyrdf/examples/html_tag_helpers.php";
// Setup some additional prefixes
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('thk', 'http://dpch.oss.web.id/Bali/TriHitaKarana.owl#');
$sparql = new EasyRdf_Sparql_Client('http://localhost:3030/thk/query');
?>
<html>
<head>
  <title>List of Villages</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>List of space in Bali</h1>

<h2>Lists of villages in Bali</h2>
<ul>
<?php 
$result = $sparql->query('SELECT * WHERE {' . '  ?Desa rdf:type thk:Desa;
    thk:isPartOf+ thk:Gianyar .' . '} ORDER BY ?Desa');
foreach ($result as $row) {
// Setup some additional prefixes for the Drupal Site
EasyRdf_Namespace::set('schema', 'http://schema.org/');
EasyRdf_Namespace::set('content', 'http://purl.org/rss/1.0/modules/content/');
EasyRdf_Namespace::set('dc', 'http://purl.org/dc/terms/');
EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
EasyRdf_Namespace::set('og', 'http://ogp.me/ns#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('sioc', 'http://rdfs.org/sioc/ns#');
EasyRdf_Namespace::set('sioct', 'http://rdfs.org/sioc/types#');
EasyRdf_Namespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
EasyRdf_Namespace::set('xsd', 'http://www.w3.org/2001/XMLSchema#');
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('rss', 'http://purl.org/rss/1.0/');
EasyRdf_Namespace::set('site', 'http://localhost/iksce/ns#');
$sparql = new EasyRdf_Sparql_Client('http://localhost/iksce/sparql');
?>

<?php 
// Set debugging
function dbg($level, $message, $dbg)
{
    if ($dbg = 1) {
        if ($level = 1) {
            echo $message;
        } elseif ($level = 2) {
            print_r($message);
        } elseif ($level = 3) {
            var_dump($message);
        }
    }
Пример #23
0
 *
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2013 Nicholas J Humfrey
 * @license    http://unlicense.org/
 *
 *
 * This code will insert a location into thk ontology
 * The input base on a file ../../form_location.html
 */
//Get data from ../../form_location.html
$kabupaten = $_POST['Denpasar'];
$kecamatan = $_POST['KecDenpasarBarat'];
$desa = $_POST['DesaAdatPadangSambian'];
$banjar = $_POST['BanjarAdatPadangPadang'];
set_include_path(get_include_path() . PATH_SEPARATOR . '../easyrdf/lib/');
require_once "EasyRdf.php";
require_once "../easyrdf/examples/html_tag_helpers.php";
// Setup prefix
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('thk', 'http://dpch.oss.web.id/Bali/TriHitaKarana.owl#');
$client = new EasyRdf_Sparql_Client('http://dpch.oss.web.id:3030/thk/update');
$client->update('INSERT DATA {
thk:$kecamatan a thk:Kecamatan;
thk:isPartOf thk:$kabupaten.
thk:$desa a thk:Desa;
thk:isPartOf thk:$kecamatan.
thk:$banjar a thk:Banjar;
    thk:isPartOf thk:$desa.
}');
// Load the parsers and serialisers that we are going to use
# FIXME: better way to do this?
$autoloader->autoload('EasyRdf_Serialiser_Ntriples');
$autoloader->autoload('EasyRdf_Parser_Ntriples');
?>

<html>
<head>
  <title>Zend Framework Example</title>
</head>
<body>
<h1>Zend Framework Example</h1>

<?php 
# Load some sample data into a graph
$graph = new EasyRdf_Graph('http://example.com/joe');
$joe = $graph->resource('http://example.com/joe#me', 'foaf:Person');
$joe->add('foaf:name', 'Joe Bloggs');
$joe->addResource('foaf:homepage', 'http://example.com/joe/');
# Store it in a local graphstore
$store = new EasyRdf_GraphStore('http://localhost:8080/data/');
$store->replace($graph);
# Now make a query to the graphstore
$sparql = new EasyRdf_Sparql_Client('http://localhost:8080/sparql/');
$result = $sparql->query('SELECT * WHERE {<http://example.com/joe#me> ?p ?o}');
echo $result->dump();
?>

</body>
</html>
// Setup some additional prefixes for the Drupal Site
EasyRdf_Namespace::set('schema', 'http://schema.org/');
EasyRdf_Namespace::set('content', 'http://purl.org/rss/1.0/modules/content/');
EasyRdf_Namespace::set('dc', 'http://purl.org/dc/terms/');
EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
EasyRdf_Namespace::set('og', 'http://ogp.me/ns#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('sioc', 'http://rdfs.org/sioc/ns#');
EasyRdf_Namespace::set('sioct', 'http://rdfs.org/sioc/types#');
EasyRdf_Namespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
EasyRdf_Namespace::set('xsd', 'http://www.w3.org/2001/XMLSchema#');
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('rss', 'http://purl.org/rss/1.0/');
EasyRdf_Namespace::set('site', 'http://localhost/iksce/ns#');
$sparql = new EasyRdf_Sparql_Client('http://localhost/iksce/sparql');
?>
<html>
<head>
  <title>EasyRdf Basic Sparql Example</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>EasyRdf Basic Sparql Example</h1>

<ul>
<?php 
$result = $sparql->query('SELECT * { ?s schema:isRelatedTo ?o . }');
foreach ($result as $row) {
    //    echo "$row->o\n<br/><br/>";
    $html = implode('', file($row->o));
// Setup some additional prefixes for the Drupal Site
EasyRdf_Namespace::set('schema', 'http://schema.org/');
EasyRdf_Namespace::set('content', 'http://purl.org/rss/1.0/modules/content/');
EasyRdf_Namespace::set('dc', 'http://purl.org/dc/terms/');
EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
EasyRdf_Namespace::set('og', 'http://ogp.me/ns#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('sioc', 'http://rdfs.org/sioc/ns#');
EasyRdf_Namespace::set('sioct', 'http://rdfs.org/sioc/types#');
EasyRdf_Namespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
EasyRdf_Namespace::set('xsd', 'http://www.w3.org/2001/XMLSchema#');
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('rss', 'http://purl.org/rss/1.0/');
EasyRdf_Namespace::set('site', 'http://localhost/iksce/ns#');
$sparql = new EasyRdf_Sparql_Client('http://localhost/iksce/sparql');
?>
<html>
<head>
  <title>EasyRdf Basic Sparql Example</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>EasyRdf Basic Sparql Example</h1>

<ul>
<?php 
// Initially assume that we do not need to add the Tag to the rdf store
$newrdftag = "false";
// Perform SELECT query on RDF store to validate false assumption for variable rdftag
$result = $sparql->query('SELECT * { ?s schema:isRelatedTo ?o .
Пример #27
0
 function sparql_graph()
 {
     // cache data is refreshed if it's older than the given TTL
     $time = time() - $this->ttl;
     $date = date("Y", $time) . '-' . date("m", $time) . '-' . date("d", $time) . 'T' . date("H", $time) . ':' . date("i", $time) . ':' . date("s", $time);
     $db = sparql_connect($this->endpoint);
     $query = 'SELECT * FROM <' . $this->webid . '> WHERE { ' . '?person dc:date ?date . ' . 'FILTER (?date > "' . $date . '"^^xsd:dateTime)}';
     $result = $db->query($query);
     // fallback to EasyRdf if there's a problem with the SPARQL endpoint
     if (!$result) {
         $this->direct_graph();
     } else {
         // cache data into the triple store if it's the first time we see it
         $count = $result->num_rows($result);
         // force refresh of data if cache expired
         if ($count == 0) {
             $this->sparql_cache();
         }
         $query = "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> ";
         $query .= "PREFIX cert: <http://www.w3.org/ns/auth/cert#> ";
         $query .= "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <" . $this->webid . "> { ?s ?p ?o } }";
         $sparql = new EasyRdf_Sparql_Client($this->endpoint);
         $graph = $sparql->query($query);
         $this->graph = $graph;
     }
     return true;
 }
 * The example creates a new SPARQL client, pointing at the
 * Talis hosted BBC Backstage store. It then makes a SELECT
 * query that returns all of the episodes, along with their
 * episode number and title.
 *
 * Note how the PO prefix declaration is automatically added to the query.
 *
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2011 Nicholas J Humfrey
 * @license    http://unlicense.org/
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
require_once "html_tag_helpers.php";
EasyRdf_Namespace::set('po', 'http://purl.org/ontology/po/');
$sparql = new EasyRdf_Sparql_Client('http://api.talis.com/stores/bbc-backstage/services/sparql');
?>
<html>
<head><title>Basic Sparql</title></head>
<body>
<h1>Basic Sparql</h1>

<h2>Doctor Who - Series 1</h2>
<ul>
<?php 
$series1 = 'http://www.bbc.co.uk/programmes/b007vvcq#programme';
$result = $sparql->query("SELECT * WHERE {" . "  <{$series1}> po:episode ?episode ." . "  ?episode po:position ?pos ." . "  ?episode rdfs:label ?title ." . "} ORDER BY ?pos");
foreach ($result as $row) {
    echo "<li>{$row->pos}. " . link_to($row->title, $row->episode) . "</li>\n";
}
?>
Пример #29
0
<?php

require_once '../api/easyrdf-0.9.0/lib/EasyRdf.php';
if (isset($_GET['resource'])) {
    $resource = $_GET['resource'];
    $endpoint = new EasyRdf_Sparql_Client('http://id.dbpedia.org/sparql');
    $res = $endpoint->query("select distinct * where { <{$resource}> ?prop ?val . }");
    $graph = new EasyRdf_Graph();
    $final_results = [];
    foreach ($res as $r) {
        $item = new stdClass();
        $item->property = $r->prop->getUri();
        $item->value = $r->val instanceof EasyRdf_Resource ? $r->val->getUri() : $r->val->getValue();
        $final_results[] = $item;
    }
    header("Content-Type:application/json");
    echo json_encode($final_results);
}
Пример #30
0
 public function testGetDifferentUpdateUri()
 {
     $sparql = new EasyRdf_Sparql_Client('http://localhost/query', 'http://localhost/update');
     $this->assertSame('http://localhost/query', $sparql->getQueryUri());
     $this->assertSame('http://localhost/update', $sparql->getUpdateUri());
 }