/**
  * @Route("/create-person")
  */
 public function createPersonAction()
 {
     \EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Arc');
     \EasyRdf_Format::registerSerialiser('posh', 'EasyRdf_Serialiser_Arc');
     \EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Arc');
     \EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Arc');
     \EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
     $uri = 'http://www.example.com/emi#me';
     $name = 'Emi Berea';
     $emailStr = '*****@*****.**';
     $homepageStr = 'http://bereae.me/';
     $graph = new \EasyRdf_Graph();
     # 1st Technique
     $me = $graph->resource($uri, 'foaf:Person');
     $me->set('foaf:name', $name);
     if ($emailStr) {
         $email = $graph->resource("mailto:" . $emailStr);
         $me->add('foaf:mbox', $email);
     }
     if ($homepageStr) {
         $homepage = $graph->resource($homepageStr);
         $me->add('foaf:homepage', $homepage);
     }
     # Finally output the graph
     $data = $graph->serialise('rdfxml');
     if (!is_scalar($data)) {
         $data = var_export($data, true);
     }
     var_dump($data);
     die;
 }
예제 #2
0
 /** Get the data for reuse based off sparql endpoint
  * @access public
  * @return array $data
  * */
 public function getInfo($identifier)
 {
     $key = md5($identifier . 'ocre');
     $uri = self::CRRO . $identifier;
     if (!$this->getCache()->test($key)) {
         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#');
         $request = new EasyRdf_Http_Client();
         $request->setUri($uri);
         $response = $request->request()->getStatus();
         if ($response == 200) {
             $graph = new EasyRdf_Graph($uri);
             $graph->load();
             $data = $graph->resource($uri);
             $this->getCache()->save($data);
         } else {
             $data = NULL;
         }
     } else {
         $data = $this->getCache()->load($key);
     }
     return $data;
 }
예제 #3
0
 public function setUp()
 {
     if (PHP_MAJOR_VERSION < 5 or PHP_MAJOR_VERSION >= 5 and PHP_MINOR_VERSION < 3) {
         $this->markTestSkipped("JSON-LD support requires PHP 5.3+");
     }
     if (!class_exists('\\ML\\JsonLD\\JsonLD')) {
         $this->markTestSkipped('"ml/json-ld" dependency is not installed');
     }
     $this->graph = new EasyRdf_Graph('http://example.com/');
     $this->serialiser = new EasyRdf_Serialiser_JsonLd();
     $joe = $this->graph->resource('http://www.example.com/joe#me', 'foaf:Person');
     $joe->set('foaf:name', new EasyRdf_Literal('Joe Bloggs', 'en'));
     $joe->set('foaf:age', 59);
     $project = $this->graph->newBNode();
     $project->add('foaf:name', 'Project Name');
     $joe->add('foaf:project', $project);
 }
예제 #4
0
 public function testParseQuery()
 {
     $graph = new EasyRdf_Graph();
     $graph->parse(readFixture('query/describe.ttl'), 'turtle');
     $query = $graph->resource('test:describe');
     $this->assertClass('EasySpinRdf_Query_Describe', $query);
     $this->assertStringEquals("DESCRIBE ?value WHERE { ?this test:uncle ?value }", $query->getSparql());
 }
예제 #5
0
 public function testParseQuery()
 {
     $graph = new EasyRdf_Graph();
     $graph->parse(readFixture('query/ask.ttl'), 'turtle');
     $query = $graph->resource('test:ask');
     $this->assertClass('EasySpinRdf_Query_Ask', $query);
     $this->assertStringEquals("# must be 18 years old\nASK WHERE { ?this test:age 18 }", $query->getSparql());
 }
예제 #6
0
 public function testParseQuery()
 {
     $graph = new EasyRdf_Graph();
     $graph->parse(readFixture('query/construct.ttl'), 'turtle');
     $query = $graph->resource('test:construct');
     $this->assertClass('EasySpinRdf_Query_Construct', $query);
     $this->assertStringEquals("CONSTRUCT { ?this test:grandParent ?grandParent } WHERE { ?parent test:child ?this. ?grandParent test:child ?parent }", $query->getSparql());
 }
예제 #7
0
 public function testParseWithFormatObject()
 {
     $data = readFixture('foaf.jsonld');
     $format = EasyRdf_Format::getFormat('jsonld');
     $count = $this->parser->parse($this->graph, $data, $format, null);
     $this->assertSame(14, $count);
     $joe = $this->graph->resource('http://www.example.com/joe#me');
     $this->assertStringEquals('Joe Bloggs', $joe->get('foaf:name'));
 }
 public function testParseWebId()
 {
     $graph = new EasyRdf_Graph();
     $graph->parseFile(fixturePath('webid.ttl'), 'turtle');
     $me = $graph->resource('http://www.example.com/myfoaf#me');
     $modulus = $me->get('cert:key')->get('cert:modulus');
     $this->assertStringEquals('CB24ED85D64D794B69C701C186ACC059501E856000F661C93204D8380E07191C' . '5C8B368D2AC32A428ACB970398664368DC2A867320220F755E99CA2EECDAE62E' . '8D15FB58E1B76AE59CB7ACE8838394D59E7250B449176E51A494951A1C366C62' . '17D8768D682DDE78DD4D55E613F8839CF275D4C8403743E7862601F3C49A6366' . 'E12BB8F498262C3C77DE19BCE40B32F89AE62C3780F5B6275BE337E2B3153AE2' . 'BA72A9975AE71AB724649497066B660FCF774B7543D980952D2E8586200EDA41' . '58B014E75465D91ECF93EFC7AC170C11FC7246FC6DED79C37780000AC4E079F6' . '71FD4F207AD770809E0E2D7B0EF5493BEFE73544D8E1BE3DDDB52455C61391A1', $modulus);
     $this->assertInternalType('string', $modulus->getValue());
     $this->assertSame(NULL, $modulus->getLang());
     $this->assertSame('xsd:hexBinary', $modulus->getDatatype());
 }
