|
From: <cw...@us...> - 2007-09-18 17:55:19
|
Revision: 537
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=537&view=rev
Author: cweiske
Date: 2007-09-18 10:55:11 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
Allow SPARQL debugging
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/Query.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
trunk/rdfapi-php/test/config.php.dist
trunk/rdfapi-php/test/sparql-test.php
trunk/rdfapi-php/test/sparqlDb-test.php
Modified: trunk/rdfapi-php/api/sparql/Query.php
===================================================================
--- trunk/rdfapi-php/api/sparql/Query.php 2007-08-20 17:21:35 UTC (rev 536)
+++ trunk/rdfapi-php/api/sparql/Query.php 2007-09-18 17:55:11 UTC (rev 537)
@@ -20,6 +20,12 @@
protected $base;
/**
+ * Original SPARQL query string
+ * @var string
+ */
+ protected $queryString = null;
+
+ /**
* Array that contains used prefixes and namespaces.
* Key is the prefix, value the namespace.
*
@@ -555,6 +561,30 @@
return true;
}//public function isIncomplete()
+
+
+ /**
+ * Sets the orignal query string
+ *
+ * @param string $queryString SPARQL query string
+ */
+ public function setQueryString($queryString)
+ {
+ $this->queryString = $queryString;
+ }//public function setQueryString($queryString)
+
+
+
+ /**
+ * Returns the orignal query string
+ *
+ * @return string SPARQL query string
+ */
+ public function getQueryString()
+ {
+ return $this->queryString;
+ }//public function getQueryString()
+
}// end class: Query.php
@@ -648,6 +678,7 @@
{
return $this->getName();
}
+
}//class Query_ResultVariable
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-08-20 17:21:35 UTC (rev 536)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-09-18 17:55:11 UTC (rev 537)
@@ -115,16 +115,23 @@
*/
public function queryModel($dataset, Query $query, $resultform = false)
{
+ if (isset($GLOBALS['debugSparql']) && $GLOBALS['debugSparql']) {
+ echo "\n" . 'SPARQL query: ' . $query->getQueryString() . "\n";
+ }
+
$this->query = $query;
$this->dataset = $dataset;
+
$qsimp = new SparqlEngineDb_QuerySimplifier();
$qsimp->simplify($this->query);
+
$this->sg = new SparqlEngineDb_SqlGenerator ($this->query, $this->dbConn, $this->arModelIds);
$this->rc = new SparqlEngineDb_ResultConverter($this->query, $this->sg, $this);
$this->ts = new SparqlEngineDb_TypeSorter ($this->query, $this->dbConn);
+
$this->setOptions();
- if($this->query->isEmpty()){
+ if ($this->query->isEmpty()){
$vartable[0]['patternResult'] = null;
return $this->returnResult($vartable, $resultform);
}
@@ -312,7 +319,10 @@
// I want associative arrays.
$oldmode = $this->dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
-//var_dump($strSql);
+ if (isset($GLOBALS['debugSparql']) && $GLOBALS['debugSparql']) {
+ echo 'SQL query: ' . $strSql . "\n";
+ }
+
if ($nLimit === null && $nOffset == 0) {
$ret = $this->dbConn->execute($strSql);
} else if ($nLimit === null) {
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-08-20 17:21:35 UTC (rev 536)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-09-18 17:55:11 UTC (rev 537)
@@ -105,9 +105,10 @@
$this->prepare();
if ($queryString) {
+ $this->query->setQueryString($queryString);
$uncommentedQuery = $this->uncomment($queryString);
$this->tokenize($uncommentedQuery);
- $this->querystring = $uncommentedQuery;
+ $this->queryString = $uncommentedQuery;
$this->parseQuery();
if (!$this->query->isComplete()) {
throw new SparqlParserException(
@@ -136,7 +137,7 @@
protected function prepare()
{
$this->query = new Query();
- $this->querystring = null;
+ $this->queryString = null;
$this->tokens = array();
$this->tmp = null;
// add the default prefixes defined in constants.php
@@ -147,7 +148,7 @@
/**
- * Tokenizes the querystring.
+ * Tokenizes the query string.
*
* @param String $queryString
* @return void
@@ -1481,6 +1482,7 @@
* Parses an RDF collection.
*
* @param TriplePattern $trp
+ *
* @return Node The first parsed label
*/
protected function parseCollection(&$trp)
@@ -1498,7 +1500,7 @@
}
$trp[] = new QueryTriple($this->parseNode($tmpLabel),new Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"),new Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"));
return $firstLabel;
- }
+ }//protected function parseCollection(&$trp)
}// end class: SparqlParser.php
Modified: trunk/rdfapi-php/test/config.php.dist
===================================================================
--- trunk/rdfapi-php/test/config.php.dist 2007-08-20 17:21:35 UTC (rev 536)
+++ trunk/rdfapi-php/test/config.php.dist 2007-09-18 17:55:11 UTC (rev 537)
@@ -21,6 +21,9 @@
//enable this to get more information about failing unit tests
//$GLOBALS['debugTests'] = true;
+//debug SPARQL engine
+//$GLOBALS['debugSparql'] = true;
+
//used in W3C earl report serialization
$GLOBALS['earlReport'] = array(
'reporter' => array(
Modified: trunk/rdfapi-php/test/sparql-test.php
===================================================================
--- trunk/rdfapi-php/test/sparql-test.php 2007-08-20 17:21:35 UTC (rev 536)
+++ trunk/rdfapi-php/test/sparql-test.php 2007-09-18 17:55:11 UTC (rev 537)
@@ -9,9 +9,9 @@
$model->load(SPARQL_TESTFILES . 'data/model9.n3');
$qs = 'SELECT * WHERE { ?s ?p ?o}';
-$result = $model->sparqlQuery($qs, 'HTML');
+$result = $model->sparqlQuery($qs);
-header('Content-Type: text/html');
-echo $result . "\n";
-//var_dump($result);
+//header('Content-Type: text/html');
+//echo $result . "\n";
+var_dump($result);
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/test/sparqlDb-test.php
===================================================================
--- trunk/rdfapi-php/test/sparqlDb-test.php 2007-08-20 17:21:35 UTC (rev 536)
+++ trunk/rdfapi-php/test/sparqlDb-test.php 2007-09-18 17:55:11 UTC (rev 537)
@@ -36,6 +36,10 @@
UNION {?value ?p ?o . FILTER (isIRI(?value)) }
}
EOT;
-var_dump($dbModel->sparqlQuery($qs));
+$qs = <<<EOT
+SELECT DISTINCT datatype(?o) as ?dt WHERE { ?s ?p ?o} LIMIT 3
+EOT;
+$qs= '-';
+var_dump($database->sparqlQuery($qs, null));
//echo $dbModel->sparqlQuery($qs, 'HTML');
?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|