Beispiel #1
0
 public static function toFile($filePath, $triples)
 {
     $graph = new \EasyRdf_Graph();
     foreach ($triples as $triple) {
         if (!empty($triple->lg)) {
             $graph->addLiteral($triple->subject, $triple->predicate, $triple->object, $triple->lg);
         } elseif (\common_Utils::isUri($triple->object)) {
             $graph->add($triple->subject, $triple->predicate, $triple->object);
         } else {
             $graph->addLiteral($triple->subject, $triple->predicate, $triple->object);
         }
     }
     $format = \EasyRdf_Format::getFormat('rdfxml');
     return file_put_contents($filePath, $graph->serialise($format));
 }
 /**
  * @ignore
  */
 private static function statement2rdf(PDOStatement $statement)
 {
     $graph = new EasyRdf_Graph();
     while ($r = $statement->fetch()) {
         if (isset($r['l_language']) && !empty($r['l_language'])) {
             $graph->addLiteral($r['subject'], $r['predicate'], $r['object'], $r['l_language']);
         } elseif (common_Utils::isUri($r['object'])) {
             $graph->add($r['subject'], $r['predicate'], $r['object']);
         } else {
             $graph->addLiteral($r['subject'], $r['predicate'], $r['object']);
         }
     }
     $format = EasyRdf_Format::getFormat('rdfxml');
     return $graph->serialise($format);
 }
Beispiel #3
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();
 }
Beispiel #4
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;
 }
<?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
    for ($i = 1; $i <= 4; $i++) {
        if ($_REQUEST["person_{$i}"]) {
            $person = $graph->resource($_REQUEST["person_{$i}"]);
            $graph->add($me, 'foaf:knows', $person);
        }
    }
    # Finally output the graph
    $data = $graph->serialise($_REQUEST['format']);
    if (!is_scalar($data)) {
        $data = var_export($data, true);
    }