예제 #9
0
 public function setUp()
 {
     if (PHP_MAJOR_VERSION < 5 or PHP_MAJOR_VERSION == 5 and PHP_MINOR_VERSION < 3) {
         $this->markTestSkipped("JSON-LD support requires PHP 5.3+");
     }
     if (!class_exists('\\ML\\JsonLD\\JsonLD')) {
         $this->markTestSkipped('"ml/json-ld" dependency is not installed');
     }
     $this->graph = new EasyRdf_Graph('http://example.com/');
     $this->serialiser = new EasyRdf_Serialiser_JsonLd();
     $joe = $this->graph->resource('http://www.example.com/joe#me', 'foaf:Person');
     $joe->set('foaf:name', new EasyRdf_Literal('Joe Bloggs', 'en'));
     $joe->set('foaf:age', 59);
     $joe->set('foaf:homepage', $this->graph->resource('http://foo/bar/me'));
     $project = $this->graph->newBNode();
     $project->add('foaf:name', 'Project Name');
     $joe->add('foaf:project', $project);
     EasyRdf_Namespace::set('dc', 'http://purl.org/dc/elements/1.1/');
     EasyRdf_Namespace::set('ex', 'http://example.org/vocab#');
     EasyRdf_Namespace::set('xsd', 'http://www.w3.org/2001/XMLSchema#');
     EasyRdf_Namespace::set('', 'http://foo/bar/');
     $chapter = $this->graph->resource('http://example.org/library/the-republic#introduction', 'ex:Chapter');
     $chapter->set('dc:description', new EasyRdf_Literal('An introductory chapter on The Republic.'));
     $chapter->set('dc:title', new EasyRdf_Literal('The Introduction'));
     $book = $this->graph->resource('http://example.org/library/the-republic', 'ex:Book');
     $book->set('dc:creator', new EasyRdf_Literal('Plato'));
     $book->set('dc:title', new EasyRdf_Literal('The Republic'));
     $book->addResource('ex:contains', $chapter);
     $library = $this->graph->resource('http://example.org/library', 'ex:Library');
     $library->addResource('ex:contains', $book);
 }
예제 #10
0
 /** Get data from the endpoint
  * @access protected
  * @return string
  */
 protected function getData()
 {
     $key = md5($this->_uri);
     if (!$this->_cache->test($key)) {
         $graph = new EasyRdf_Graph(self::URI . $this->_uri . self::SUFFIX);
         $graph->load();
         $data = $graph->resource(self::URI . $this->_uri);
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load($key);
     }
     EasyRdf_Namespace::set('dcterms', 'http://purl.org/dc/terms/');
     EasyRdf_Namespace::set('pleiades', 'http://pleiades.stoa.org/places/vocab#');
     return $data;
 }
예제 #11
0
 /** Get the graph to parse
  * @access protected
  * @returns object
  */
 protected function getData()
 {
     $key = md5($this->_uri);
     if (!$this->_cache->test($key)) {
         $graph = new EasyRdf_Graph($this->_uri);
         $graph->load();
         $data = $graph->resource($this->_uri);
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load($key);
     }
     EasyRdf_Namespace::set('dbpediaowl', 'http://dbpedia.org/ontology/');
     EasyRdf_Namespace::set('dbpprop', 'http://dbpedia.org/property/');
     EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
     return $data;
 }
예제 #12
0
 public function index()
 {
     Auth::requirePermissions('catalog.view');
     $uri = \URL::to('/catalog#dcat');
     $graph = new \EasyRdf_Graph();
     $catalogR = $graph->resource($uri);
     $catalogR->addLiteral('dc:title', \Config::get('catalog.title'));
     $catalogR->addLiteral('dc:description', \Config::get('catalog.description'));
     $catalogR->addType('dcat:Catalog');
     $datasetRepo = new DatasetRepository();
     foreach ($datasetRepo->getAll() as $datasetGraph) {
         foreach ($datasetGraph->allOfType('dcat:Dataset') as $datasetR) {
             $graph->addResource($catalogR, 'dcat:dataset', $datasetR);
         }
     }
     $serializer = new \EasyRdf_Serialiser_Turtle();
     $turtle = $serializer->serialise($graph, 'turtle');
     return \View::make('catalog.detail')->with('title', 'Catalog | Linda')->with('turtle', $turtle);
 }
