Skip to content

Commit

Permalink
Fixes #638
Browse files Browse the repository at this point in the history
  • Loading branch information
kouralex authored and osma committed Apr 9, 2018
1 parent 375fe4d commit de27112
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ public function __construct($endpoint, $graph, $model) {

}

/**
* Returns prefix-definitions for a query
*
* @param string $query
* @return string
*/
protected function generateQueryPrefixes($query)
{
// Check for undefined prefixes
$prefixes = '';
foreach (EasyRdf\RdfNamespace::namespaces() as $prefix => $uri) {
if (strpos($query, "{$prefix}:") !== false and
strpos($query, "PREFIX {$prefix}:") === false
) {
$prefixes .= "PREFIX {$prefix}: <{$uri}>\n";
}
}
return $prefixes;
}

/**
* Execute the SPARQL query using the SPARQL client, logging it as well.
* @param string $query SPARQL query to perform
Expand All @@ -67,7 +87,7 @@ public function __construct($endpoint, $graph, $model) {
protected function query($query) {
$queryId = sprintf("%05d", rand(0, 99999));
$logger = $this->model->getLogger();
$logger->info("[qid $queryId] SPARQL query:\n$query\n");
$logger->info("[qid $queryId] SPARQL query:\n" . $this->generateQueryPrefixes($query) . "\n$query\n");
$starttime = microtime(true);
$result = $this->client->query($query);
$elapsed = intval(round((microtime(true) - $starttime) * 1000));
Expand Down

0 comments on commit de27112

Please sign in to comment.