Esempio n. 1
0
 /**
  *
  */
 private function hasParameters()
 {
     $sparql_param_defaults = array('?s', '?p', '?o');
     foreach (SparqlQueryBuilder::getParameters() as $param) {
         if (!in_array($param, $sparql_param_defaults)) {
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Check if hash variants should be used by the sparql query builder
  *
  */
 private function checkHashVariants()
 {
     SparqlQueryBuilder::setHashVariant(\Request::query('hash_variants', false));
 }
Esempio n. 3
0
 public function testConstructQueryWithDottedURI()
 {
     $query_builder = new QueryBuilder(array('?s', '?p', '?o'));
     $construct_query = $query_builder->createFetchQuery('http://foo.test/sub/sub.space', 'http://foo.test', 'http://foo.test/namedgraph#version1', 150, 0, 3);
     $expected_query = 'construct {<http://foo.test/sub/sub.space> ?p ?o.?o ?p2 ?o2. ?o2 ?p3 ?o3. } FROM <http://foo.test/namedgraph#version1>{ <http://foo.test/sub/sub.space> ?p ?o.OPTIONAL { ?o ?p2 ?o2. ?o2 ?p3 ?o3. }}' . ' offset 0 limit 150';
     $this->assertEquals($expected_query, $construct_query);
 }
Esempio n. 4
0
 /**
  * Resolve a graph pattern query (/all route)
  *
  * @param string $format The format of the request
  *
  * @return \Response
  */
 public function solveQuery($format = null)
 {
     $data;
     if (!empty($format)) {
         $format = ltrim($format, '.');
     }
     // Ignore the rest of the uri after /all and work with the request parameters as they were given
     $cache_string = sha1($this->getRawRequestURI(\Request::root()));
     // Check if the response to the query has been cached already
     if (Cache::has($cache_string)) {
         $data = Cache::get($cache_string);
     } else {
         // Get the graph pattern query string parameters from the request
         list($s, $p, $o) = $this->getTemplateParameters();
         // Pass them to our sparql query builder
         SparqlQueryBuilder::setParameters(array($s, $p, $o));
         $base_uri = null;
         // If no parameter has been filled in, the URI we have to match triples with is the root of our application
         if ($s == '?s' && $p == '?p' && $o == '?o') {
             $base_uri = \Request::root();
         }
         // Fetch matching triples
         $result = $this->triples->getTriples($base_uri, \Request::get('limit', 100), \Request::get('offset', 0));
         // If the graph contains no triples, then the graph pattern couldn't resolve to anything, 404 it is
         if ($result->countTriples() == 0) {
             \App::abort(404, "The resource couldn't be found, nor dereferenced.");
         }
         $definition = array('resource_name' => "all", 'collection_uri' => "");
         $source_definition = array('description' => 'Semantic data collected out the configured semantic data sources.', 'type' => 'Semantic');
         $data = new Data();
         $data->definition = $definition;
         $data->source_definition = $source_definition;
         $data->data = $result;
         $data->is_semantic = true;
         // Add the available, supported formats to the object
         $format_helper = new FormatHelper();
         $data->formats = $format_helper->getAvailableFormats($data);
         // Store in cache for a default of 5 minutes
         Cache::put($cache_string, $data, 5);
     }
     // Add the hydra namespace, it's not present in the easy rdf namespaces by default
     \EasyRdf_Namespace::set('hydra', 'http://www.w3.org/ns/hydra/core#');
     // Return the formatted response with content negotiation
     $response = ContentNegotiator::getResponse($data, $format);
     // Pass a Vary header so that browsers know they have to take the accept header
     // into consideration when they apply caching client side
     $response->header('Vary', 'Accept');
     // Allow CORS
     $response->header('Access-Control-Allow-Origin', '*');
     return $response;
 }