forked from openphacts/OPS_LinkedDataApi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtuosoformatter.class.php
More file actions
24 lines (20 loc) · 1014 Bytes
/
virtuosoformatter.class.php
File metadata and controls
24 lines (20 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
class VirtuosoFormatter {
function formatQuery ( $query ) {
$output = $query ;
if (stristr($query , "CONSTRUCT") != false
&& stristr($query , "SELECT") != false
&& preg_match('/CONSTRUCT.*WHERE.*SELECT/s',$query) == 0) {
$output = substr($output , 0 , strpos($query , "}")+1) . " WHERE { " . substr($output , strpos($query , "}")+1) . "}";
}
$output = preg_replace('/\([ ]*GROUP_CONCAT[ ]*\([ ]*DISTINCT/i' , '( sql:GROUP_DIGEST (' , $output);
$output = preg_replace('/GROUP_CONCAT/i' , 'sql:GROUP_CONCAT' , $output);
$output = preg_replace('/;[ ]*SEPARATOR[ ]*=[ ]*/i' , ', ' , $output);
$output = preg_replace("/[ ]*sql:GROUP_DIGEST[ ]*\([ ]*[ a-z\?,_]*, [\"'] , [\"']/i" , '$0 , 1000 , 1' , $output);
//$output = preg_replace('#(\?[a-z,]*_uri[ ]*=[ ]*)(<http://.*>)#iU' , '$1 IRI($2)' , $output);
$output = preg_replace('/\([ ]*COUNT[ ]*\([ ]*\?/' , '( COUNT (DISTINCT ?' , $output);
$output = preg_replace("/(^\s+|\s+$)/m"," ",$output);
return $output ;
}
}
?>