示例#1
0
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
$ns = new EasyRdf_Namespace();
$ns->set("dct", "http://www.dc.com");
$graph = new EasyRdf_Graph();
$me = $graph->resource('http://www.example.com/joe#me', 'foaf:Person');
$me->set('foaf:name', 'Joseph Bloggs');
$me->set('foaf:title', 'Mr');
$me->set('dct:title', 'ma oeeeeeee');
$me->set('foaf:nick', 'Joe');
$me->add('foaf:homepage', $graph->resource('http://example.com/joe/'));
// I made these up; they are not officially part of FOAF
$me->set('foaf:dateOfBirth', new EasyRdf_Literal_Date('1980-09-08'));
$me->set('foaf:height', 1.82);
$project = $graph->newBnode('foaf:Project');
$project->set('foaf:name', "Joe's current project");
$me->set('foaf:currentProject', $project);
if (isset($_REQUEST['format'])) {
    $format = preg_replace("/[^\\w\\-]+/", '', strtolower($_REQUEST['format']));
} else {
    $format = 'ntriples';
}
?>
<html>
<head><title>EasyRdf Serialiser Example</title></head>
<body>
<h1>EasyRdf Serialiser Example</h1>

<ul>
<?php 
 public function testDumpResource()
 {
     $graph = new EasyRdf_Graph();
     $graph->addResource('http://example.com/joe#me', 'rdf:type', 'foaf:Person');
     $graph->addResource('http://example.com/joe#me', 'foaf:homepage', 'http://example.com/');
     $graph->add('http://example.com/joe#me', 'foaf:knows', $graph->newBnode());
     $text = $graph->dumpResource('http://example.com/joe#me', false);
     $this->assertContains('http://example.com/joe#me', $text);
     $this->assertContains('-> rdf:type -> foaf:Person', $text);
     $this->assertContains('-> foaf:homepage -> http://example.com/', $text);
     $this->assertContains('-> foaf:knows -> _:genid1', $text);
     $html = $graph->dumpResource('http://example.com/joe#me', true);
     $this->assertContains('http://example.com/joe#me', $html);
     $this->assertContains('>rdf:type</span>', $html);
     $this->assertContains('>foaf:Person</a>', $html);
     $this->assertContains('>foaf:homepage</span>', $html);
     $this->assertContains('>http://example.com/</a>', $html);
     $this->assertContains('>foaf:knows</span>', $html);
     $this->assertContains('>_:genid1</a>', $html);
 }