Пример #1
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);
 }
 public function testNewBNode()
 {
     $graph = new EasyRdf_Graph();
     $bnodeOne = $graph->newBNode();
     $this->assertEquals('_:genid1', $bnodeOne->getUri());
     $bnodeTwo = $graph->newBNode();
     $this->assertEquals('_:genid2', $bnodeTwo->getUri());
 }
Пример #3
0
function convert_to_rdf($path)
{
    //get processed array
    $uris = get_uris();
    $result = process_spreadsheet($path);
    init_vocabularies();
    global $voc_keys;
    $root = new EasyRdf_Graph();
    $courses = $root->newBNode('rdf:Seq');
    //create container
    //iterate through array and create nodes
    foreach ($result as $key => $value) {
        $resource_uri = $uris[$key];
        $temp_cours = new EasyRdf_Resource($resource_uri, $root);
        $courses->append($temp_cours);
        foreach ($value as $propName => $propValue) {
            if ($propName == null || $propName == "" || $propName == "id") {
                continue;
            }
            $predicate_url = $voc_keys[$propName];
            //add to resource predicate with property. probably addLiteral method
            $temp_cours->addLiteral($predicate_url, $propValue);
        }
    }
    return $root->serialise("rdfxml");
}
Пример #4
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);
 }
$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');
$njh->addResource('foaf:homepage', 'http://www.aelius.com/njh/');
$easyrdf->add('doap:maintainer', $njh);
$easyrdf->add('doap:developer', $njh);
$easyrdf->add('foaf:maker', $njh);
print $doap->serialise('rdfxml');
Пример #6
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();
 }
Пример #7
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;
 }
Пример #8
0
 if (isset($_REQUEST['foaf:knows']) && strlen($_REQUEST['foaf:knows'][0]) > 0) {
     foreach ($_REQUEST['foaf:knows'] as $key => $person_uri) {
         if (strlen($person_uri) > 0) {
             $graph->addResource($me, 'foaf:knows', $person_uri);
         }
     }
 }
 // ----- pingback:to relation ----- //
 $graph->addResource($me, 'pingback:to', $base_uri . '/pingback.php');
 // certificates
 // write certificates' public keys (if we have more than one)
 foreach ($_REQUEST['modulus'] as $key => $val) {
     if (strlen($val) > 0) {
         $modulus = preg_replace('/\\s+/', '', $val);
         $exponent = strlen($_REQUEST['exponent'][$key]) > 0 ? trim($_REQUEST['exponent'][$key]) : '65537';
         $cert = $graph->newBNode('cert:RSAPublicKey');
         $cert->add('cert:modulus', array('type' => 'literal', 'datatype' => 'http://www.w3.org/2001/XMLSchema#hexBinary', 'value' => $modulus));
         $cert->add('cert:exponent', array('type' => 'literal', 'datatype' => 'http://www.w3.org/2001/XMLSchema#int', 'value' => $exponent));
         $me->add('cert:key', $cert);
     }
 }
 // ----- GENERATE CERTIFICATE ----- //
 // Do not generate a certificate if we're just editing the profile
 if ($_REQUEST["action"] == 'new') {
     // append other webids after the local one
     $foafLocation = array();
     $foafLocation[] = $webid;
     foreach ($_REQUEST['webid_uri'] as $val) {
         if (strlen($val) > 0) {
             $foafLocation[] = $val;
         }
/**
 * 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;
}
Пример #10
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);
 }