protected function processUri($uri) { echo "Accessing {$uri}...\n"; $retries = 3; while (true) { try { $graph = Graph::newAndLoad($uri); break; } catch (\Exception $e) { $retries--; if ($retries < 0) { throw $e; } echo "Error! Sleeping for 10 secs, then retrying ({$retries} tries left)...\n"; sleep(10); } } $triples = $graph->serialise('ntriples'); fwrite($this->handle, $triples); $this->visited[] = $uri; preg_match_all('/<(https?:\\/\\/[^>]*)>/', $triples, $matches); foreach (array_unique($matches[1]) as $uri) { $this->enqueue($uri); } }
/** * Seed the themes * * return @void */ private function seedThemes() { $this->info('---- Seeding new themes ----'); $base_uri = $this->argument('uri'); $taxonomy_uri = $this->argument('taxonomy_uri'); if (empty($taxonomy_uri)) { $taxonomy_uri = $base_uri; } // Try to get the themes from the ns.thedatatank.com (semantic data) try { $this->info('Trying to fetch triples from the uri: ' . $base_uri); $themes_graph = Graph::newAndLoad($base_uri); if ($themes_graph->isEmpty()) { $this->info('We could not reach the online themes.'); } else { $this->info('Found new themes online, removing the old ones.'); // Empty the themes table \Theme::truncate(); } // Fetch the resources with a skos:conceptScheme relationship $resources = $themes_graph->allOfType('skos:ConceptScheme'); $taxonomy_uris = array(); foreach ($resources as $r) { array_push($taxonomy_uris, $r->getUri()); } if (!empty($taxonomy_uris)) { if (count($taxonomy_uris) == 1) { $taxonomy_uri = $taxonomy_uris[0]; } else { // Check if one of the possible taxonomy uris compares to the uri of the document foreach ($taxonomy_uris as $tax_uri) { if ($base_uri == $tax_uri) { $taxonomy_uri = $tax_uri; break; } $this->error('None of the URIs that have the skos:ConceptScheme property matched the URI of the document, please specify the taxonomy URI as a second parameter.'); } } } else { $this->error('No resource has been found with a property of skos:ConceptScheme.'); } // Fetch all of the themes foreach ($themes_graph->resourcesMatching('skos:inScheme') as $theme) { if ($theme->get('skos:inScheme')->getUri() == $taxonomy_uri) { $uri = $theme->getUri(); $label = $theme->getLiteral('rdfs:label'); if (!empty($label) && !empty($uri)) { $label = $label->getValue(); $this->info('Added ' . $uri . ' with label ' . $label); \Theme::create(array('uri' => $uri, 'label' => $label)); } } } $this->info('Added new themes.'); } catch (Exception $ex) { $this->info('An error occurred when we tried to fetch online themes.'); } }
/** * Seed the themes * * return @void */ private function seedThemes() { $this->command->info('---- DCAT Themes ----'); $uri = 'http://ns.thedatatank.com/dcat/themes#Taxonomy'; $themes_fetched = false; // Try to get the themes from the ns.thedatatank.com (semantic data) try { $this->command->info('Trying to fetch new themes online.'); $themes_graph = Graph::newAndLoad($uri); if ($themes_graph->isEmpty()) { $this->command->info('We could not reach the online themes.'); } else { $themes_fetched = true; $this->command->info('Found new themes online, removing the old ones.'); // Empty the themes table \Theme::truncate(); } // Fetch all of the themes foreach ($themes_graph->resourcesMatching('skos:inScheme') as $theme) { if ($theme->get('skos:inScheme')->getUri() == $uri) { $theme_uri = $theme->getUri(); $label = $theme->getLiteral('rdfs:label'); if (!empty($label) && !empty($theme_uri)) { $label = $label->getValue(); $this->command->info('Added ' . $uri . ' with label ' . $label); \Theme::create(array('uri' => $theme_uri, 'label' => $label)); } } } $this->command->info('Added new themes.'); } catch (Exception $ex) { $this->command->info('An error occurred when we tried to fetch online themes.'); } // If it's not available, get them from a file (json) if (!$themes_fetched) { $this->command->info('Trying to fetch the themes from the local json file containing a default set of themes.'); $themes = json_decode(file_get_contents(app_path() . '/database/seeds/data/themes.json')); if (!empty($themes)) { $this->command->info('Found new themes, removing the old ones.'); // Empty the themes table \Theme::truncate(); foreach ($themes as $theme) { \Theme::create(array('uri' => $theme->uri, 'label' => $theme->label)); } if (!empty($themes)) { $this->command->info('Added themes from the local json file.'); } } else { $this->command->info('No themes were found in the local json file, the old ones will not be replaced.'); } } }
<?php use EasyRdf\Graph; use EasyRdf\Format; use EasyRdf\Serialiser\GraphViz; $app->get('/image', function () { $graph = Graph::newAndLoad(site_base_uri() . '/asset/dataset/countries.rdf'); $format = Format::getFormat('png'); $viz = new GraphViz(); header("Content-Type: " . $format->getDefaultMimeType()); echo $viz->renderImage($graph, $format); die; })->name('home');
protected function open() { \EasyRdf\RdfNamespace::set('locn', 'http://www.w3.org/ns/locn#'); $graph = Graph::newAndLoad($this->extractor->uri, $this->extractor->format); $this->datasets = $graph->allOfType('dcat:Dataset'); }
/** * Fetch the default licenses * * @return \EasyRdf_Graph */ private function fetchDefaultGraph() { $license_uri = $this->licenses_uri . $this->DEFAULT_LICENSE . '.json'; return Graph::newAndLoad($license_uri, 'jsonld'); }