예제 #13
0
 /**
  * Create a new dataset
  *
  * @param array $config The config of the new dataset
  *
  * @return void
  */
 public function add($config)
 {
     \EasyRdf_Namespace::set('odapps', 'http://semweb.mmlab.be/ns/odapps#');
     // Create a auto-generated subject URI
     $id = $this->getIncrementalId();
     $uri = \URL::to('/apps/' . $id);
     $context = $this->getContext();
     $graph = new \EasyRdf_Graph();
     $application = $graph->resource($uri . '#application');
     $application->addType('odapps:Application');
     foreach ($this->getFields() as $field) {
         if ($field['domain'] == 'odapps:Application') {
             if ($field['single_value'] && in_array($field['type'], ['string', 'text', 'list'])) {
                 if (filter_var(trim($config[$field['var_name']]), FILTER_VALIDATE_URL)) {
                     $graph->addResource($application, $field['sem_term'], trim($config[$field['var_name']]));
                 } else {
                     $graph->add($application, $field['sem_term'], trim($config[$field['var_name']]));
                 }
             } else {
                 if (!$field['single_value'] && in_array($field['type'], ['string', 'list'])) {
                     if (!empty($config[$field['var_name']])) {
                         foreach ($config[$field['var_name']] as $val) {
                             if (filter_var($val, FILTER_VALIDATE_URL)) {
                                 $graph->addResource($application, $field['sem_term'], $val);
                             } else {
                                 $graph->add($application, $field['sem_term'], $val);
                             }
                         }
                     }
                 }
             }
         }
     }
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $collection = $this->getMongoCollection();
     $collection->insert($compact_document);
 }
예제 #14
0
 /**
  * Create a new dataset
  *
  * @param array $config The config of the new dataset
  *
  * @return void
  */
 public function add($config)
 {
     // Create a auto-generated subject URI
     $id = $this->getIncrementalId();
     $uri = \URL::to('/users/' . $id);
     $context = $this->getContext();
     // Add the dataset resource
     $graph = new \EasyRdf_Graph();
     $user = $graph->resource($uri . '#agent');
     $user->addType('foaf:Agent');
     foreach ($this->getFields() as $field) {
         if ($field['domain'] == 'foaf:Agent') {
             if ($field['single_value'] && in_array($field['type'], ['string', 'text', 'list'])) {
                 if (filter_var(trim($config[$field['var_name']]), FILTER_VALIDATE_URL)) {
                     $graph->addResource($user, $field['sem_term'], trim($config[$field['var_name']]));
                 } else {
                     $graph->add($user, $field['sem_term'], trim($config[$field['var_name']]));
                 }
             } else {
                 if (!$field['single_value'] && in_array($field['type'], ['string', 'list'])) {
                     if (!empty($config[$field['var_name']])) {
                         foreach ($config[$field['var_name']] as $val) {
                             if (filter_var($val, FILTER_VALIDATE_URL)) {
                                 $graph->addResource(${$user}, $field['sem_term'], $val);
                             } else {
                                 $graph->add(${$user}, $field['sem_term'], $val);
                             }
                         }
                     }
                 }
             }
         }
     }
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $collection = $this->getMongoCollection();
     $collection->insert($compact_document);
 }
예제 #15
0
 /** Get the data for rendering
  * @access public
  * @return
  * */
 public function getData()
 {
     $key = md5($this->getUri());
     if (!$this->getCache()->test($key)) {
         $request = new EasyRdf_Http_Client();
         $request->setUri($this->getUri());
         $response = $request->request()->getStatus();
         if ($response == 200) {
             $graph = new EasyRdf_Graph($this->_uri);
             $graph->load();
             $data = $graph->resource($this->_uri);
         } else {
             $data = NULL;
         }
         $this->getCache()->save($data);
     } else {
         $data = $this->getCache()->load($key);
     }
     return $data;
 }
예제 #16
0
 * Rending a graph to an image will only work if you have the
 * GraphViz 'dot' command installed.
 *
 * @package    EasyRdf
 * @copyright  Copyright (c) 2012-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";