Beispiel #6
0
 /**
  * Return a DCAT document based on the definitions that are passed
  *
  * @param array Array with definition configurations
  *
  * @return \EasyRdf_Graph
  */
 public function getDcatDocument(array $definitions, $oldest_definition)
 {
     // Create a new EasyRDF graph
     $graph = new \EasyRdf_Graph();
     \EasyRdf_Namespace::set('adms', 'http://www.w3.org/ns/adms#');
     $all_settings = $this->settings->getAll();
     $uri = \Request::root();
     // Add the catalog and a title
     $graph->addResource($uri . '/api/dcat', 'a', 'dcat:Catalog');
     $graph->addLiteral($uri . '/api/dcat', 'dct:title', $all_settings['catalog_title']);
     // Fetch the catalog description, issued date and language
     $graph->addLiteral($uri . '/api/dcat', 'dct:description', $all_settings['catalog_description']);
     $graph->addLiteral($uri . '/api/dcat', 'dct:issued', $this->getIssuedDate());
     $lang = $this->languages->getByCode($all_settings['catalog_language']);
     if (!empty($lang)) {
         $graph->addResource($uri . '/api/dcat', 'dct:language', 'http://lexvo.org/id/iso639-3/' . $lang['lang_id']);
         $graph->addResource('http://lexvo.org/id/iso639-3/' . $lang['lang_id'], 'a', 'dct:LinguisticSystem');
     }
     // Fetch the homepage and rights
     $graph->addResource($uri . '/api/dcat', 'foaf:homepage', $uri);
     $graph->addResource($uri . '/api/dcat', 'dct:license', 'http://www.opendefinition.org/licenses/cc-zero');
     $graph->addResource('http://www.opendefinition.org/licenses/cc-zero', 'a', 'dct:LicenseDocument');
     // Add the publisher resource to the catalog
     $graph->addResource($uri . '/api/dcat', 'dct:publisher', $all_settings['catalog_publisher_uri']);
     $graph->addResource($all_settings['catalog_publisher_uri'], 'a', 'foaf:Agent');
     $graph->addLiteral($all_settings['catalog_publisher_uri'], 'foaf:name', $all_settings['catalog_publisher_name']);
     if (count($definitions) > 0) {
         // Add the last modified timestamp in ISO8601
         $graph->addLiteral($uri . '/api/dcat', 'dct:modified', date(\DateTime::ISO8601, strtotime($oldest_definition['updated_at'])));
         foreach ($definitions as $definition) {
             // Create the dataset uri
             $dataset_uri = $uri . "/" . $definition['collection_uri'] . "/" . $definition['resource_name'];
             $dataset_uri = str_replace(' ', '%20', $dataset_uri);
             $source_type = $definition['type'];
             // Add the dataset link to the catalog
             $graph->addResource($uri . '/api/dcat', 'dcat:dataset', $dataset_uri);
             // Add the dataset resource and its description
             $graph->addResource($dataset_uri, 'a', 'dcat:Dataset');
             $title = null;
             if (!empty($definition['title'])) {
                 $title = $definition['title'];
             } else {
                 $title = $definition['collection_uri'] . '/' . $definition['resource_name'];
             }
             $graph->addLiteral($dataset_uri, 'dct:title', $title);
             // Add the description, identifier, issued date, modified date, contact point and landing page of the dataset
             $graph->addLiteral($dataset_uri, 'dct:description', @$definition['description']);
             $graph->addLiteral($dataset_uri, 'dct:identifier', str_replace(' ', '%20', $definition['collection_uri'] . '/' . $definition['resource_name']));
             $graph->addLiteral($dataset_uri, 'dct:issued', date(\DateTime::ISO8601, strtotime($definition['created_at'])));
             $graph->addLiteral($dataset_uri, 'dct:modified', date(\DateTime::ISO8601, strtotime($definition['updated_at'])));
             $graph->addResource($dataset_uri, 'dcat:landingPage', $dataset_uri);
             // Backwards compatibility
             if (!empty($definition['contact_point'])) {
                 $graph->addResource($dataset_uri, 'adms:contactPoint', $definition['contact_point']);
             }
             // Add the publisher resource to the dataset
             if (!empty($definition['publisher_name']) && !empty($definition['publisher_uri'])) {
                 $graph->addResource($dataset_uri, 'dct:publisher', $definition['publisher_uri']);
                 $graph->addResource($definition['publisher_uri'], 'a', 'foaf:Agent');
                 $graph->addLiteral($definition['publisher_uri'], 'foaf:name', $definition['publisher_name']);
             }
             // Add the keywords to the dataset
             if (!empty($definition['keywords'])) {
                 foreach (explode(',', $definition['keywords']) as $keyword) {
                     $keyword = trim($keyword);
                     $graph->addLiteral($dataset_uri, 'dcat:keyword', $keyword);
                 }
             }
             // Add the source resource if it's a URI
             if (strpos($definition['source'], 'http://') !== false || strpos($definition['source'], 'https://')) {
                 $graph->addResource($dataset_uri, 'dct:source', str_replace(' ', '%20', $definition['source']));
             }
             // Optional dct terms
             $optional = array('date', 'language', 'theme');
             foreach ($optional as $dc_term) {
                 if (!empty($definition[$dc_term])) {
                     if ($dc_term == 'language') {
                         $lang = $this->languages->getByName($definition[$dc_term]);
                         if (!empty($lang)) {
                             $graph->addResource($dataset_uri, 'dct:' . $dc_term, 'http://lexvo.org/id/iso639-3/' . $lang['lang_id']);
                             $graph->addResource('http://lexvo.org/id/iso639-3/' . $lang['lang_id'], 'a', 'dct:LinguisticSystem');
                         }
                     } elseif ($dc_term == 'theme') {
                         $theme = $this->themes->getByLabel($definition[$dc_term]);
                         if (!empty($theme)) {
                             $graph->addResource($dataset_uri, 'dcat:' . $dc_term, $theme['uri']);
                             $graph->addLiteral($theme['uri'], 'rdfs:label', $theme['label']);
                         }
                     } else {
                         $graph->addLiteral($dataset_uri, 'dct:' . $dc_term, $definition[$dc_term]);
                     }
                 }
             }
             // Add the distribution of the dataset
             if ($this->isDataGeoFormatted($definition)) {
                 $distribution_uri = $dataset_uri . '.geojson';
             } else {
                 $distribution_uri = $dataset_uri . '.json';
             }
             $graph->addResource($dataset_uri, 'dcat:distribution', $distribution_uri);
             $graph->addResource($distribution_uri, 'a', 'dcat:Distribution');
             $graph->addResource($distribution_uri, 'dcat:accessURL', $dataset_uri);
             $graph->addResource($distribution_uri, 'dcat:downloadURL', $distribution_uri);
             $graph->addLiteral($distribution_uri, 'dct:title', $title);
             $graph->addLiteral($distribution_uri, 'dct:description', 'A json feed of ' . $dataset_uri);
             $graph->addLiteral($distribution_uri, 'dcat:mediaType', 'application/json');
             $graph->addLiteral($distribution_uri, 'dct:issued', date(\DateTime::ISO8601, strtotime($definition['created_at'])));
             // Add the license to the distribution
             if (!empty($definition['rights'])) {
                 $license = $this->licenses->getByTitle($definition['rights']);
                 if (!empty($license) && !empty($license['url'])) {
                     $graph->addResource($dataset_uri . '.json', 'dct:license', $license['url']);
                     $graph->addResource($license['url'], 'a', 'dct:LicenseDocument');
                 }
             }
         }
     }
     return $graph;
 }
 /**
  * Add a resource to the graph
  * 
  * @param EasyRdf_Graph $graph
  * @param core_kernel_classes_Resource $resource
  * @ignore
  */
 private function addResource(EasyRdf_Graph $graph, core_kernel_classes_Resource $resource)
 {
     foreach ($resource->getRdfTriples() as $triple) {
         if (!empty($triple->lg)) {
             $graph->addLiteral($triple->subject, $triple->predicate, $triple->object, $triple->lg);
         } elseif (common_Utils::isUri($triple->object)) {
             $graph->add($triple->subject, $triple->predicate, $triple->object);
         } else {
             $graph->addLiteral($triple->subject, $triple->predicate, $triple->object);
         }
     }
 }
