protected function preRun() { $data = parent::getData(); $resourceUri = JURI::base() . "index.php?com_content&view=article&id=" . $data["articleID"]; $annotation = new EasyRdf_Graph($resourceUri); foreach ($data["entityIDs"] as $entityID) { $annotation->addResource($resourceUri, "sioc:about", "http://www.mni.thm.de/user/" . $entityID); } parent::setData($annotation->serialise("rdfxml")); }
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); }
/** * 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); }
/** * 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); }
/** * 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(); }
function add_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(); $me = $graph->resource($this->webid); $graph->addResource($me, 'foaf:knows', $uri); // reserialize graph $data = $graph->serialise($format); if (!is_scalar($data)) { $data = var_export($data, true); } else { $data = print_r($data, true); } // write profile to file $pf = fopen($path . '/foaf.rdf', 'w') or error('Cannot open profile RDF file!'); fwrite($pf, $data); fclose($pf); $pf = fopen($path . '/foaf.txt', 'w') or error('Cannot open profile PHP file!'); fwrite($pf, $data); fclose($pf); // cache the user's data if possible $friend = new MyProfile($uri, $this->base_uri, SPARQL_ENDPOINT); $friend->load(); // everything is fine return success("You have just added " . $friend->get_name() . " to your list of friends."); }
/** * 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; }
$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'])); }
public function testDumpResource() { $graph = new EasyRdf_Graph(); $graph->addResource('http://example.com/joe#me', 'rdf:type', 'foaf:Person'); $graph->addResource('http://example.com/joe#me', 'foaf:homepage', 'http://example.com/'); $graph->add('http://example.com/joe#me', 'foaf:knows', $graph->newBnode()); $text = $graph->dumpResource('http://example.com/joe#me', false); $this->assertContains('http://example.com/joe#me', $text); $this->assertContains('-> rdf:type -> foaf:Person', $text); $this->assertContains('-> foaf:homepage -> http://example.com/', $text); $this->assertContains('-> foaf:knows -> _:genid1', $text); $html = $graph->dumpResource('http://example.com/joe#me', true); $this->assertContains('http://example.com/joe#me', $html); $this->assertContains('>rdf:type</span>', $html); $this->assertContains('>foaf:Person</a>', $html); $this->assertContains('>foaf:homepage</span>', $html); $this->assertContains('>http://example.com/</a>', $html); $this->assertContains('>foaf:knows</span>', $html); $this->assertContains('>_:genid1</a>', $html); }
/** * 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; }
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')); }
* @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"; ?> <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
private function getGraphs() { $graph = new \EasyRdf_Graph(); $graph->addResource('http://schema.org/Article', 'rdf:type', 'rdfs:Class'); $graph->addResource('http://schema.org/Article', 'rdfs:subClassOf', 'http://schema.org/CreativeWork'); $graph->addResource('http://schema.org/BlogPosting', 'rdf:type', 'rdfs:Class'); $graph->addResource('http://schema.org/BlogPosting', 'rdfs:subClassOf', 'http://schema.org/SocialMediaPosting'); $graph->addResource('http://schema.org/CreativeWork', 'rdf:type', 'rdfs:Class'); $graph->addResource('http://schema.org/CreativeWork', 'rdfs:subClassOf', 'http://schema.org/Thing'); $graph->addResource('http://schema.org/Person', 'rdf:type', 'rdfs:Class'); $graph->addResource('http://schema.org/Person', 'rdfs:subClassOf', 'http://schema.org/Thing'); $graph->addResource('http://schema.org/SocialMediaPosting', 'rdf:type', 'rdfs:Class'); $graph->addResource('http://schema.org/SocialMediaPosting', 'rdfs:subClassOf', 'http://schema.org/Article'); $graph->addResource('http://schema.org/Thing', 'rdf:type', 'rdfs:Class'); $graph->addResource('http://schema.org/articleBody', 'rdf:type', 'rdf:Property'); $graph->addResource('http://schema.org/articleBody', 'schema:domainIncludes', 'http://schema.org/Article'); $graph->addResource('http://schema.org/articleBody', 'schema:rangeIncludes', 'http://schema.org/Text'); $graph->addResource('http://schema.org/articleSection', 'rdf:type', 'rdf:Property'); $graph->addResource('http://schema.org/articleSection', 'schema:domainIncludes', 'http://schema.org/Article'); $graph->addResource('http://schema.org/articleSection', 'schema:rangeIncludes', 'http://schema.org/Text'); $graph->addResource('http://schema.org/author', 'rdf:type', 'rdf:Property'); $graph->addResource('http://schema.org/author', 'schema:domainIncludes', 'http://schema.org/CreativeWork'); $graph->addResource('http://schema.org/author', 'schema:rangeIncludes', 'http://schema.org/Person'); $graph->addResource('http://schema.org/datePublished', 'rdf:type', 'rdf:Property'); $graph->addResource('http://schema.org/datePublished', 'schema:domainIncludes', 'http://schema.org/CreativeWork'); $graph->addResource('http://schema.org/datePublished', 'schema:rangeIncludes', 'http://schema.org/Date'); $graph->addResource('http://schema.org/headline', 'rdf:type', 'rdf:Property'); $graph->addResource('http://schema.org/headline', 'schema:domainIncludes', 'http://schema.org/CreativeWork'); $graph->addResource('http://schema.org/headline', 'schema:rangeIncludes', 'http://schema.org/Text'); $graph->addResource('http://schema.org/isFamilyFriendly', 'rdf:type', 'rdf:Property'); $graph->addResource('http://schema.org/isFamilyFriendly', 'schema:domainIncludes', 'http://schema.org/CreativeWork'); $graph->addResource('http://schema.org/isFamilyFriendly', 'schema:rangeIncludes', 'http://schema.org/Boolean'); $graph->addResource('http://schema.org/name', 'rdf:type', 'rdf:Property'); $graph->addResource('http://schema.org/name', 'schema:domainIncludes', 'http://schema.org/Thing'); $graph->addResource('http://schema.org/name', 'schema:rangeIncludes', 'http://schema.org/Text'); $graph->addResource('http://schema.org/sharedContent', 'rdf:type', 'rdf:Property'); $graph->addResource('http://schema.org/sharedContent', 'schema:domainIncludes', 'http://schema.org/SocialMediaPosting'); $graph->addResource('http://schema.org/sharedContent', 'schema:rangeIncludes', 'http://schema.org/CreativeWork'); return [$graph]; }
* @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"; ?> <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://aelius.com/njh#me", "foaf:Person"); $graph->add("http://aelius.com/njh#me", "rdfs:label", "Nick"); $graph->addLiteral("http://aelius.com/njh#me", "foaf:name", "Nicholas Humfrey"); $graph->addResource("http://aelius.com/njh#me", "foaf:homepage", "http://aelius.com/njh"); ?> <p> <b>Name:</b> <?php echo $graph->get("http://example.com/joe", "foaf:name"); ?> <br /> <b>Names:</b> <?php