$formats = array('PNG' => 'png', 'GIF' => 'gif', 'SVG' => 'svg');
$format = EasyRdf_Format::getFormat(isset($_REQUEST['format']) ? $_REQUEST['format'] : 'png');
// Construct a graph of three people
$graph = new EasyRdf_Graph();
$graph->set('foaf:knows', 'rdfs:label', 'knows');
$bob = $graph->resource('http://www.example.com/bob', 'foaf:Person');
$alice = $graph->resource('http://www.example.com/alice', 'foaf:Person');
$carol = $graph->resource('http://www.example.com/carol', 'foaf:Person');
$bob->set('foaf:name', 'Bob');
$alice->set('foaf:name', 'Alice');
$carol->set('foaf:name', 'Carol');
$bob->add('foaf:knows', $alice);
$bob->add('foaf:knows', $carol);
$alice->add('foaf:knows', $bob);
$alice->add('foaf:knows', $carol);
// Create a GraphViz serialiser
$gv = new EasyRdf_Serialiser_GraphViz();
$gv->setUseLabels(isset($_REQUEST['ul']));
$gv->setOnlyLabelled(isset($_REQUEST['ol']));
// If this is a request for the image, just render it and exit
if (isset($_REQUEST['image'])) {
<?php 
echo label_tag('format') . select_tag('format', $format_options, 'rdfxml');
?>
<br />

<?php 
echo submit_tag();
echo form_end_tag();
?>


<?php 
if (isset($_REQUEST['uri'])) {
    $graph = new EasyRdf_Graph();
    # 1st Technique
    $me = $graph->resource($_REQUEST['uri'], 'foaf:Person');
    $me->set('foaf:name', $_REQUEST['title'] . ' ' . $_REQUEST['given_name'] . ' ' . $_REQUEST['family_name']);
    if ($_REQUEST['email']) {
        $email = $graph->resource("mailto:" . $_REQUEST['email']);
        $me->add('foaf:mbox', $email);
    }
    if ($_REQUEST['homepage']) {
        $homepage = $graph->resource($_REQUEST['homepage']);
        $me->add('foaf:homepage', $homepage);
    }
    # 2nd Technique
    $graph->addLiteral($_REQUEST['uri'], 'foaf:title', $_REQUEST['title']);
    $graph->addLiteral($_REQUEST['uri'], 'foaf:givenname', $_REQUEST['given_name']);
    $graph->addLiteral($_REQUEST['uri'], 'foaf:family_name', $_REQUEST['family_name']);
    $graph->addLiteral($_REQUEST['uri'], 'foaf:nick', $_REQUEST['nickname']);
    # Add friends
예제 #18
0
 public function testLoad()
 {
     EasyRdf_Http::setDefaultHttpClient($client = new EasyRdf_Http_MockClient());
     $client->addMock('GET', 'http://example.com/foaf.json', readFixture('foaf.json'));
     $graph = new EasyRdf_Graph('http://example.com/');
     $resource = $graph->resource('http://example.com/foaf.json');
     $resource->load();
     $this->assertStringEquals('Joe Bloggs', $graph->get('http://www.example.com/joe#me', 'foaf:name'));
 }
예제 #19
0
                 } else {
                     $alert .= error('Could not copy the picture to the user\'s dir. Please check permissions.');
                 }
                 break;
             default:
                 $alert .= error('The selected image format is not supported.');
                 break;
         }
     } else {
         $alert .= error('The image size is too large. The maximum allowed size is 100KB.');
     }
 }
 // Create the graph object in which we will store data
 $graph = new EasyRdf_Graph();
 // create primary topic
 $pt = $graph->resource($webid_base, 'foaf:PersonalProfileDocument');
 $graph->addResource($pt, 'foaf:maker', $webid);
 $graph->addResource($pt, 'foaf:primaryTopic', $webid);
 $pt->set('foaf:title', urldecode($_REQUEST['foaf:name']) . "'s profile.");
 // ----- foaf:Person ----- //
 // create the Person graph
 $me = $graph->resource($webid, 'foaf:Person');
 // name
 $me->set('foaf:name', $_REQUEST['foaf:name']);
 // first name
 if (isset($_REQUEST['foaf:givenName']) && strlen($_REQUEST['foaf:givenName']) > 0) {
     $me->set('foaf:givenName', trim($_REQUEST['foaf:givenName']));
 }
 // last name
 if (isset($_REQUEST['foaf:familyName']) && strlen($_REQUEST['foaf:familyName']) > 0) {
     $me->set('foaf:familyName', trim($_REQUEST['foaf:familyName']));
예제 #20
0
echo form_tag();
?>
  <?php 
echo text_field_tag('postcode', 'W1A 1AA', array('size' => 10));
?>
  <?php 
echo submit_tag();
echo form_end_tag();
?>

<?php 
if (isset($_REQUEST['postcode'])) {
    $postcode = str_replace(' ', '', strtoupper($_REQUEST['postcode']));
    $docuri = "http://www.uk-postcodes.com/postcode/{$postcode}.rdf";
    $graph = new EasyRdf_Graph($docuri);
    $res = $graph->resource("postcode:{$postcode}");
    $ll = $res->get('geo:lat') . ',' . $res->get('geo:long');
    print "<iframe id='map' width='500' height='250' frameborder='0' scrolling='no' src='http://maps.google.com/maps?f=q&amp;sll={$ll}&amp;output=embed'></iframe>";
    print "<table id='facts'>\n";
    print "<tr><th>Easting:</th><td>" . $res->get('sr:easting') . "</td></tr>\n";
    print "<tr><th>Northing:</th><td>" . $res->get('sr:northing') . "</td></tr>\n";
    print "<tr><th>Longitude:</th><td>" . $res->get('geo:long') . "</td></tr>\n";
    print "<tr><th>Latitude:</th><td>" . $res->get('geo:lat') . "</td></tr>\n";
    print "<tr><th>Local Authority:</th><td>" . $res->get('ag:localAuthority')->label() . "</td></tr>\n";
    print "<tr><th>Electoral Ward:</th><td>" . $res->get('eg:ward')->label() . "</td></tr>\n";
    print "</table>\n";
    print "<div style='clear: both'></div>\n";
    print $graph->dump();
}
?>
</body>
 * and then used to display my name.
 *
 * @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";
EasyRdf_Namespace::set('mdc', 'http://www.purl.org/meducator/ns/');
?>
<html>
<head>
  <title>Basic FOAF example</title>
</head>
<body>

<?php 
$foaf = new EasyRdf_Graph("http://localhost/mod/content_item/metadata42922.rdf");
$foaf->load();
$me = $foaf->resource("http://metamorphosis.med.duth.gr/uid#42922");
?>

<p>
  My name is: <?php 
echo $me->get('mdc:title');
?>
</p>

</body>
</html>
예제 #22
0
/**
 * Basic serialisation example
 *
 * This example create a simple FOAF graph in memory and then
 * serialises it to the page in the format of choice.
 *
 * @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";
$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';
예제 #23
0
 /**
  * Output data in RDF and Turtle format
  *
  * @param array   $data       The items to output
  * @param string  $format     The output format
  * @param string  $predicate  The predicate for the list
  * @param string  $namespaces An associative array with the namespace, e.g. [ 'foaf' => 'http://xmlns.com/foaf/0.1/' ].
  *                            Note that EasyRDF already adds the standard prefixes, such as dc, foaf, etc.
  * @param integer $status     HTTP status code
  *
  * @uses \EasyRdf_Graph
  *
  * @throws \SameAsLite\Exception\ContentTypeException An exception may be thrown if the requested MIME type
  * is not supported
  */
 protected function outputRDF(array $data = array(), $format = 'list', $predicate = 'owl:sameAs', array $namespaces = array(), $status = null)
 {
     // how to: escape
     // array_walk($list, '\SameAsLite\Helper::escapeInputArray');
     if (!is_null($status)) {
         $this->app->response->setStatus($status);
     }
     //end if
     // get the query parameters
     $symbol = $this->app->request()->params('string');
     if (!$symbol) {
         $symbol = $this->app->request()->params('symbol');
     }
     //end if
     $symbol = $symbol ? urldecode($symbol) : false;
     $store = $this->store ? $this->store : false;
     $storeurl = $this->app->request()->getURL() . $this->app->request()->getRootUri() . '/datasets/' . urlencode($store);
     // EASY RDF
     $graph = new \EasyRdf_Graph();
     //-----------
     // namespaces
     // ----------
     if (!empty($namespaces)) {
         foreach ($namespaces as $prefix => $uri) {
             \EasyRdf_Namespace::set($prefix, $uri);
         }
     }
     //-------------
     // result block
     // ------------
     if ($symbol && strpos($symbol, 'http') === 0) {
         $graph_uri = $meta_uri = $graph->resource($symbol);
     } else {
         $graph_uri = $graph->newBNode();
     }
     $result_block = $graph->resource($graph_uri);
     //-------------
     // meta block
     // ------------
     $meta_uri = $this->app->request()->getURL() . $_SERVER['REQUEST_URI'];
     $meta_block = $graph->resource($meta_uri);
     // if this part is added, EasyRDF will merge the result block with the meta block
     // $meta_block->add('foaf:primaryTopic', $graph->resource( '_:' . $result_block->getBNodeId() ));
     $meta_block->set('dc:creator', 'sameAsLite');
     // TODO: maybe also add info about store (storename, URI)?
     if ($store) {
         $meta_block->set('dc:source', $graph->resource($storeurl));
     }
     // $meta_block->set('dc:title', 'Co-references from sameAs.org for ' . $symbol);
     if (isset($this->appOptions['license']['url'])) {
         $meta_block->add('dct:license', $graph->resource($this->appOptions['license']['url']));
     }
     // list
     if ($format === 'list') {
         // simple list
         foreach ($data as $str) {
             if (strpos($str, 'http') === 0) {
                 // resource
                 $result_block->add($predicate, $graph->resource(urldecode($str)));
             } else {
                 // literal values - not technically correct, because sameAs expects a resource
                 // but validates in W3C Validator
                 $result_block->add($predicate, $str);
             }
         }
     } elseif ($format === 'table') {
         // table output
         // data is in the form of:
         // [ [header1, header2, ...], [row1_1, row1_2, ...], [row2_1, row2_2, ...] ]
         $preds = array_shift($data);
         foreach ($data as $arr) {
             // if (isset($val['url'])) {
             //     $url = $val['url'];
             //     unset($val['url']);
             // } else {
             //     $url = $graph_uri;
             // }
             $resources = array();
             for ($i = 0, $s = count($arr); $i < $s; $i++) {
                 $resources[$i] = $graph->resource($storeurl);
                 // TODO
                 for ($k = 0, $t = count($preds); $k < $t; $k++) {
                     if (strpos($arr[$i], 'http') === 0) {
                         // resource
                         $graph->addResource($resources[$i], $preds[$k], $graph->resource(urldecode($arr[$i])));
                     } else {
                         // literal
                         $graph->addLiteral($resources[$i], $preds[$k], urldecode($arr[$i]));
                     }
                 }
             }
         }
     } else {
         // keyed = 'arbitrary' output format (e.g. for analysis)
         // Accepts data in the form of:
         // [ [ $key1 => $value1 ], [ $key2 => $value2 ], [...] ]
         // Will take key as predicate and
         // value as resource (if url) or literal
         $resource = $graph->resource($storeurl);
         foreach ($data as $key => $value) {
             if (strpos($value, 'http') === 0) {
                 // resource
                 $graph->addResource($resource, $key, $graph->resource(urldecode($value)));
             } else {
                 // literal
                 $graph->addLiteral($resource, $key, $value);
             }
         }
     }
     // ------
     // output
     // ------
     if ($this->mimeBest === 'application/rdf+xml') {
         $outFormat = 'rdf';
     } else {
         $outFormat = 'turtle';
     }
     $data = $graph->serialise($outFormat);
     if (!is_scalar($data)) {
         $data = var_export($data, true);
     }
     $this->app->response->setBody($data);
     $this->app->stop();
 }
 public function testInstantiate()
 {
     EasyRdf_TypeMapper::set('foaf:Person', 'MyType_Class');
     $data = readFixture('foaf.json');
     $graph = new EasyRdf_Graph('http://www.example.com/joe/foaf.rdf', $data, 'json');
     $joe = $graph->resource('http://www.example.com/joe#me');
     $this->assertClass('MyType_Class', $joe);
     $this->assertTrue($joe->myMethod());
 }
예제 #25
0
 /**
  * Add void and hydra meta-data to an existing graph
  *
  * @param EasyRdf_Graph $graph    The graph to which meta data has to be added
  * @param integer       $count    The total amount of triples that match the URI
  *
  * @return EasyRdf_Graph $graph
  */
 public function addMetaTriples($graph, $limit, $offset, $count)
 {
     // Add the void and hydra namespace to the EasyRdf framework
     \EasyRdf_Namespace::set('hydra', 'http://www.w3.org/ns/hydra/core#');
     \EasyRdf_Namespace::set('void', 'http://rdfs.org/ns/void#');
     \EasyRdf_Namespace::set('dcterms', 'http://purl.org/dc/terms/');
     // Add the meta data semantics to the graph
     $root = \Request::root();
     $root .= '/';
     $base_uri = $root . 'all';
     $identifier = str_replace($root, '', $base_uri);
     $graph->addResource($base_uri . '#dataset', 'a', 'void:Dataset');
     $graph->addResource($base_uri . '#dataset', 'a', 'hydra:Collection');
     $resource = $graph->resource($base_uri);
     $subject_temp_mapping = $graph->newBNode();
     $subject_temp_mapping->addResource('a', 'hydra:IriTemplateMapping');
     $subject_temp_mapping->addLiteral('hydra:variable', 'subject');
     $subject_temp_mapping->addResource('hydra:property', 'rdf:subject');
     $predicate_temp_mapping = $graph->newBNode();
     $predicate_temp_mapping->addResource('a', 'hydra:IriTemplateMapping');
     $predicate_temp_mapping->addLiteral('hydra:variable', 'predicate');
     $predicate_temp_mapping->addResource('hydra:property', 'rdf:predicate');
     $object_temp_mapping = $graph->newBNode();
     $object_temp_mapping->addResource('a', 'hydra:IriTemplateMapping');
     $object_temp_mapping->addLiteral('hydra:variable', 'object');
     $object_temp_mapping->addResource('hydra:property', 'rdf:object');
     $iri_template = $graph->newBNode();
     $iri_template->addResource('a', 'hydra:IriTemplate');
     $iri_template->addLiteral('hydra:template', $root . 'all' . '{?subject,predicate,object}');
     $iri_template->addResource('hydra:mapping', $subject_temp_mapping);
     $iri_template->addResource('hydra:mapping', $predicate_temp_mapping);
     $iri_template->addResource('hydra:mapping', $object_temp_mapping);
     // Add the template to the requested URI resource in the graph
     $graph->addResource($base_uri . '#dataset', 'hydra:search', $iri_template);
     $is_deferenced = false;
     if (strtolower(\Request::segment(1)) != 'all') {
         $full_url = \Request::root() . '/' . \Request::path();
         $is_deferenced = true;
     } else {
         $full_url = $base_uri . '?';
     }
     $template_url = $full_url;
     $templates = array('subject', 'predicate', 'object');
     $has_param = false;
     $query_string = $_SERVER['QUERY_STRING'];
     $query_parts = explode('&', $query_string);
     foreach ($query_parts as $part) {
         if (!empty($part)) {
             $couple = explode('=', $part);
             if (strtolower($couple[0]) == 'subject') {
                 $template_url .= $couple[0] . '=' . $couple[1] . '&';
                 $has_param = true;
             }
             if (strtolower($couple[0]) == 'predicate') {
                 $template_url .= $couple[0] . '=' . $couple[1] . '&';
                 $has_param = true;
             }
             if (strtolower($couple[0]) == 'object') {
                 $template_url .= $couple[0] . '=' . $couple[1] . '&';
                 $has_param = true;
             }
             $full_url .= $couple[0] . '=' . $couple[1] . '&';
         }
     }
     $full_url = rtrim($full_url, '?');
     $full_url = rtrim($full_url, '&');
     $template_url = rtrim($template_url, '?');
     $template_url = rtrim($template_url, '&');
     $full_url = str_replace('#', '%23', $full_url);
     $template_url = str_replace('#', '%23', $template_url);
     if ($is_deferenced) {
         $full_url .= '#dataset';
     }
     // Add paging information
     $graph->addLiteral($full_url, 'hydra:totalItems', \EasyRdf_Literal::create($count, null, 'xsd:integer'));
     $graph->addLiteral($full_url, 'void:triples', \EasyRdf_Literal::create($count, null, 'xsd:integer'));
     $graph->addLiteral($full_url, 'hydra:itemsPerPage', \EasyRdf_Literal::create($limit, null, 'xsd:integer'));
     $graph->addResource($full_url, 'void:subset', \Request::root() . '/all#dataset');
     $paging_info = $this->getPagingInfo($limit, $offset, $count);
     foreach ($paging_info as $key => $info) {
         switch ($key) {
             case 'next':
                 if ($has_param) {
                     $glue = '&';
                 } else {
                     $glue = '?';
                 }
                 $graph->addResource($full_url, 'hydra:nextPage', $template_url . $glue . 'limit=' . $info['limit'] . '&offset=' . $info['offset']);
                 break;
             case 'previous':
                 if ($has_param) {
                     $glue = '&';
                 } else {
                     $glue = '?';
                 }
                 $graph->addResource($full_url, 'hydra:previousPage', $template_url . $glue . 'limit=' . $info['limit'] . '&offset=' . $info['offset']);
                 break;
             case 'last':
                 if ($has_param) {
                     $glue = '&';
                 } else {
                     $glue = '?';
                 }
                 $graph->addResource($full_url, 'hydra:lastPage', $template_url . $glue . 'limit=' . $info['limit'] . '&offset=' . $info['offset']);
                 break;
             case 'first':
                 if ($has_param) {
                     $glue = '&';
                 } else {
                     $glue = '?';
                 }
                 $graph->addResource($full_url, 'hydra:firstPage', $template_url . $glue . 'limit=' . $info['limit'] . '&offset=' . $info['offset']);
                 break;
         }
     }
     // Tell the agent that it's a subset
     $graph->addResource($root . 'all#dataset', 'void:subset', $full_url);
     return $graph;
 }
/**
 * Erzeugt einen Graph aus dem JSON Dokument der spezifischen Rezeptsuche.
 * 
 * @param Array $jsonObject        	
 * @return EasyRdf_Graph
 */
function buildGraphFromJsonRecipeResult($jsonObject)
{
    $baseURL = 'http://chefkoch.de/rezept/';
    //$wrapperURL = "http://chefkoch:8888/index.php/lookup/";
    $graph = new EasyRdf_Graph();
    $rezeptNamespace = new EasyRdf_Namespace();
    $rezeptNamespace->set('arecipe', "http://purl.org/amicroformat/arecipe/");
    $rezeptNamespace->set('rezept', "http://manke-hosting.de/ns-syntax#");
    $rezeptNamespace->set('wrapper', HOST . "index.php/lookup/");
    $rezeptNamespace->set('owl', "http://www.w3.org/2002/07/owl#");
    $rezeptNamespace->set('reweSuche', HOST . "index.php/reweSuche/");
    //$rezeptNamespace->set('reweSuche', "http://manke-hosting.de/wrapper/index.php/reweSuche/");
    //$rezeptNamespace->set('reweSuche', "http://localhost/wrapper/index.php/reweSuche/");
    $url = $baseURL . $jsonObject['rezept_show_id'];
    $me = $graph->resource($url, 'arecipe:Recipe');
    foreach ($jsonObject as $key => $value) {
        $type = gettype($value);
        $namespace = "rezept";
        if ($type == "string") {
            $me->set($namespace . ':' . $key, $value);
        } elseif ($type == "array" && !empty($value)) {
            switch ($key) {
                case 'rezept_videos':
                    // TODO
                    break;
                case 'rezept_bilder':
                    $bn = $graph->newBNode();
                    $me->set($namespace . ':' . $key, $bn);
                    buildTree($graph, $bn, $value, 'rezept');
                    break;
                case 'rezept_zutaten':
                    foreach ($value as $rezept_zutaten => $zutat) {
                        $bn = $graph->newBNode();
                        $me->add($namespace . ":" . $key, $bn);
                        foreach ($zutat as $attribut => $attributWert) {
                            if ($attribut == "name" && $zutat["id"] != "") {
                                $attributWert = $str = str_replace(array('ä', 'ö', 'ü', 'ß', 'Ä', 'Ö', 'Ü'), array('ae', 'oe', 'ue', 'ss', 'Ae', 'Oe', 'Ue'), $attributWert);
                                $attributWert = preg_replace('/[^a-zA-Z0-9]+/', '', $attributWert);
                                $bn->addResource('rezept:reweSuche', 'reweSuche:' . $attributWert);
                                $bn->addLiteral($namespace . ":" . $attribut, $attributWert);
                            } elseif ($attribut == "menge") {
                                $attributWert = str_replace(".", ",", $attributWert);
                                $bn->addLiteral($namespace . ":" . $attribut, $attributWert);
                            } else {
                                $bn->addLiteral($namespace . ":" . $attribut, $attributWert);
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
    return $graph;
}
예제 #27
0
 function del_friend($uri, $format = 'rdfxml')
 {
     $uri = urldecode($uri);
     $path = $this->get_local_path($this->webid);
     // Create the new graph object in which we store data
     $graph = new EasyRdf_Graph($this->webid);
     $graph->load();
     $person = $graph->resource($this->webid);
     $graph->deleteResource($person, 'foaf:knows', $uri);
     // write profile to file
     $data = $graph->serialise($format);
     if (!is_scalar($data)) {
         $data = var_export($data, true);
     } else {
         $data = print_r($data, true);
     }
     $pf = fopen($path . '/foaf.rdf', 'w') or die('Cannot open profile RDF file!');
     fwrite($pf, $data);
     fclose($pf);
     $pf = fopen($path . '/foaf.txt', 'w') or die('Cannot open profile TXT file!');
     fwrite($pf, $data);
     fclose($pf);
     // get the user's name
     $friend = new MyProfile($uri, $this->base_uri, SPARQL_ENDPOINT);
     $friend->load();
     // everything is fine
     return success("You have just removed " . $friend->get_name() . " from your list of friends.");
 }
예제 #28
0
<body>
<h1>EasyRdf Spec Maker</h1>

<?php 
echo form_tag();
echo text_field_tag('short', 'foaf', array('size' => 8));
echo text_field_tag('uri', 'http://xmlns.com/foaf/0.1/', array('size' => 50));
echo submit_tag();
echo form_end_tag();
?>

<?php 
if (isset($_REQUEST['uri'])) {
    EasyRdf_Namespace::set($_REQUEST['short'], $_REQUEST['uri']);
    $graph = new EasyRdf_Graph($_REQUEST['uri']);
    $ontology = $graph->resource($_REQUEST['uri']);
} else {
    echo "<h2>Some examples:</h2>\n";
    echo "<ul>\n";
    echo "<li><a href='easyspec.php?short=foaf&uri=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F'>Friend of a Friend</a></li>\n";
    echo "<li><a href='easyspec.php?short=mo&uri=http%3A%2F%2Fpurl.org%2Fontology%2Fmo%2F'>Music Ontology</a></li>\n";
    echo "<li><a href='easyspec.php?short=po&uri=http%3A%2F%2Fpurl.org%2Fontology%2Fpo%2F'>Programmes Ontology</a></li>\n";
    echo "<li><a href='easyspec.php?short=rev&uri=http%3A%2F%2Fpurl.org%2Fstuff%2Frev%23'>Review Vocabulary</a></li>\n";
    echo "</ul>\n";
}
?>

<?
    if (isset($ontology)) {
        echo "<h2>".$ontology->label()."</h2>\n";
예제 #29
0
<?php

set_include_path(get_include_path() . PATH_SEPARATOR . './lib/');
require_once "EasyRdf.php";
// Load some properties from the composer file
$composer = json_decode(file_get_contents('composer.json'));
// Start building up a RDF graph
$doap = new EasyRdf_Graph($composer->homepage . 'doap.rdf');
$easyrdf = $doap->resource('#easyrdf', 'doap:Project', 'foaf:Project');
$easyrdf->addLiteral('doap:name', 'EasyRDF');
$easyrdf->addLiteral('doap:shortname', 'easyrdf');
$easyrdf->addLiteral('doap:revision', $composer->version);
$easyrdf->addLiteral('doap:shortdesc', $composer->description, 'en');
$easyrdf->addResource('doap:homepage', $composer->homepage);
$easyrdf->addLiteral('doap:programming-language', 'PHP');
$easyrdf->addLiteral('doap:description', 'EasyRdf is a PHP library designed to make it easy to consume and produce RDF. ' . 'It was designed for use in mixed teams of experienced and inexperienced RDF developers. ' . 'It is written in Object Oriented PHP and has been tested extensively using PHPUnit.', 'en');
$easyrdf->addResource('doap:license', 'http://usefulinc.com/doap/licenses/bsd');
$easyrdf->addResource('doap:download-page', 'http://github.com/njh/easyrdf/downloads');
$easyrdf->addResource('doap:download-page', 'http://github.com/njh/easyrdf/downloads');
$easyrdf->addResource('doap:bug-database', 'http://github.com/njh/easyrdf/issues');
$easyrdf->addResource('doap:mailing-list', 'http://groups.google.com/group/easyrdf');
$easyrdf->addResource('doap:category', 'http://dbpedia.org/resource/Resource_Description_Framework');
$easyrdf->addResource('doap:category', 'http://dbpedia.org/resource/PHP');
$easyrdf->addResource('doap:category', 'http://dbpedialite.org/things/24131#id');
$easyrdf->addResource('doap:category', 'http://dbpedialite.org/things/53847#id');
$repository = $doap->newBNode('doap:GitRepository');
$repository->addResource('doap:browse', 'http://github.com/njh/easyrdf');
$repository->addResource('doap:location', 'git://github.com/njh/easyrdf.git');
$easyrdf->addResource('doap:repository', $repository);
$njh = $doap->resource('http://njh.me/', 'foaf:Person');
$njh->addLiteral('foaf:name', 'Nicholas J Humfrey');
 public function testResourceWithMultipleTypes()
 {
     $graph = new EasyRdf_Graph();
     $resource = $graph->resource('http://www.foo.com/bar', array('rdf:Type1', 'rdf:Type2'));
     $types = $resource->types();
     $this->assertEquals(2, count($types));
     $this->assertStringEquals('rdf:Type1', $types[0]);
     $this->assertStringEquals('rdf:Type2', $types[1]);
 }