Beispiel #8
0
 public static function getBody($dataObj)
 {
     // Query parameters
     $query_string = '';
     if (!empty($_GET)) {
         $query_string = '?' . http_build_query(\Input::all());
     }
     // Links to pages
     $prev_link = '';
     $next_link = '';
     if (!empty($dataObj->paging)) {
         $input_array = array_except(\Input::all(), array('limit', 'offset'));
         $query_string = '';
         if (!empty($input_array)) {
             $query_string = '&' . http_build_query($input_array);
         }
         if (!empty($dataObj->paging['previous'])) {
             $prev_link = '?offset=' . $dataObj->paging['previous'][0] . '&limit=' . $dataObj->paging['previous'][1] . $query_string;
         }
         if (!empty($dataObj->paging['next'])) {
             $next_link = '?offset=' . $dataObj->paging['next'][0] . '&limit=' . $dataObj->paging['next'][1] . $query_string;
         }
     }
     // Create the link to the dataset
     $dataset_link = \URL::to($dataObj->definition['collection_uri'] . "/" . $dataObj->definition['resource_name']);
     // Append rest parameters
     if (!empty($dataObj->rest_parameters)) {
         $dataset_link .= '/' . implode('/', $dataObj->rest_parameters);
     }
     if (!empty($dataObj->source_definition)) {
         $type = $dataObj->source_definition['type'];
         // Check if other views need to be served
         switch ($type) {
             case 'XLS':
             case 'CSV':
                 $first_row = array_shift($dataObj->data);
                 array_unshift($dataObj->data, $first_row);
                 if (is_array($first_row) || is_object($first_row)) {
                     $view = 'dataset.tabular';
                     $data = $dataObj->data;
                 } else {
                     $view = 'dataset.code';
                     $data = self::displayTree($dataObj->data);
                 }
                 break;
             case 'SHP':
                 $view = 'dataset.map';
                 $data = $dataset_link . '.map' . $query_string;
                 break;
             case 'XML':
                 $view = 'dataset.code';
                 $data = self::displayTree($dataObj->data, 'xml');
                 break;
             default:
                 if ($dataObj->is_semantic) {
                     // This data object is always semantic
                     $view = 'dataset.turtle';
                     // Check if a configuration is given
                     $conf = array();
                     if (!empty($dataObj->semantic->conf)) {
                         $conf = $dataObj->semantic->conf;
                     }
                     $data = $dataObj->data->serialise('turtle');
                 } else {
                     $view = 'dataset.code';
                     $data = self::displayTree($dataObj->data);
                 }
                 break;
         }
     } elseif ($dataObj->is_semantic) {
         // The data object can be semantic without a specified source type
         $view = 'dataset.code';
         $data = $dataObj->data->serialise('turtle');
     } else {
         // Collection view
         $view = 'dataset.collection';
         $data = $dataObj->data;
     }
     // Gather meta-data to inject as a JSON-LD document so it can be picked up by search engines
     $definition = $dataObj->definition;
     $uri = \Request::root();
     $graph = new \EasyRdf_Graph();
     // Create the dataset uri
     $dataset_uri = $uri . "/" . $definition['collection_uri'] . "/" . $definition['resource_name'];
     $dataset_uri = str_replace(' ', '%20', $dataset_uri);
     // Add the dataset resource and its description
     $graph->addResource($dataset_uri, 'a', 'schema:Dataset');
     // Add the title to the dataset resource of the catalog
     if (!empty($definition['title'])) {
         $graph->addLiteral($dataset_uri, 'schema:headline', $definition['title']);
     }
     // Add the description, identifier, issues, modified of the dataset
     $graph->addLiteral($dataset_uri, 'schema:description', @$definition['description']);
     $graph->addLiteral($dataset_uri, 'schema:dateCreated', date(\DateTime::ISO8601, strtotime($definition['created_at'])));
     $graph->addLiteral($dataset_uri, 'schema:dateModified', date(\DateTime::ISO8601, strtotime($definition['updated_at'])));
     // Add the publisher resource to the dataset
     if (!empty($definition['publisher_name']) && !empty($definition['publisher_uri'])) {
         $graph->addResource($dataset_uri, 'schema:publisher', $definition['publisher_uri']);
     }
     // Optional dct terms
     $optional = array('date', 'language');
     $languages = \App::make('Tdt\\Core\\Repositories\\Interfaces\\LanguageRepositoryInterface');
     $licenses = \App::make('Tdt\\Core\\Repositories\\Interfaces\\LicenseRepositoryInterface');
     foreach ($optional as $dc_term) {
         if (!empty($definition[$dc_term])) {
             if ($dc_term == 'language') {
                 $lang = $languages->getByName($definition[$dc_term]);
                 if (!empty($lang)) {
                     $graph->addResource($dataset_uri, 'schema:inLanguage', 'http://lexvo.org/id/iso639-3/' . $lang['lang_id']);
                 }
             } else {
                 $graph->addLiteral($dataset_uri, 'schema:datasetTimeInterval', $definition[$dc_term]);
             }
         }
     }
     // Add the distribution of the dataset for SEO
     $format = '.json';
     if ($definition['source_type'] == 'ShpDefinition') {
         $format = '.geojson';
     }
     $dataDownload = $graph->newBNode();
     $graph->addResource($dataset_uri, 'schema:distribution', $dataDownload);
     $graph->addResource($dataDownload, 'a', 'schema:DataDownload');
     $graph->addResource($dataDownload, 'schema:contentUrl', $dataset_uri . $format);
     // Add the license to the distribution
     if (!empty($definition['rights'])) {
         $license = $licenses->getByTitle($definition['rights']);
         if (!empty($license) && !empty($license['url'])) {
             $graph->addResource($dataset_uri, 'schema:license', $license['url']);
         }
         if (!empty($license)) {
             $dataObj->definition['rights_uri'] = $license['url'];
         }
     }
     $jsonld = $graph->serialise('jsonld');
     // Render the view
     return \View::make($view)->with('title', 'Dataset: ' . $dataObj->definition['collection_uri'] . "/" . $dataObj->definition['resource_name'] . ' | The Datatank')->with('body', $data)->with('page_title', $dataObj->definition['collection_uri'] . "/" . $dataObj->definition['resource_name'])->with('definition', $dataObj->definition)->with('paging', $dataObj->paging)->with('source_definition', $dataObj->source_definition)->with('formats', $dataObj->formats)->with('dataset_link', $dataset_link)->with('prev_link', $prev_link)->with('next_link', $next_link)->with('query_string', $query_string)->with('json_ld', $jsonld);
 }
 /**
  * testSerialiseReferenceAlreadyOutput
  *
  * Test referencing a resource with a single property that
  * has already been output.
  */
 function testSerialiseReferenceAlreadyOutput()
 {
     $graph = new EasyRdf_Graph();
     $graph->addLiteral('http://example.com/2', 'rdf:label', 'label');
     $graph->addResource('http://example.com/1', 'foaf:homepage', 'http://example.com/2');
     $this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" . "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" . "         xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">\n\n" . "  <rdf:Description rdf:about=\"http://example.com/2\">\n" . "    <rdf:label>label</rdf:label>\n" . "  </rdf:Description>\n\n" . "  <rdf:Description rdf:about=\"http://example.com/1\">\n" . "    <foaf:homepage rdf:resource=\"http://example.com/2\"/>\n" . "  </rdf:Description>\n\n" . "</rdf:RDF>\n", $this->_serialiser->serialise($graph, 'rdfxml'));
 }
 * @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";
?>
<html>
<head>
  <title>Example of using EasyRdf_Graph directly</title>
</head>
<body>

<?php 
$graph = new EasyRdf_Graph();
$graph->addResource("http://example.com/joe", "rdf:type", "foaf:Person");
$graph->addLiteral("http://example.com/joe", "foaf:name", "Joe Bloggs");
$graph->addLiteral("http://example.com/joe", "foaf:name", "Joseph Bloggs");
$graph->add("http://example.com/joe", "rdfs:label", "Joe");
$graph->setType("http://njh.me/", "foaf:Person");
$graph->add("http://njh.me/", "rdfs:label", "Nick");
$graph->addLiteral("http://njh.me/", "foaf:name", "Nicholas Humfrey");
$graph->addResource("http://njh.me/", "foaf:homepage", "http://www.aelius.com/njh/");
?>

<p>
  <b>Name:</b> <?php 
echo $graph->get("http://example.com/joe", "foaf:name");
?>
 <br />
  <b>Names:</b> <?php 
echo $graph->join("http://example.com/joe", "foaf:name");