You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(19) |
Jul
(6) |
Aug
(65) |
Sep
(4) |
Oct
(5) |
Nov
(8) |
Dec
(2) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(1) |
Feb
(9) |
Mar
(1) |
Apr
|
May
(8) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <cw...@us...> - 2007-08-08 13:47:54
|
Revision: 475
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=475&view=rev
Author: cweiske
Date: 2007-08-08 06:47:51 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
- Enable all tests
- Fix result array of test-B-18
- Modify debug message to tell which array was expected and which the calculated result
Modified Paths:
--------------
trunk/rdfapi-php/test/unit/Sparql/SparqlDbTests_test.php
trunk/rdfapi-php/test/unit/Sparql/cases.php
trunk/rdfapi-php/test/unit/Sparql/result/test-B-18.res
Modified: trunk/rdfapi-php/test/unit/Sparql/SparqlDbTests_test.php
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/SparqlDbTests_test.php 2007-08-08 12:56:38 UTC (rev 474)
+++ trunk/rdfapi-php/test/unit/Sparql/SparqlDbTests_test.php 2007-08-08 13:47:51 UTC (rev 475)
@@ -94,9 +94,11 @@
echo get_class($e) . ': ' . $e->getMessage() . "\n";
}
echo 'Query string: ' . $qs . "\n";
+ echo "Expected:\n";
echo Console_Color::convert('%p');
var_dump($result);
echo Console_Color::convert('%n');
+ echo "Result:\n";
echo Console_Color::convert('%r');
var_dump($t);
echo Console_Color::convert('%n');
Modified: trunk/rdfapi-php/test/unit/Sparql/cases.php
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/cases.php 2007-08-08 12:56:38 UTC (rev 474)
+++ trunk/rdfapi-php/test/unit/Sparql/cases.php 2007-08-08 13:47:51 UTC (rev 475)
@@ -51,6 +51,8 @@
'ex11.2.3.1_1',
//bound() across union patterns is not possible
'ex11.2.3.2_0',
+ 'query-survey-1',
+ 'query-eq2-1',
);
@@ -73,7 +75,7 @@
15 => "q-select-1" ,
16 => "q-select-2" ,
17 => "q-select-3" ,
-// 18 => "query-survey-1"
+ 18 => "query-survey-1"
);
@@ -110,11 +112,11 @@
6 => array('data' => "data-sort-6.n3",
'query' => "query-sort-6",
'result' => "sort6") ,
-/*
- 7 => array('data' => "data-sort-7.n3",
- 'query' => "query-sort-7",
- 'result' => "sort7") ,
-*/
+//file is missing
+// 7 => array('data' => "data-sort-7.n3",
+// 'query' => "query-sort-7",
+// 'result' => "sort7") ,
+
8 => array('data' => "data-sort-8.n3",
'query' => "query-sort-4",
'result' => "sort8") ,
@@ -321,13 +323,13 @@
'query' => "query-eq-5",
'result' => "query-eq-5") ,
- //(43) => array('data' => "data-eq.n3",
- // 'query' => "query-eq2-1",
- // 'result' => "query-eq2-1") ,
+ 43 => array('data' => "data-eq.n3",
+ 'query' => "query-eq2-1",
+ 'result' => "query-eq2-1") ,
- //(44) => array('data' => "data-eq.n3",
- // 'query' => "query-eq2-1",
- // 'result' => "query-eq2-1") ,
+ 44 => array('data' => "data-eq.n3",
+ 'query' => "query-eq2-1",
+ 'result' => "query-eq2-1") ,
/**/
@@ -537,9 +539,9 @@
'result' => "test-4-05") ,
//ARQ fails
- //(47) => array('data' => "model3.nt",
- // 'query' => "test-4-06",
- // 'result' => "test-4-06") ,
+ (47) => array('data' => "model3.nt",
+ 'query' => "test-4-06",
+ 'result' => "test-4-06") ,
(48) => array('data' => "model3.nt",
'query' => "test-4-07",
@@ -643,28 +645,28 @@
'result' => "test-B-13") ,
// FAILS because 5==true
- //(73) => array('data' => "model9.n3",
- // 'query' => "test-B-15",
- // 'result' => "test-B-15") ,
+ (73) => array('data' => "model9.n3",
+ 'query' => "test-B-15",
+ 'result' => "test-B-15") ,
// FAILS because of type error
- //(74) => array('data' => "model9.n3",
- // 'query' => "test-B-17",
- // 'result' => "test-B-17") ,
+ (74) => array('data' => "model9.n3",
+ 'query' => "test-B-17",
+ 'result' => "test-B-17") ,
// FAILS because of type error
- //(75) => array('data' => "model9.n3",
- // 'query' => "test-B-18",
- // 'result' => "test-B-18") ,
+ (75) => array('data' => "model9.n3",
+ 'query' => "test-B-18",
+ 'result' => "test-B-18") ,
(76) => array('data' => "model9.n3",
'query' => "test-B-19",
'result' => "test-B-19") ,
// FAILS because of type error
- //(77) => array('data' => "model9.n3",
- // 'query' => "test-B-20",
- // 'result' => "test-B-20") ,
+ (77) => array('data' => "model9.n3",
+ 'query' => "test-B-20",
+ 'result' => "test-B-20") ,
);
Modified: trunk/rdfapi-php/test/unit/Sparql/result/test-B-18.res
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/result/test-B-18.res 2007-08-08 12:56:38 UTC (rev 474)
+++ trunk/rdfapi-php/test/unit/Sparql/result/test-B-18.res 2007-08-08 13:47:51 UTC (rev 475)
@@ -24,9 +24,10 @@
$res10 = new Resource("http://rdf.hp.com/p1");
-$arr["?v"] =$res1;
-$arr["?y"] =$res3;
-$arr["?x"] =$res2;
+$arr = array();
+$arr["?v"] = $res1;
+$arr["?y"] = $res3;
+$arr["?x"] = $res2;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-08-08 12:56:41
|
Revision: 474
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=474&view=rev
Author: cweiske
Date: 2007-08-08 05:56:38 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
really fix it
Modified Paths:
--------------
trunk/rdfapi-php/test/unit/Sparql/result/test-B-17.res
Modified: trunk/rdfapi-php/test/unit/Sparql/result/test-B-17.res
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/result/test-B-17.res 2007-08-08 12:51:37 UTC (rev 473)
+++ trunk/rdfapi-php/test/unit/Sparql/result/test-B-17.res 2007-08-08 12:56:38 UTC (rev 474)
@@ -33,7 +33,7 @@
-$result["rowcount"]=3;
+$result["rowcount"]=1;
$result["hits"]=1;
$result["part"][]=$arr;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-08-08 12:51:40
|
Revision: 473
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=473&view=rev
Author: cweiske
Date: 2007-08-08 05:51:37 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
fix result array initialization
Modified Paths:
--------------
trunk/rdfapi-php/test/unit/Sparql/result/test-B-17.res
Modified: trunk/rdfapi-php/test/unit/Sparql/result/test-B-17.res
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/result/test-B-17.res 2007-08-02 21:19:57 UTC (rev 472)
+++ trunk/rdfapi-php/test/unit/Sparql/result/test-B-17.res 2007-08-08 12:51:37 UTC (rev 473)
@@ -24,8 +24,9 @@
$res10 = new Resource("http://rdf.hp.com/p1");
-$arr["?y"] =$res3;
-$arr["?x"] =$res2;
+$arr = array();
+$arr["?x"] = $res2;
+$arr["?y"] = $res3;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-08-02 21:20:05
|
Revision: 472
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=472&view=rev
Author: cweiske
Date: 2007-08-02 14:19:57 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Fix table id for complicated union queries
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-07-16 12:32:24 UTC (rev 471)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-08-02 21:19:57 UTC (rev 472)
@@ -184,6 +184,7 @@
}
if ($graphPattern->getUnion() !== null) {
++$this->nUnionCount;
+ $this->nTableId = 0;
$this->nUnionTriplePatternCount = 0;
$this->nGraphPatternCount = 0;
$this->arUnionVarAssignments[$this->nUnionCount] = array();
@@ -298,7 +299,10 @@
$arSelect = array();
$strFrom = null;
$strWhere = null;
- $strWhereEquality = '';
+ $strWhereEquality = '';
+ $bWhereEqualitySubject = false;
+ $bWhereEqualityPredicate = false;
+ $bWhereEqualityObject = false;
$subject = $triple->getSubject();
$predicate = $triple->getPredicate();
@@ -314,10 +318,7 @@
if (SparqlVariable::isVariable($subject)) {
if (isset($this->arUnionVarAssignments[$this->nUnionCount][$subject])) {
//already selected -> add equality check
- $strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
- array($strTablePrefix, 's'),
- $this->arVarAssignments[$subject]
- );
+ $bWhereEqualitySubject = true;
$this->arUsedVarTypes[$subject]['s'] = true;
} else {
if (isset($this->arVarAssignments[$subject][0])) {
@@ -343,10 +344,7 @@
if (SparqlVariable::isVariable($predicate)) {
if (isset($this->arUnionVarAssignments[$this->nUnionCount][$predicate])) {
//already selected -> add equality check
- $strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
- array($strTablePrefix, 'p'),
- $this->arVarAssignments[$predicate]
- );
+ $bWhereEqualityPredicate = true;
$this->arUsedVarTypes[$predicate]['p'] = true;
} else {
if (isset($this->arVarAssignments[$predicate][0])) {
@@ -371,10 +369,7 @@
if (SparqlVariable::isVariable($object)) {
if (isset($this->arUnionVarAssignments[$this->nUnionCount][$object])) {
//already selected -> add equality check
- $strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
- array($strTablePrefix, 'o'),
- $this->arVarAssignments[$object]
- );
+ $bWhereEqualityObject = true;
$this->arUsedVarTypes[$object]['o'] = true;
} else {
if (isset($this->arVarAssignments[$object][0])) {
@@ -411,6 +406,29 @@
}
/**
+ * WhereEquality - needs to be done now because strTablePrefix may change
+ */
+ if ($bWhereEqualitySubject) {
+ $strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
+ array($strTablePrefix, 's'),
+ $this->arVarAssignments[$subject]
+ );
+ }
+ if ($bWhereEqualityPredicate) {
+ $strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
+ array($strTablePrefix, 'p'),
+ $this->arVarAssignments[$predicate]
+ );
+ }
+ if ($bWhereEqualityObject) {
+ $strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
+ array($strTablePrefix, 'o'),
+ $this->arVarAssignments[$object]
+ );
+ }
+
+
+ /**
* FROM part
*/
if ($this->nUnionTriplePatternCount == 0) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-07-16 12:32:25
|
Revision: 471
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=471&view=rev
Author: cweiske
Date: 2007-07-16 05:32:24 -0700 (Mon, 16 Jul 2007)
Log Message:
-----------
Allow changing the statements't table name in sparqlenginedb by setting
$GLOBALS['RAP']['conf']['database']['tblStatements']
(required for ACL)
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-07-16 12:31:20 UTC (rev 470)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-07-16 12:32:24 UTC (rev 471)
@@ -129,8 +129,13 @@
protected $nSqlVariableNameCount = 0;
+ /**
+ * Name of the statements table
+ */
+ protected $tblStatements = 'statements';
+
public function __construct(Query $query, ADOConnection $dbConn, $arModelIds)
{
$this->query = $query;
@@ -410,21 +415,21 @@
*/
if ($this->nUnionTriplePatternCount == 0) {
//first FROM
- $strFrom = 'statements as ' . $strTablePrefix;
+ $strFrom = $this->tblStatements . ' as ' . $strTablePrefix;
} else {
//normal join
if (count($this->arModelIds) == 1) {
- $strFrom = 'LEFT JOIN statements as ' . $strTablePrefix
+ $strFrom = 'LEFT JOIN ' . $this->tblStatements . ' as ' . $strTablePrefix
. ' ON t0.modelID = ' . $strTablePrefix . '.modelID';
} else if (count($this->arModelIds) > 1) {
$arIDs = array();
foreach ($this->arModelIds as $nId) {
$arIDs[] = $strTablePrefix . '.modelID = ' . intval($nId);
}
- $strFrom = 'LEFT JOIN statements as ' . $strTablePrefix
+ $strFrom = 'LEFT JOIN ' . $this->tblStatements . ' as ' . $strTablePrefix
. ' ON (' . implode(' OR ', $arIDs) . ')';
} else {
- $strFrom = 'LEFT JOIN statements as ' . $strTablePrefix
+ $strFrom = 'LEFT JOIN ' . $this->tblStatements . ' as ' . $strTablePrefix
. ' ON t0.modelID = ' . $strTablePrefix . '.modelID';
}
@@ -965,5 +970,12 @@
return $this->arVarAssignments[$strSparqlVar]['sql_type'];
}//protected function getSqlVariableNameDatatype($var)
+
+
+ public function setStatementsTable($tblStatements)
+ {
+ $this->tblStatements = $tblStatements;
+ }//public function setStatementsTable($tblStatements)
+
}//class SparqlEngineDb_SqlGenerator
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-07-16 12:31:20 UTC (rev 470)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-07-16 12:32:24 UTC (rev 471)
@@ -122,6 +122,7 @@
$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()){
$vartable[0]['patternResult'] = null;
@@ -336,6 +337,21 @@
+ /**
+ * Set options to subobjects like SqlGenerator
+ */
+ protected function setOptions()
+ {
+ //allow changing the statements' table name
+ if (isset($GLOBALS['RAP']['conf']['database']['tblStatements'])) {
+ $this->sg->setStatementsTable(
+ $GLOBALS['RAP']['conf']['database']['tblStatements']
+ );
+ }
+ }//protected function setOptions()
+
+
+
/*
* Dumb getters
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-07-16 12:31:22
|
Revision: 470
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=470&view=rev
Author: cweiske
Date: 2007-07-16 05:31:20 -0700 (Mon, 16 Jul 2007)
Log Message:
-----------
Throw exception on error
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/SparqlEngineDb/TypeSorter.php
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/TypeSorter.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/TypeSorter.php 2007-07-16 10:10:44 UTC (rev 469)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/TypeSorter.php 2007-07-16 12:31:20 UTC (rev 470)
@@ -221,12 +221,17 @@
. ' as "' . $strSparqlVar . '-type"';
}
- $oldmode = $this->dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
- $arResult = $this->dbConn->execute(
- 'SELECT DISTINCT ' . implode(', ', $arSel) . ' ' . $strFrom . $strWhere
- );
+ $oldmode = $this->dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
+ $sql = 'SELECT DISTINCT ' . implode(', ', $arSel) . ' ' . $strFrom . $strWhere;
+ $arResult = $this->dbConn->execute($sql);
$this->dbConn->SetFetchMode($oldmode);
+ if ($arResult === false) {
+ throw new SparqlEngineDb_SqlGeneratorException(
+ 'Error reading typesets: ' . $sql
+ );
+ }
+
$arTypes = array();
foreach ($arResult as $arRow) {
$nLine = count($arTypes);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-07-16 10:10:45
|
Revision: 469
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=469&view=rev
Author: cweiske
Date: 2007-07-16 03:10:44 -0700 (Mon, 16 Jul 2007)
Log Message:
-----------
Fix sql generation on infinite number of models
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-07-05 13:23:35 UTC (rev 468)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-07-16 10:10:44 UTC (rev 469)
@@ -424,7 +424,8 @@
$strFrom = 'LEFT JOIN statements as ' . $strTablePrefix
. ' ON (' . implode(' OR ', $arIDs) . ')';
} else {
- $strFrom = 'LEFT JOIN statements as ' . $strTablePrefix;
+ $strFrom = 'LEFT JOIN statements as ' . $strTablePrefix
+ . ' ON t0.modelID = ' . $strTablePrefix . '.modelID';
}
foreach ($arRefVars as $strRefVar => $strSqlVar) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-07-05 13:23:37
|
Revision: 468
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=468&view=rev
Author: cweiske
Date: 2007-07-05 06:23:35 -0700 (Thu, 05 Jul 2007)
Log Message:
-----------
Don't crash if query is incomplete
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/Query.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/Query.php
===================================================================
--- trunk/rdfapi-php/api/sparql/Query.php 2007-07-04 12:09:55 UTC (rev 467)
+++ trunk/rdfapi-php/api/sparql/Query.php 2007-07-05 13:23:35 UTC (rev 468)
@@ -55,7 +55,7 @@
* @var string
* @see http://www.w3.org/TR/rdf-sparql-query/#QueryForms
*/
- protected $resultForm;
+ protected $resultForm = null;
/**
* Contains the result part of the SPARQL query.
@@ -63,7 +63,7 @@
*
* @var array
*/
- protected $resultPart;
+ protected $resultPart = array();
/**
* Contains the FROM part of the SPARQL query.
@@ -98,7 +98,7 @@
*
* @var int
*/
- protected $bnodeCounter;
+ protected $bnodeCounter = 0;
/**
* GraphPattern counter.
@@ -106,7 +106,7 @@
*
* @var int
*/
- public $graphPatternCounter;
+ public $graphPatternCounter = 0;
/**
* List of all vars used in the query.
@@ -115,20 +115,20 @@
*
* @var array
*/
- public $usedVars;
+ public $usedVars = array();
/**
* If the query type is CONSTRUCT this variable contains the
* CONSTRUCT graph pattern.
*/
- protected $constructPattern;
+ protected $constructPattern = null;
/**
* TRUE if the query is empty FALSE if not.
*
* @var boolean
*/
- public $isEmpty;
+ public $isEmpty = null;
/**
* Language of variables. NULL if the variable has no
@@ -152,7 +152,7 @@
* Constructor
*/
public function Query(){
- $this->resultForm = false;
+ $this->resultForm = null;
$this->solutionModifier['order by'] = null;
$this->solutionModifier['limit'] = null;
$this->solutionModifier['offset'] = null;
@@ -537,6 +537,24 @@
return false;
}
+
+
+ /**
+ * Checks if the query is complete
+ * (so that querying is possible)
+ *
+ * @return boolean true if the query is complete
+ */
+ public function isComplete()
+ {
+ if ($this->resultForm === null) {
+ return false;
+ }
+ //TODO: maybe check selected vars and construct pattern depending
+ // on the resultform
+ return true;
+ }//public function isIncomplete()
+
}// end class: Query.php
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-07-04 12:09:55 UTC (rev 467)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-07-05 13:23:35 UTC (rev 468)
@@ -32,7 +32,7 @@
* The Querystring
* @var string
*/
- protected $querystring;
+ protected $queryString;
/**
* The tokenized Query
@@ -109,6 +109,13 @@
$this->tokenize($uncommentedQuery);
$this->querystring = $uncommentedQuery;
$this->parseQuery();
+ if (!$this->query->isComplete()) {
+ throw new SparqlParserException(
+ "Query is incomplete.",
+ null,
+ $queryString
+ );
+ }
} else {
throw new SparqlParserException(
"Querystring is empty.",
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-07-04 12:09:56
|
Revision: 467
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=467&view=rev
Author: cweiske
Date: 2007-07-04 05:09:55 -0700 (Wed, 04 Jul 2007)
Log Message:
-----------
support for variable renaming: SELECT datatype(?o) AS ?dt WHERE ..
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/Query.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/Query.php
===================================================================
--- trunk/rdfapi-php/api/sparql/Query.php 2007-07-04 08:44:01 UTC (rev 466)
+++ trunk/rdfapi-php/api/sparql/Query.php 2007-07-04 12:09:55 UTC (rev 467)
@@ -185,7 +185,7 @@
*/
public function getResultVar($strName) {
foreach ($this->resultVars as $var) {
- if ((string)$var == $strName) {
+ if ($var->getVariable() == $strName) {
return $var;
}
}
@@ -546,7 +546,7 @@
public $variable = null;
public $datatype = null;
public $language = null;
- public $newname = null;
+ public $alias = null;
public $func = null;
@@ -558,9 +558,9 @@
- public function setNewName($as)
+ public function setAlias($alias)
{
- $this->newname = $as;
+ $this->alias = $alias;
}
@@ -610,10 +610,10 @@
public function getName()
{
- if ($this->newname !== null) {
- return $this->newname;
+ if ($this->alias !== null) {
+ return $this->alias;
}
- //FIXME: support for nested(functios())
+ //FIXME: support for nested(functions())
return $this->variable;
}
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-07-04 08:44:01 UTC (rev 466)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-07-04 12:09:55 UTC (rev 467)
@@ -474,6 +474,11 @@
{
$var = $this->query->getResultVar($varname);
if ($var !== false) {
+ if ((string)$var != $varname) {
+ //copy over var assignments
+ $this->arVarAssignments[(string)$var] = $this->arVarAssignments[$varname];
+ }
+
//works on non-* only
$func = $var->getFunc();
if ($func != null) {
@@ -484,10 +489,10 @@
);
}
return array(
- $strTablePrefix . '.l_datatype as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($varname) . '"',
- '"r"' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($varname) . '"',
- '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameLanguage($varname) . '"',
- '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameDatatype($varname) . '"',
+ $strTablePrefix . '.l_datatype as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($var) . '"',
+ '"r"' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($var) . '"',
+ '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameLanguage($var) . '"',
+ '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameDatatype($var) . '"',
);
} else if ($func == 'lang') {
if ($chType != 'o') {
@@ -496,10 +501,10 @@
);
}
return array(
- $strTablePrefix . '.l_language as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($varname) . '"',
- '"l"' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($varname) . '"',
- '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameLanguage($varname) . '"',
- '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameDatatype($varname) . '"',
+ $strTablePrefix . '.l_language as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($var) . '"',
+ '"l"' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($var) . '"',
+ '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameLanguage($var) . '"',
+ '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameDatatype($var) . '"',
);
} else {
throw new SparqlEngineDb_SqlGeneratorException(
@@ -795,7 +800,15 @@
*/
protected static function isResultVar($strVar, &$arResultVars)
{
- return in_array('*', $arResultVars) || in_array($strVar, $arResultVars);
+ foreach ($arResultVars as $var) {
+ if ($var == '*') {
+ return true;
+ } else if ((is_string($var) && $var == $strVar)
+ || (is_object($var) && $var->getVariable() == $strVar)) {
+ return true;
+ }
+ }
+ return false;
}//protected static function isResultVar($strVar, &$arResultVars)
@@ -897,8 +910,9 @@
- protected function getSqlVariableName($strSparqlVar)
+ protected function getSqlVariableName($var)
{
+ $strSparqlVar = (string)$var;
if (!isset($this->arVarAssignments[$strSparqlVar]['sqlname'])) {
if (preg_match('/[a-zA-Z0-9]+/', substr($strSparqlVar, 1))) {
$strName = 'v_' . substr($strSparqlVar, 1);
@@ -908,43 +922,47 @@
$this->arVarAssignments[$strSparqlVar]['sqlname'] = $strName;
}
return $this->arVarAssignments[$strSparqlVar]['sqlname'];
- }//protected function getSqlVariableName($strSparqlVar)
+ }//protected function getSqlVariableName($var)
- protected function getSqlVariableNameValue($strSparqlVar)
+ protected function getSqlVariableNameValue($var)
{
+ $strSparqlVar = (string)$var;
$this->arVarAssignments[$strSparqlVar]['sql_value'] =
- 'value_' . $this->getSqlVariableName($strSparqlVar);
+ 'value_' . $this->getSqlVariableName($var);
return $this->arVarAssignments[$strSparqlVar]['sql_value'];
- }//protected function getSqlVariableNameValue($strSparqlVar)
+ }//protected function getSqlVariableNameValue($var)
- protected function getSqlVariableNameIs($strSparqlVar)
+ protected function getSqlVariableNameIs($var)
{
+ $strSparqlVar = (string)$var;
$this->arVarAssignments[$strSparqlVar]['sql_is'] =
- 'is_' . $this->getSqlVariableName($strSparqlVar);
+ 'is_' . $this->getSqlVariableName($var);
return $this->arVarAssignments[$strSparqlVar]['sql_is'];
- }//protected function getSqlVariableNameIs($strSparqlVar)
+ }//protected function getSqlVariableNameIs($var)
- protected function getSqlVariableNameLanguage($strSparqlVar)
+ protected function getSqlVariableNameLanguage($var)
{
+ $strSparqlVar = (string)$var;
$this->arVarAssignments[$strSparqlVar]['sql_lang'] =
- 'lang_' . $this->getSqlVariableName($strSparqlVar);
+ 'lang_' . $this->getSqlVariableName($var);
return $this->arVarAssignments[$strSparqlVar]['sql_lang'];
- }//protected function getSqlVariableNameLanguage($strSparqlVar)
+ }//protected function getSqlVariableNameLanguage($var)
- protected function getSqlVariableNameDatatype($strSparqlVar)
+ protected function getSqlVariableNameDatatype($var)
{
+ $strSparqlVar = (string)$var;
$this->arVarAssignments[$strSparqlVar]['sql_type'] =
- 'type_' . $this->getSqlVariableName($strSparqlVar);
+ 'type_' . $this->getSqlVariableName($var);
return $this->arVarAssignments[$strSparqlVar]['sql_type'];
- }//protected function getSqlVariableNameDatatype($strSparqlVar)
+ }//protected function getSqlVariableNameDatatype($var)
}//class SparqlEngineDb_SqlGenerator
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-07-04 08:44:01 UTC (rev 466)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-07-04 12:09:55 UTC (rev 467)
@@ -311,7 +311,7 @@
// I want associative arrays.
$oldmode = $this->dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
-var_dump($strSql);
+//var_dump($strSql);
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-07-04 08:44:01 UTC (rev 466)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-07-04 12:09:55 UTC (rev 467)
@@ -314,7 +314,7 @@
if ($this->varCheck($curTok) || $curLow == '*') {
if ($bWaitForRenaming) {
$bWaitForRenaming = false;
- $currentVar->setNewName($curTok);
+ $currentVar->setAlias($curTok);
if ($currentFunc != null) {
$currentVar->setFunc($currentFunc);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-07-04 08:44:03
|
Revision: 466
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=466&view=rev
Author: cweiske
Date: 2007-07-04 01:44:01 -0700 (Wed, 04 Jul 2007)
Log Message:
-----------
Add support for selecting lang() and datatype()
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/Query.php
trunk/rdfapi-php/api/sparql/SparqlEngine.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/HTML.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/XML.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/Query.php
===================================================================
--- trunk/rdfapi-php/api/sparql/Query.php 2007-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/Query.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -178,6 +178,19 @@
public function getPrefixes(){
return $this->prefixes;
}
+ /**
+ * Returns a list containing the result vars.
+ *
+ * @return Array
+ */
+ public function getResultVar($strName) {
+ foreach ($this->resultVars as $var) {
+ if ((string)$var == $strName) {
+ return $var;
+ }
+ }
+ return false;
+ }
/**
* Returns a list containing the result vars.
@@ -274,9 +287,11 @@
* @return void
*/
public function addResultVar($var){
- $this->resultVars[]= $var;
- $this->varLanguages[$var] = self::getLanguageTag($var);
- $this->varDatatypes[$var] = $this->getDatatype($var);
+ $this->resultVars[] = $var;
+ $var->setDatatype($this->getDatatype($var));
+
+ $this->varLanguages[$var->getId()] = self::getLanguageTag($var);
+ $this->varDatatypes[$var->getId()] = $this->getDatatype($var);
}
@@ -522,7 +537,99 @@
return false;
}
-}
-// end class: Query.php
+}// end class: Query.php
+
+
+class Query_ResultVariable
+{
+ public $variable = null;
+ public $datatype = null;
+ public $language = null;
+ public $newname = null;
+ public $func = null;
+
+
+ public function __construct($variable)
+ {
+ $this->variable = $variable;
+ $this->language = Query::getLanguageTag($variable);
+ }
+
+
+
+ public function setNewName($as)
+ {
+ $this->newname = $as;
+ }
+
+
+
+ public function setFunc($func)
+ {
+ $this->func = $func;
+ }
+
+
+
+ public function setDatatype($datatype)
+ {
+ $this->datatype = $datatype;
+ }
+
+
+
+ public function getId()
+ {
+ //FIXME
+ return $this->variable;
+ }
+
+
+
+ public function getFunc()
+ {
+ return $this->func;
+ }
+
+
+
+ public function getLanguage()
+ {
+ return $this->language;
+ }
+
+
+
+ public function getDatatype()
+ {
+ return $this->datatype;
+ }
+
+
+
+ public function getName()
+ {
+ if ($this->newname !== null) {
+ return $this->newname;
+ }
+ //FIXME: support for nested(functios())
+ return $this->variable;
+ }
+
+
+
+ public function getVariable()
+ {
+ return $this->variable;
+ }
+
+
+
+ public function __toString()
+ {
+ return $this->getName();
+ }
+}//class Query_ResultVariable
+
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine.php 2007-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -599,10 +599,10 @@
$hits = 0;
foreach($table as $val){
foreach($vars as $var){
- if(isset($val[$var])){
- $resTable[$hits][$var]=$val[$var];
+ if(isset($val[(string)$var])){
+ $resTable[$hits][(string)$var]=$val[(string)$var];
}else{
- $resTable[$hits][$var]="";
+ $resTable[$hits][(string)$var]="";
}
}
$hits++;
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php 2007-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -146,14 +146,15 @@
foreach ($dbRecordSet as $row) {
$arResultRow = array();
- foreach ($arResultVars as $strVarName) {
+ foreach ($arResultVars as $strVar) {
+ $strVarName = (string)$strVar;
if (!isset($this->sg->arVarAssignments[$strVarName])) {
//variable is in select, but not in result (test: q-select-2)
$arResultRow[$strVarName] = '';
} else {
$arVarSettings = $this->sg->arVarAssignments[$strVarName];
$strMethod = $this->arCreationMethods[$arVarSettings[1]];
- $arResultRow[$strVarName] = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVarName);
+ $arResultRow[$strVarName] = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVar);
}
}
$arResult[] = $arResultRow;
@@ -196,8 +197,9 @@
*
* @return Resource RDF triple subject resource object
*/
- protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
//FIXME: should be NULL, but doesn't pass test
return '';
@@ -227,8 +229,9 @@
*
* @return Resource RDF triple predicate resource object
*/
- protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
//FIXME: should be NULL, but doesn't pass test
return '';
@@ -250,8 +253,9 @@
*
* @return Resource RDF triple object resource object
*/
- protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
//FIXME: should be NULL, but doesn't pass test
return '';
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/HTML.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/HTML.php 2007-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/HTML.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -127,14 +127,15 @@
foreach ($dbRecordSet as $row) {
$arResultRow = array();
- foreach ($arResultVars as $strVarName) {
+ foreach ($arResultVars as $strVar) {
+ $strVarName = (string)$strVar;
if (!isset($this->sg->arVarAssignments[$strVarName])) {
//variable is in select, but not in result (test: q-select-2)
$arResultRow[$strVarName] = '';
} else {
$arVarSettings = $this->sg->arVarAssignments[$strVarName];
$strMethod = $this->arCreationMethods[$arVarSettings[1]];
- list($strCode, $strColor) = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVarName);
+ list($strCode, $strColor) = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVar);
$arResultRow[$strVarName] = '<td style="background-color: '
. $strColor . '">' . $strCode . '</td>';
}
@@ -178,8 +179,9 @@
*
* @return string HTML code
*/
- protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
return $this->getHtmlNull();
}
@@ -191,7 +193,7 @@
} else {
return $this->getHtmlBlank($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
}
- }//protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
@@ -206,14 +208,15 @@
*
* @return string HTML code
*/
- protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
return $this->getHtmlNull();
}
return $this->getHtmlResource($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
- }//protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
@@ -228,8 +231,9 @@
*
* @return string HTML code
*/
- protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
return $this->getHtmlNull();
}
@@ -247,7 +251,7 @@
$dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_type']]
);
}
- }//protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php 2007-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -146,14 +146,15 @@
foreach ($dbRecordSet as $row) {
$arResultRow = array();
- foreach ($arResultVars as $strVarName) {
+ foreach ($arResultVars as $strVar) {
+ $strVarName = (string)$strVar;
if (!isset($this->sg->arVarAssignments[$strVarName])) {
//variable is in select, but not in result (test: q-select-2)
$arResultRow[$strVarName] = '';
} else {
$arVarSettings = $this->sg->arVarAssignments[$strVarName];
$strMethod = $this->arCreationMethods[$arVarSettings[1]];
- $arResultRow[$strVarName] = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVarName);
+ $arResultRow[$strVarName] = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVar);
}
}
$arResult[] = $arResultRow;
@@ -196,8 +197,9 @@
*
* @return Resource RDF triple subject resource object
*/
- protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
//FIXME: should be NULL, but doesn't pass test
return '';
@@ -212,7 +214,7 @@
return $this->createBlankNode($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
}
return $subject;
- }//protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
@@ -227,14 +229,15 @@
*
* @return Resource RDF triple predicate resource object
*/
- protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
//FIXME: should be NULL, but doesn't pass test
return '';
}
return $this->createResource($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
- }//protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
@@ -249,8 +252,9 @@
*
* @return Resource RDF triple object resource object
*/
- protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
//FIXME: should be NULL, but doesn't pass test
return '';
@@ -269,7 +273,7 @@
$dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_type']]
);
}
- }//protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/XML.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/XML.php 2007-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/XML.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -146,14 +146,15 @@
foreach ($dbRecordSet as $row) {
$arResultRow = array();
- foreach ($arResultVars as $strVarName) {
+ foreach ($arResultVars as $strVar) {
+ $strVarName = (string)$strVar;
if (!isset($this->sg->arVarAssignments[$strVarName])) {
//variable is in select, but not in result (test: q-select-2)
$arResultRow[$strVarName] = '';
} else {
$arVarSettings = $this->sg->arVarAssignments[$strVarName];
$strMethod = $this->arCreationMethods[$arVarSettings[1]];
- $arResultRow[$strVarName] = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVarName);
+ $arResultRow[$strVarName] = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVar);
}
}
$arResult[] = $arResultRow;
@@ -213,8 +214,9 @@
*
* @return string HTML code
*/
- protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
return $this->getXmlNull();
}
@@ -226,7 +228,7 @@
} else {
return $this->getXmlBlank($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
}
- }//protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
@@ -241,14 +243,15 @@
*
* @return string HTML code
*/
- protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
return $this->getXmlNull();
}
return $this->getXmlResource($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
- }//protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
@@ -263,8 +266,9 @@
*
* @return string HTML code
*/
- protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
{
+ $strVarName = (string)$strVar;
if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
return $this->getXmlNull();
}
@@ -282,7 +286,7 @@
$dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_type']]
);
}
- }//protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ }//protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVar)
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -323,9 +323,8 @@
$this->arUsedVarTypes[$subject]['s'] = true;
if (self::isResultVar($subject, $arResultVars)) {
//new variable that needs to be selected
- $arSelect[$subject] = array(
- $strTablePrefix . '.subject as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($subject) . '"',
- $strTablePrefix . '.subject_is as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($subject) . '"'
+ $arSelect[$subject] = $this->createVariableSelectArray(
+ 's', $subject, $strTablePrefix
);
if (isset($this->arUsedVarAssignments[$subject])) {
$arRefVars[$subject] = $strTablePrefix . '.subject';
@@ -352,8 +351,8 @@
$this->arUnionVarAssignments[$this->nUnionCount][$predicate] = array($strTablePrefix, 'p');
$this->arUsedVarTypes[$predicate]['p'] = true;
if (self::isResultVar($predicate, $arResultVars)) {
- $arSelect[$predicate] = array(
- $strTablePrefix . '.predicate as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($predicate) . '"'
+ $arSelect[$predicate] = $this->createVariableSelectArray(
+ 'p', $predicate, $strTablePrefix
);
if (isset($this->arUsedVarAssignments[$predicate])) {
$arRefVars[$predicate] = $strTablePrefix . '.predicate';
@@ -380,11 +379,8 @@
$this->arUnionVarAssignments[$this->nUnionCount][$object] = array($strTablePrefix, 'o');
$this->arUsedVarTypes[$object]['o'] = true;
if (self::isResultVar($object, $arResultVars)) {
- $arSelect[$object] = array(
- $strTablePrefix . '.object as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($object) . '"',
- $strTablePrefix . '.object_is as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($object) . '"',
- $strTablePrefix . '.l_language as "' . $strTablePrefix . '.' . $this->getSqlVariableNameLanguage($object) . '"',
- $strTablePrefix . '.l_datatype as "' . $strTablePrefix . '.' . $this->getSqlVariableNameDatatype($object) . '"',
+ $arSelect[$object] = $this->createVariableSelectArray(
+ 'o', $object, $strTablePrefix
);
if (isset($this->arUsedVarAssignments[$object])) {
$arRefVars[$object] = $strTablePrefix . '.object';
@@ -473,6 +469,72 @@
+
+ protected function createVariableSelectArray($chType, $varname, $strTablePrefix)
+ {
+ $var = $this->query->getResultVar($varname);
+ if ($var !== false) {
+ //works on non-* only
+ $func = $var->getFunc();
+ if ($func != null) {
+ if ($func == 'datatype') {
+ if ($chType != 'o') {
+ throw new SparqlEngineDb_SqlGeneratorException(
+ 'datatype() works on objects only'
+ );
+ }
+ return array(
+ $strTablePrefix . '.l_datatype as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($varname) . '"',
+ '"r"' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($varname) . '"',
+ '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameLanguage($varname) . '"',
+ '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameDatatype($varname) . '"',
+ );
+ } else if ($func == 'lang') {
+ if ($chType != 'o') {
+ throw new SparqlEngineDb_SqlGeneratorException(
+ 'lang() works on objects only'
+ );
+ }
+ return array(
+ $strTablePrefix . '.l_language as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($varname) . '"',
+ '"l"' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($varname) . '"',
+ '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameLanguage($varname) . '"',
+ '""' . ' as "' . $strTablePrefix . '.' . $this->getSqlVariableNameDatatype($varname) . '"',
+ );
+ } else {
+ throw new SparqlEngineDb_SqlGeneratorException(
+ 'Unsupported function for select "' . $func . '"'
+ );
+ }
+ }
+ }
+
+ switch ($chType) {
+ case 's':
+ return array(
+ $strTablePrefix . '.subject as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($varname) . '"',
+ $strTablePrefix . '.subject_is as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($varname) . '"'
+ );
+ case 'p':
+ return array(
+ $strTablePrefix . '.predicate as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($varname) . '"'
+ );
+ case 'o':
+ return array(
+ $strTablePrefix . '.object as "' . $strTablePrefix . '.' . $this->getSqlVariableNameValue($varname) . '"',
+ $strTablePrefix . '.object_is as "' . $strTablePrefix . '.' . $this->getSqlVariableNameIs($varname) . '"',
+ $strTablePrefix . '.l_language as "' . $strTablePrefix . '.' . $this->getSqlVariableNameLanguage($varname) . '"',
+ $strTablePrefix . '.l_datatype as "' . $strTablePrefix . '.' . $this->getSqlVariableNameDatatype($varname) . '"',
+ );
+ default:
+ throw new SparqlEngineDb_SqlGeneratorException(
+ 'Unknown sentence type "' . $chType . "', one of (s,p,o) expected"
+ );
+ }
+ }//protected function createVariableSelectArray($chType, $value, $strTablePrefix)
+
+
+
/**
* Creates SELECT statements that have the same number of columns.
* Needed for UNIONs.
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -311,7 +311,7 @@
// I want associative arrays.
$oldmode = $this->dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
-//var_dump($strSql);
+var_dump($strSql);
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-06-27 16:47:57 UTC (rev 465)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-07-04 08:44:01 UTC (rev 466)
@@ -292,34 +292,56 @@
*/
protected function parseSelect()
{
- while (strtolower(current($this->tokens)) != 'from' &
- strtolower(current($this->tokens)) != 'where' &
- strtolower(current($this->tokens)) != "{"
+ $this->_fastForward();
+ $curLow = strtolower(current($this->tokens));
+ prev($this->tokens);
+ if ($curLow == 'distinct') {
+ $this->query->setResultForm('select distinct');
+ } else {
+ $this->query->setResultForm('select');
+ }
+
+ $currentVar = null;
+ $currentFunc = null;
+ $bWaitForRenaming = false;
+ while ($curLow != 'from' && $curLow != 'where' &&
+ $curLow != "{"
){
$this->_fastForward();
- if ($this->varCheck(current($this->tokens))
- | strtolower(current($this->tokens)) == '*'
- ){
- $this->query->addResultVar(current($this->tokens));
- if (!$this->query->getResultForm()) {
- $this->query->setResultForm('select');
- }
- } else {
- if (strtolower(current($this->tokens))=='distinct') {
- $this->query->setResultForm('select distinct');
- $this->_fastForward();
- if ($this->varCheck(current($this->tokens))
- | strtolower(current($this->tokens))=='*'
- ) {
- $this->query->addResultVar(current($this->tokens));
- } else {
- throw new SparqlParserException(
- "Variable or '*' expected.",
- null,
- key($this->tokens)
- );
+ $curTok = current($this->tokens);
+ $curLow = strtolower($curTok);
+
+ if ($this->varCheck($curTok) || $curLow == '*') {
+ if ($bWaitForRenaming) {
+ $bWaitForRenaming = false;
+ $currentVar->setNewName($curTok);
+ if ($currentFunc != null) {
+ $currentVar->setFunc($currentFunc);
}
+ $this->query->addResultVar($currentVar);
+ $currentVar = null;
+ } else {
+ if ($currentVar != null) {
+ $this->query->addResultVar($currentVar);
+ $currentVar = null;
+ }
+ $currentVar = new Query_ResultVariable($curTok);
+ if ($currentFunc != null) {
+ $currentVar->setFunc($currentFunc);
+ }
}
+ $currentFunc = null;
+ } else if ($curLow == 'as') {
+ if ($currentVar === null) {
+ throw new SparqlParserException(
+ 'AS requires a variable left and right',
+ null,
+ key($this->tokens)
+ );
+ }
+ $bWaitForRenaming = true;
+ } else if (in_array($curLow, self::$sops)) {
+ $currentFunc = $curLow;
}
if (!current($this->tokens)) {
@@ -328,13 +350,24 @@
null,
key($this->tokens)
);
- break;
}
}
+
+ if ($currentVar != null) {
+ $this->query->addResultVar($currentVar);
+ }
prev($this->tokens);
- }
+ if (count($this->query->getResultVars()) == 0) {
+ throw new SparqlParserException(
+ "Variable or '*' expected.",
+ null,
+ key($this->tokens)
+ );
+ }
+ }//protected function parseSelect()
+
/**
* Adds a new variable to the query and sets result form to 'DESCRIBE'.
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-27 16:47:59
|
Revision: 465
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=465&view=rev
Author: cweiske
Date: 2007-06-27 09:47:57 -0700 (Wed, 27 Jun 2007)
Log Message:
-----------
Add LGPL license tag to sparql files
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/ClientQuery.php
trunk/rdfapi-php/api/sparql/Constraint.php
trunk/rdfapi-php/api/sparql/FilterFunctions.php
trunk/rdfapi-php/api/sparql/GraphPattern.php
trunk/rdfapi-php/api/sparql/Query.php
trunk/rdfapi-php/api/sparql/QueryTriple.php
trunk/rdfapi-php/api/sparql/SparqlClient.php
trunk/rdfapi-php/api/sparql/SparqlEngine/PreparedStatement.php
trunk/rdfapi-php/api/sparql/SparqlEngine/ResultConverter.php
trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/Default.php
trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/HTML.php
trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/XML.php
trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer.php
trunk/rdfapi-php/api/sparql/SparqlEngine.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/Offsetter.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/Preparator.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/PreparedStatement.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultConverter.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/HTML.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/XML.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGeneratorException.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlMerger.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/TypeSorter.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
trunk/rdfapi-php/api/sparql/SparqlParserException.php
trunk/rdfapi-php/api/sparql/SparqlVariable.php
Modified: trunk/rdfapi-php/api/sparql/ClientQuery.php
===================================================================
--- trunk/rdfapi-php/api/sparql/ClientQuery.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/ClientQuery.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -8,7 +8,8 @@
* ClientQuery Object to run a SPARQL Query against a SPARQL server.
*
* @version $Id$
-* @author Tobias Gau\xDF <tob...@we...>
+* @author Tobias Gau� <tob...@we...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/Constraint.php
===================================================================
--- trunk/rdfapi-php/api/sparql/Constraint.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/Constraint.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -11,6 +11,7 @@
*
* @author Tobias Gauss <tob...@we...>
* @version $Id$
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/FilterFunctions.php
===================================================================
--- trunk/rdfapi-php/api/sparql/FilterFunctions.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/FilterFunctions.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -6,6 +6,7 @@
* @package sparql
* @author Tobias Gauss <tob...@we...>
* @version $Id$
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
*/
Modified: trunk/rdfapi-php/api/sparql/GraphPattern.php
===================================================================
--- trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -9,6 +9,7 @@
*
* @author Tobias Gauss <tob...@we...>
* @version $Id$
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/Query.php
===================================================================
--- trunk/rdfapi-php/api/sparql/Query.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/Query.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -7,6 +7,7 @@
*
* @author Tobias Gauss <tob...@we...>
* @version $Id$
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/QueryTriple.php
===================================================================
--- trunk/rdfapi-php/api/sparql/QueryTriple.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/QueryTriple.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -9,6 +9,7 @@
*
* @author Tobias Gauss <tob...@we...>
* @version $Id$
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlClient.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlClient.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlClient.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -9,6 +9,7 @@
*
* @version $Id$
* @author Tobias Gauß <tob...@we...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine/PreparedStatement.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine/PreparedStatement.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine/PreparedStatement.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -3,6 +3,7 @@
* A prepared statement that can be execute()d later multiple
* times with different variable values.
*
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
* @package sparql
*/
class SparqlEngine_PreparedStatement
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine/ResultConverter.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine/ResultConverter.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine/ResultConverter.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -6,6 +6,7 @@
* rdf statement triple array
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/Default.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/Default.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/Default.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -6,6 +6,7 @@
*
* @author Tobias Gauß <tob...@we...>
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/HTML.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/HTML.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/HTML.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -7,6 +7,7 @@
*
* @author Tobias Gauß <tob...@we...>
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/XML.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/XML.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/XML.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -6,6 +6,7 @@
*
* @author Tobias Gauß <tob...@we...>
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -7,6 +7,7 @@
* so on.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -12,6 +12,7 @@
*
* @version $Id$
* @author Tobias Gauß <tob...@we...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -5,6 +5,7 @@
* Generates SQL from Sparql FILTER parts
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/Offsetter.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/Offsetter.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/Offsetter.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -5,6 +5,7 @@
* Determines the offset in a row of sql queries.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/Preparator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/Preparator.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/Preparator.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -6,6 +6,7 @@
* Preparing them in the database, replacing
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/PreparedStatement.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/PreparedStatement.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/PreparedStatement.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -6,6 +6,7 @@
* times with different variable values.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -21,6 +21,7 @@
* This class does this.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*/
class SparqlEngineDb_QuerySimplifier
{
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultConverter.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultConverter.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultConverter.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -6,6 +6,7 @@
* rdf statement triple array
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -5,6 +5,7 @@
* Default RAP result renderer.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/HTML.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/HTML.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/HTML.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -5,6 +5,7 @@
* Sparql DB HTML result renderer.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -5,6 +5,7 @@
* Result renderer that creates a text array
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/XML.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/XML.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/XML.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -6,6 +6,7 @@
* http://www.w3.org/TR/rdf-sparql-XMLres/
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -7,6 +7,7 @@
* so on.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -8,6 +8,7 @@
* Creates sql statements from a Query object
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGeneratorException.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGeneratorException.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGeneratorException.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -3,6 +3,7 @@
* Exception when generating the SQL statement
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlMerger.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlMerger.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlMerger.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -4,6 +4,7 @@
* Creates an sql string from an sql array
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/TypeSorter.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/TypeSorter.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/TypeSorter.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -3,6 +3,7 @@
* Sorts database types as the Sparql specs want it.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -13,6 +13,7 @@
* selecting, joining, filtering and ordering results.
*
* @author Christian Weiske <cw...@cw...>
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -15,6 +15,7 @@
* @author Tobias Gauss <tob...@we...>
* @author Christian Weiske <cw...@cw...>
* @version $Id$
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlParserException.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParserException.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlParserException.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -7,6 +7,7 @@
*
* @author Tobias Gauss <tob...@we...>
* @version $Id$
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*
* @package sparql
*/
Modified: trunk/rdfapi-php/api/sparql/SparqlVariable.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlVariable.php 2007-06-27 14:36:09 UTC (rev 464)
+++ trunk/rdfapi-php/api/sparql/SparqlVariable.php 2007-06-27 16:47:57 UTC (rev 465)
@@ -4,6 +4,7 @@
/**
* Object representation of a SPARQL variable.
+* @license http://www.gnu.org/licenses/lgpl.html LGPL
*/
class SparqlVariable extends Object
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-27 14:36:11
|
Revision: 464
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=464&view=rev
Author: cweiske
Date: 2007-06-27 07:36:09 -0700 (Wed, 27 Jun 2007)
Log Message:
-----------
PlainText renderer
Added Paths:
-----------
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php
Added: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php (rev 0)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/PlainText.php 2007-06-27 14:36:09 UTC (rev 464)
@@ -0,0 +1,358 @@
+<?php
+require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/ResultRenderer.php';
+
+/**
+* Result renderer that creates a text array
+*
+* @author Christian Weiske <cw...@cw...>
+*
+* @package sparql
+*/
+class SparqlEngineDb_ResultRenderer_PlainText implements SparqlEngineDb_ResultRenderer
+{
+
+ /**
+ * Defines the methods needed to create the types
+ * in $arVarAssignments.
+ * Key is the type (e.g. "s" for subject), and
+ * value the method's name.
+ *
+ * @see $arVarAssignments
+ *
+ * @var array
+ */
+ protected $arCreationMethods = array(
+ 's' => 'createSubjectFromDbRecordSetPart',
+ 'p' => 'createPredicateFromDbRecordSetPart',
+ 'o' => 'createObjectFromDbRecordSetPart'
+ );
+
+
+
+ /**
+ * Converts the database results into the desired output format
+ * and returns the result.
+ *
+ * @param array $arRecordSets Array of (possibly several) SQL query results.
+ * @param Query $query SPARQL query object
+ * @param SparqlEngineDb $engine Sparql Engine to query the database
+ * @return mixed The result as rendered by the result renderers.
+ */
+ public function convertFromDbResults($arRecordSets, Query $query, SparqlEngineDb $engine)
+ {
+ $this->query = $query;
+ $this->engine = $engine;
+ $this->sg = $engine->getSqlGenerator();
+
+ $strResultForm = $this->query->getResultForm();
+ switch ($strResultForm) {
+ case 'construct':
+ case 'select':
+ case 'select distinct':
+ $arResult = $this->getVariableArrayFromRecordSets($arRecordSets, $strResultForm);
+
+ //some result forms need more modification
+ switch ($strResultForm) {
+ case 'construct';
+ $arResult = $this->constructGraph(
+ $arResult,
+ $this->query->getConstructPattern()
+ );
+ break;
+ case 'describe';
+ $arResult = $this->describeGraph($arResult);
+ break;
+ }
+
+ return $arResult;
+ break;
+
+ case 'count':
+ case 'ask':
+ if (count($arRecordSets) > 1) {
+ throw new Exception(
+ 'More than one result set for a '
+ . $strResultForm . ' query!'
+ );
+ }
+
+ $nCount = 0;
+ $dbRecordSet = reset($arRecordSets);
+ foreach ($dbRecordSet as $row) {
+ $nCount += intval($row['count']);
+ break;
+ }
+
+ if ($strResultForm == 'ask') {
+ return $nCount > 0;
+ } else {
+ return $nCount;
+ }
+ break;
+
+ case 'describe':
+ default:
+ throw new Exception('Unsupported result form: ' . $strResultForm);
+ }
+
+ }//public function convertFromDbResults($arRecordSets, Query $query, SparqlEngineDb $engine)
+
+
+
+
+ protected function getVariableArrayFromRecordSets($arRecordSets, $strResultForm)
+ {
+ $arResult = array();
+ foreach ($arRecordSets as $dbRecordSet) {
+ $arResult = array_merge(
+ $arResult,
+ $this->getVariableArrayFromRecordSet($dbRecordSet, $strResultForm)
+ );
+ }
+ return $arResult;
+ }//protected function getVariableArrayFromRecordSets($arRecordSets, $strResultForm)
+
+
+
+ /**
+ * Converts a ADORecordSet object into an array of "rows" that
+ * are subarrays of variable => value pairs.
+ *
+ * @param ADORecordSet $dbRecordSet Anything ADOConnection::Execute() can return
+ * @return array
+ */
+ protected function getVariableArrayFromRecordSet(ADORecordSet $dbRecordSet, $strResultForm)
+ {
+ $arResult = array();
+ switch ($strResultForm) {
+ case 'construct':
+ $arResultVars = $this->query->getConstructPatternVariables();
+ break;
+ default:
+ $arResultVars = $this->query->getResultVars();
+ break;
+ }
+
+ if (in_array('*', $arResultVars)) {
+ $arResultVars = array_keys($this->sg->arVarAssignments);
+ }
+
+ //work around bug in adodb:
+ // ADORecordSet_empty does not implement php5 iterators
+ if ($dbRecordSet->RowCount() <= 0) {
+ return array();
+ }
+
+ foreach ($dbRecordSet as $row) {
+ $arResultRow = array();
+ foreach ($arResultVars as $strVarName) {
+ if (!isset($this->sg->arVarAssignments[$strVarName])) {
+ //variable is in select, but not in result (test: q-select-2)
+ $arResultRow[$strVarName] = '';
+ } else {
+ $arVarSettings = $this->sg->arVarAssignments[$strVarName];
+ $strMethod = $this->arCreationMethods[$arVarSettings[1]];
+ $arResultRow[$strVarName] = $this->$strMethod($dbRecordSet, $arVarSettings[0], $strVarName);
+ }
+ }
+ $arResult[] = $arResultRow;
+ }
+ return $arResult;
+ }//function getVariableArrayFromRecordSet(ADORecordSet $dbRecordSet)
+
+
+
+ /**
+ * Creates an RDF Statement object for one of the variables
+ * contained in the given $dbRecordSet object.
+ *
+ * @see convertFromDbResult() to understand $strVarBase necessity
+ *
+ * @param ADORecordSet $dbRecordSet Record set returned from ADOConnection::Execute()
+ * @param string $strVarBase Prefix of the columns the recordset fields have.
+ *
+ * @return Statement RDF statement object
+ */
+ protected function createStatementFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase)
+ {
+ return new Statement(
+ $this->createSubjectFromDbRecordSetPart ($dbRecordSet, $strVarBase),
+ $this->createPredicateFromDbRecordSetPart($dbRecordSet, $strVarBase),
+ $this->createObjectFromDbRecordSetPart ($dbRecordSet, $strVarBase)
+ );
+ }//protected function createStatementFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase)
+
+
+
+ /**
+ * Creates an RDF subject object
+ * contained in the given $dbRecordSet object.
+ *
+ * @see convertFromDbResult() to understand $strVarBase necessity
+ *
+ * @param ADORecordSet $dbRecordSet Record set returned from ADOConnection::Execute()
+ * @param string $strVarBase Prefix of the columns the recordset fields have.
+ *
+ * @return Resource RDF triple subject resource object
+ */
+ protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ {
+ if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
+ //FIXME: should be NULL, but doesn't pass test
+ return '';
+ }
+
+ if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_is']] == 'r'
+ //null should be predicate which is always a resource
+ || $dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_is']] === null
+ ) {
+ return $this->createResource($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
+ } else {
+ return $this->createBlankNode($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
+ }
+ return $subject;
+ }//protected function createSubjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+
+
+
+ /**
+ * Creates an RDF predicate object
+ * contained in the given $dbRecordSet object.
+ *
+ * @see convertFromDbResult() to understand $strVarBase necessity
+ *
+ * @param ADORecordSet $dbRecordSet Record set returned from ADOConnection::Execute()
+ * @param string $strVarBase Prefix of the columns the recordset fields have.
+ *
+ * @return Resource RDF triple predicate resource object
+ */
+ protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ {
+ if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
+ //FIXME: should be NULL, but doesn't pass test
+ return '';
+ }
+ return $this->createResource($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
+ }//protected function createPredicateFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+
+
+
+ /**
+ * Creates an RDF object object
+ * contained in the given $dbRecordSet object.
+ *
+ * @see convertFromDbResult() to understand $strVarBase necessity
+ *
+ * @param ADORecordSet $dbRecordSet Record set returned from ADOConnection::Execute()
+ * @param string $strVarBase Prefix of the columns the recordset fields have.
+ *
+ * @return Resource RDF triple object resource object
+ */
+ protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+ {
+ if ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']] === null) {
+ //FIXME: should be NULL, but doesn't pass test
+ return '';
+ }
+ switch ($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_is']]) {
+ case 'r':
+ return $this->createResource($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
+ break;
+ case 'b':
+ return $this->createBlankNode($dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']]);
+ break;
+ default:
+ return $this->createLiteral(
+ $dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_value']],
+ $dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_lang']],
+ $dbRecordSet->fields[$strVarBase . '.' . $this->sg->arVarAssignments[$strVarName]['sql_type']]
+ );
+ }
+ }//protected function createObjectFromDbRecordSetPart(ADORecordSet $dbRecordSet, $strVarBase, $strVarName)
+
+
+
+ /**
+ * Constructs a result graph.
+ *
+ * @param array $arVartable A table containing the result vars and their bindings
+ * @param GraphPattern $constructPattern The CONSTRUCT pattern
+ * @return MemModel The result graph which matches the CONSTRUCT pattern
+ */
+ protected function constructGraph($arVartable, $constructPattern)
+ {
+ $resultGraph = new MemModel();
+
+ if (!$arVartable) {
+ return $resultGraph;
+ }
+
+ $tp = $constructPattern->getTriplePatterns();
+
+ $bnode = 0;
+ foreach ($arVartable as $value) {
+ foreach ($tp as $triple) {
+ $sub = $triple->getSubject();
+ $pred = $triple->getPredicate();
+ $obj = $triple->getObject();
+
+ if (is_string($sub) && $sub{1} == '_') {
+ $sub = new BlankNode("_bN".$bnode);
+ }
+ if (is_string($pred) && $pred{1} == '_') {
+ $pred = new BlankNode("_bN".$bnode);
+ }
+ if (is_string($obj) && $obj{1} == '_') {
+ $obj = new BlankNode("_bN".$bnode);
+ }
+
+
+ if (is_string($sub)) {
+ $sub = $value[$sub];
+ }
+ if (is_string($pred)) {
+ $pred = $value[$pred];
+ }
+ if (is_string($obj)) {
+ $obj = $value[$obj];
+ }
+
+ if ($sub !== "" && $pred !== "" && $obj !== "") {
+ $resultGraph->add(new Statement($sub,$pred,$obj));
+ }
+ }
+ $bnode++;
+ }
+ return $resultGraph;
+ }//protected function constructGraph($arVartable, $constructPattern)
+
+
+
+ protected function createResource($uri)
+ {
+ return 'R<' . $uri . '>';
+ }//protected function createResource($uri)
+
+
+
+ protected function createBlankNode($id)
+ {
+ return 'B(' . $id . ')';
+ }//protected function createBlankNode($id)
+
+
+
+ protected function createLiteral($value, $language, $datatype)
+ {
+ $v = 'L(' . $value;
+ if ($language != null) {
+ $v .= '@' . $language;
+ }
+ if ($datatype != null) {
+ $v .= '^^' . $datatype;
+ }
+ return $v . ')';
+ }//protected function createLiteral($value, $language, $datatype)
+
+}//class SparqlEngineDb_ResultRenderer_PlainText implements SparqlEngineDb_ResultRenderer
+?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-21 15:52:57
|
Revision: 463
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=463&view=rev
Author: cweiske
Date: 2007-06-21 08:52:53 -0700 (Thu, 21 Jun 2007)
Log Message:
-----------
Some Sparql parser tests for nested queries and the querysimplifier
Modified Paths:
--------------
trunk/rdfapi-php/test/unit/Sparql/SparqlParserTests_test.php
trunk/rdfapi-php/test/unit/Sparql/SparqlTestHelper.php
trunk/rdfapi-php/test/unit/Sparql/SparqlTests_test.php
Added Paths:
-----------
trunk/rdfapi-php/test/unit/Sparql/casesParserFilter.php
trunk/rdfapi-php/test/unit/Sparql/casesParserNested.php
trunk/rdfapi-php/test/unit/sparqlParserTests.php
Removed Paths:
-------------
trunk/rdfapi-php/test/unit/Sparql/filterCases.php
Modified: trunk/rdfapi-php/test/unit/Sparql/SparqlParserTests_test.php
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/SparqlParserTests_test.php 2007-06-21 14:48:58 UTC (rev 462)
+++ trunk/rdfapi-php/test/unit/Sparql/SparqlParserTests_test.php 2007-06-21 15:52:53 UTC (rev 463)
@@ -1,7 +1,10 @@
<?php
require_once dirname(__FILE__) . '/../../config.php';
+require_once dirname(__FILE__) . '/casesParserFilter.php';
+require_once dirname(__FILE__) . '/casesParserNested.php';
+require_once dirname(__FILE__) . '/SparqlTestHelper.php';
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlParser.php';
-require_once dirname(__FILE__) . '/filterCases.php';
+require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/QuerySimplifier.php';
/**
@@ -9,6 +12,57 @@
*/
class testSparqlParserTests extends UnitTestCase
{
+ /**
+ * Tests if Query::getLanguageTag() works correctly
+ */
+ function testQueryGetLanguageTag()
+ {
+ $this->assertEqual('en', Query::getLanguageTag('?x@en'));
+ $this->assertEqual('en', Query::getLanguageTag('?x@en^^xsd:integer'));
+ $this->assertEqual('en', Query::getLanguageTag('?x^^xsd:integer@en'));
+ $this->assertEqual('en_US', Query::getLanguageTag('?x@en_US'));
+ }//function testQueryGetLanguageTag()
+
+
+
+ /**
+ * Tests if Query::getDatatype() works correctly
+ */
+ function testQueryGetDatatype()
+ {
+ $q = new Query();
+ $q->addPrefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
+ $q->addPrefix('rdf' , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
+ $q->addPrefix('xsd' , 'http://www.w3.org/2001/XMLSchema#');
+
+ $this->assertNull($q->getDatatype('?name'));
+ $this->assertNull($q->getDatatype('?name@en'));
+ $this->assertEqual(
+ 'http://www.w3.org/2001/XMLSchema#integer',
+ $q->getDatatype('?name^^xsd:integer')
+ );
+ $this->assertEqual(
+ 'http://www.w3.org/2001/XMLSchema#integer',
+ $q->getDatatype('?name^^<http://www.w3.org/2001/XMLSchema#integer>')
+ );
+ }//function testQueryGetDatatype()
+
+
+
+ function testQueryGetFullUri()
+ {
+ $q = new Query();
+ $q->addPrefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
+ $q->addPrefix('rdf' , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
+ $q->addPrefix('xsd' , 'http://www.w3.org/2001/XMLSchema#');
+
+ $this->assertEqual('http://www.w3.org/2001/XMLSchema#integer', $q->getFullUri('xsd:integer'));
+ $this->assertFalse($q->getFullUri('yyy:integer'));
+ $this->assertFalse($q->getFullUri('integer'));
+ }//function testQueryGetFullUri()
+
+
+
function testEdgeCases()
{
$query = <<<EOT
@@ -33,7 +87,7 @@
EOT;
$p = new SparqlParser();
$q = $p->parse($query);
- }
+ }//function testEdgeCases()
@@ -47,7 +101,7 @@
$q = $p->parse($query);
$res = $q->getResultPart();
- $constraint = $res[0]->getConstraint();
+ $constraint = $res[0]->getConstraints();
$tree = $constraint[0]->getTree();
self::removeLevel($tree);
@@ -55,92 +109,29 @@
if ($result != $tree) {
var_dump($tree);
echo '----------------------' . "\n" . $query . "\n";
- echo "\n!!!!!!!! " . self::renderTree($tree) . "\n\n";
+ echo "\n!!!!!!!! " . SparqlTestHelper::renderTree($tree) . "\n\n";
}
}
- }
+ }//function testParseFilter()
- /**
- * Tests if Query::getLanguageTag() works correctly
- */
- function testQueryGetLanguageTag()
- {
- $this->assertEqual('en', Query::getLanguageTag('?x@en'));
- $this->assertEqual('en', Query::getLanguageTag('?x@en^^xsd:integer'));
- $this->assertEqual('en', Query::getLanguageTag('?x^^xsd:integer@en'));
- $this->assertEqual('en_US', Query::getLanguageTag('?x@en_US'));
- }
- /**
- * Tests if Query::getDatatype() works correctly
- */
- function testQueryGetDatatype()
+ function testParseNested()
{
- $q = new Query();
- $q->addPrefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
- $q->addPrefix('rdf' , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
- $q->addPrefix('xsd' , 'http://www.w3.org/2001/XMLSchema#');
+ echo "<b>Nested queries tests</b><br/>\n";
+ foreach ($GLOBALS['testSparqlParserTestsNested'] as $arNestedTest) {
+ list($query, $strExpected) = $arNestedTest;
- $this->assertNull($q->getDatatype('?name'));
- $this->assertNull($q->getDatatype('?name@en'));
- $this->assertEqual(
- 'http://www.w3.org/2001/XMLSchema#integer',
- $q->getDatatype('?name^^xsd:integer')
- );
- $this->assertEqual(
- 'http://www.w3.org/2001/XMLSchema#integer',
- $q->getDatatype('?name^^<http://www.w3.org/2001/XMLSchema#integer>')
- );
- }
+ $p = new SparqlParser();
+ $q = $p->parse($query);
+ $qs = new SparqlEngineDb_QuerySimplifier();
+ $qs->simplify($q);
- function testQueryGetFullUri()
- {
- $q = new Query();
- $q->addPrefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
- $q->addPrefix('rdf' , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
- $q->addPrefix('xsd' , 'http://www.w3.org/2001/XMLSchema#');
-
- $this->assertEqual('http://www.w3.org/2001/XMLSchema#integer', $q->getFullUri('xsd:integer'));
- $this->assertFalse($q->getFullUri('yyy:integer'));
- $this->assertFalse($q->getFullUri('integer'));
- }
-
-
-
- /**
- * Helper method that creates a sparql filter string from the
- * given filter tree.
- */
- static function renderTree($tree)
- {
- if (!is_array($tree) || !isset($tree['type'])) {
- return 'Parser is broken';
+ $strRendResult = SparqlTestHelper::renderResult($q);
+ $this->assertEqual($strExpected, $strRendResult);
}
- $negation = isset($tree['negated']) ? '!' : '';
- switch ($tree['type']) {
- case 'equation':
- return $negation . '(' . self::renderTree($tree['operand1'])
- . ' ' . $tree['operator'] . ' '
- . self::renderTree($tree['operand2']) . ')';
- case 'value':
- return $negation . $tree['value'];
- case 'function':
- return $negation . $tree['name'] . '('
- . implode(
- ', ',
- array_map(
- array('self', 'renderTree'),
- $tree['parameter']
- )
- ) . ')';
- default:
- var_dump($tree);
- throw new Exception('Unsupported tree type: ' . $tree['type']);
- break;
- }
- }//static function renderTree($tree)
+ }//function testParseNested()
@@ -157,6 +148,7 @@
self::removeLevel($tree['operand1']);
self::removeLevel($tree['operand2']);
}
- }
-}
+ }//static function removeLevel(&$tree)
+
+}//class testSparqlParserTests extends UnitTestCase
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/test/unit/Sparql/SparqlTestHelper.php
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/SparqlTestHelper.php 2007-06-21 14:48:58 UTC (rev 462)
+++ trunk/rdfapi-php/test/unit/Sparql/SparqlTestHelper.php 2007-06-21 15:52:53 UTC (rev 463)
@@ -67,5 +67,66 @@
return true;
}//public static resultCheckSort($table, $result)
+
+
+ /**
+ * Helper method that creates a sparql filter string from the
+ * given filter tree.
+ */
+ static function renderTree($tree)
+ {
+ if (!is_array($tree) || !isset($tree['type'])) {
+ return 'Parser is broken';
+ }
+ $negation = isset($tree['negated']) ? '!' : '';
+ switch ($tree['type']) {
+ case 'equation':
+ return $negation . '(' . self::renderTree($tree['operand1'])
+ . ' ' . $tree['operator'] . ' '
+ . self::renderTree($tree['operand2']) . ')';
+ case 'value':
+ return $negation . $tree['value'];
+ case 'function':
+ return $negation . $tree['name'] . '('
+ . implode(
+ ', ',
+ array_map(
+ array('self', 'renderTree'),
+ $tree['parameter']
+ )
+ ) . ')';
+ default:
+ var_dump($tree);
+ throw new Exception('Unsupported tree type: ' . $tree['type']);
+ break;
+ }
+ }//static function renderTree($tree)
+
+
+
+ /**
+ * renders the result part of a query object as a string
+ */
+ static function renderResult(Query $query)
+ {
+ $s = '';
+ foreach ($query->getResultPart() as $gp) {
+ //dumpGp:
+ $s .= 'GP #' . $gp->getId();
+ if ($gp->getOptional() !== null) $s .= ' optionalTo(' . $gp->getOptional() . ')';
+ if ($gp->getUnion() !== null) $s .= ' unionWith(' . $gp->getUnion() . ')';
+ if ($gp->getSubpatternOf() !== null) $s .= ' subpatternOf(' . $gp->getSubpatternOf() . ')';
+ if (count($gp->getConstraints()) > 0)$s .= ' filter(' . count($gp->getConstraints()) . ')';
+ $s .= "\n";
+ if ($gp->getTriplePatterns()) {
+ foreach ($gp->getTriplePatterns() as $tp) {
+ $s .= ' ' . $tp->getSubject() . ', ' . $tp->getPredicate()
+ . ', ' . $tp->getObject() . "\n";
+ }
+ }
+ }
+ return $s;
+ }//static function renderResult($query)
+
}//class SparqlTestHelper
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/test/unit/Sparql/SparqlTests_test.php
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/SparqlTests_test.php 2007-06-21 14:48:58 UTC (rev 462)
+++ trunk/rdfapi-php/test/unit/Sparql/SparqlTests_test.php 2007-06-21 15:52:53 UTC (rev 463)
@@ -210,7 +210,6 @@
function testFilterTestcases()
{
foreach($_SESSION['sparql_filter_tests'] as $name) {
-echo $name['query'] . "\n";
$_SESSION['test']= $name['query']." test";
$parser = new SparqlParser();
$graphset = ModelFactory::getDatasetMem('Dataset1');
@@ -222,7 +221,11 @@
$q = $parser->parse($qs);
$engine = SparqlEngine::factory();
$t = $engine->queryModel($graphset, $q, false);
- $this->assertTrue(SparqlTestHelper::resultCheck($t,$result));
+ $bOk = SparqlTestHelper::resultCheck($t,$result);
+ $this->assertTrue($bOk);
+ if (!$bOk) {
+ echo $name['query'] . "\n";
+ }
}
}
@@ -231,7 +234,6 @@
function testArqTestcases()
{
foreach($_SESSION['sparql_arq_tests'] as $name) {
-echo $name['query'] . "\n";
$_SESSION['test']= $name['query']." test";
$parser = new SparqlParser();
$graphset = ModelFactory::getDatasetMem('Dataset1');
@@ -243,10 +245,15 @@
$q = $parser->parse($qs);
$engine = SparqlEngine::factory();
$t = $engine->queryModel($graphset, $q,false);
- if($t instanceof MemModel)
- $this->assertTrue($t->equals($result));
- else
- $this->assertTrue(SparqlTestHelper::resultCheck($t,$result));
+ if ($t instanceof MemModel) {
+ $bOk = $t->equals($result);
+ } else {
+ $bOk = SparqlTestHelper::resultCheck($t,$result);
+ }
+ $this->assertTrue($bOk);
+ if (!$bOk) {
+ echo $name['query'] . "\n";
+ }
}
}
}
Copied: trunk/rdfapi-php/test/unit/Sparql/casesParserFilter.php (from rev 447, trunk/rdfapi-php/test/unit/Sparql/filterCases.php)
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/casesParserFilter.php (rev 0)
+++ trunk/rdfapi-php/test/unit/Sparql/casesParserFilter.php 2007-06-21 15:52:53 UTC (rev 463)
@@ -0,0 +1,406 @@
+<?php
+/**
+* Filter parser tests
+*/
+$GLOBALS['testSparqlParserTestsFilter'] = array(
+ array(
+<<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+SELECT ?s, ?o
+{ ?s foaf:name ?o . FILTER (?s = ?o)}
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '=',
+ 'operand1' => array('type' => 'value', 'value' => '?s', 'quoted' => false),
+ 'operand2' => array('type' => 'value', 'value' => '?o', 'quoted' => false)
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+SELECT ?s, ?o
+{ ?s foaf:name ?o . FILTER (! bound(?s))}
+EOT
+,
+ array(
+ 'negated' => true,
+ 'type' => 'function',
+ 'name' => 'bound',
+ 'parameter' => array(
+ array('type' => 'value', 'value' => '?s', 'quoted' => false)
+ ),
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+SELECT ?s, ?o
+{ ?s foaf:name ?o . FILTER(?date < xsd:dateTime("2005-01-01T00:00:00Z"))}
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '<',
+ 'operand1' => array('type' => 'value', 'value' => '?date', 'quoted' => false),
+ 'operand2' => array(
+ 'type' => 'function',
+ 'name' => 'xsd:dateTime',
+ 'parameter' => array(
+ array(
+ 'type' => 'value',
+ 'value' => '2005-01-01T00:00:00Z',
+ 'quoted' => true
+ )
+ )
+ )
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+SELECT ?mbox1
+{ ?name1 foaf:mbox ?mbox1 . FILTER ( (?mbox1 = ?mbox2) && (?name1 != ?name2) )}
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '&&',
+ 'operand1' => array(
+ 'type' => 'equation',
+ 'operator' => '=',
+ 'operand1' => array('type' => 'value', 'value' => '?mbox1', 'quoted' => false),
+ 'operand2' => array('type' => 'value', 'value' => '?mbox2', 'quoted' => false)
+ ),
+ 'operand2' => array(
+ 'type' => 'equation',
+ 'operator' => '!=',
+ 'operand1' => array('type' => 'value', 'value' => '?name1', 'quoted' => false),
+ 'operand2' => array('type' => 'value', 'value' => '?name2', 'quoted' => false)
+ )
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+SELECT ?mbox1
+{ ?name1 foaf:mbox ?mbox1 . FILTER ( ?mbox1 = ?mbox2 && ?name1 != ?name2 )}
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '&&',
+ 'operand1' => array(
+ 'type' => 'equation',
+ 'operator' => '=',
+ 'operand1' => array('type' => 'value', 'value' => '?mbox1', 'quoted' => false),
+ 'operand2' => array('type' => 'value', 'value' => '?mbox2', 'quoted' => false)
+ ),
+ 'operand2' => array(
+ 'type' => 'equation',
+ 'operator' => '!=',
+ 'operand1' => array('type' => 'value', 'value' => '?name1', 'quoted' => false),
+ 'operand2' => array('type' => 'value', 'value' => '?name2', 'quoted' => false)
+ )
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+SELECT ?mbox1
+{ ?name1 foaf:mbox ?mbox1 . FILTER regex(str(?mbox), "@work.example")}
+EOT
+,
+ array(
+ 'type' => 'function',
+ 'name' => 'regex',
+ 'parameter' => array(
+ array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array('type' => 'value', 'value' => '?mbox', 'quoted' => false)
+ )
+ ),
+ array(
+ 'type' => 'value',
+ 'value' => '@work.example',
+ 'quoted' => true
+ )
+ ),
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+SELECT ?mbox1
+{ ?name1 foaf:mbox ?mbox1 . FILTER str(str(str(str(?mbox))))}
+EOT
+,
+ array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array(
+ 'type' => 'value',
+ 'value' => '?mbox',
+ 'quoted' => false
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+PREFIX : <http://example.org/things#>
+SELECT ?x
+WHERE
+ { ?x :p ?v .
+ FILTER (?v = 1.0)
+ }
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '=',
+ 'operand1' => array('type' => 'value', 'value' => '?v', 'quoted' => false),
+ 'operand2' => array('type' => 'value', 'value' => '1.0', 'quoted' => false),
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+PREFIX : <http://example.org/ns#>
+SELECT ?a
+WHERE
+ { ?a :p ?v .
+ FILTER (?v) .
+ }
+EOT
+,
+ array(
+ 'type' => 'value',
+ 'value' => '?v',
+ 'quoted' => false
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX a: <http://www.w3.org/2000/10/annotation-ns#>
+PREFIX dc: <http://purl.org/dc/elements/1.1/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+
+SELECT ?annot
+WHERE { ?annot a:annotates <http://www.w3.org/TR/rdf-sparql-query/> .
+ ?annot dc:created ?date .
+ FILTER ( xsd:dateTime(?date) < xsd:dateTime("2005-01-01T00:00:00Z") )
+ }
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '<',
+ 'operand1' => array(
+ 'type' => 'function',
+ 'name' => 'xsd:dateTime',
+ 'parameter' => array(
+ array('type' => 'value', 'value' => '?date', 'quoted' => false),
+ )
+ ),
+ 'operand2' => array(
+ 'type' => 'function',
+ 'name' => 'xsd:dateTime',
+ 'parameter' => array(
+ array(
+ 'type' => 'value',
+ 'value' => '2005-01-01T00:00:00Z',
+ 'quoted' => true
+ )
+ )
+ )
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+
+SELECT ?p, ?o
+ { ?s ?p ?o . FILTER (!!!isLiteral(?o)). }
+EOT
+,
+ array(
+ 'negated' => true,
+ 'type' => 'function',
+ 'name' => 'isLiteral',
+ 'parameter' => array(
+ array('type' => 'value', 'value' => '?o', 'quoted' => false)
+ ),
+ )
+ ),
+
+ array(
+<<<EOT
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+PREFIX : <http://example.org/ns#>
+SELECT ?a
+WHERE { ?a :p ?v . FILTER ( ! ?v ) . }
+EOT
+,
+ array(
+ 'negated' => true,
+ 'type' => 'value',
+ 'value' => '?v',
+ 'quoted' => false
+ )
+ ),
+/**/
+ array(
+<<<EOT
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+PREFIX : <http://example.org/ns#>
+SELECT ?a
+WHERE { ?a :p ?v . FILTER ("true"^^xsd:boolean && ?v) .}
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '&&',
+ 'operand1' => array(
+ 'type' => 'value',
+ 'value' => 'true',
+ 'quoted' => true,
+ 'datatype' => 'http://www.w3.org/2001/XMLSchema#boolean'
+ ),
+ 'operand2' => array('type' => 'value', 'value' => '?v', 'quoted' => false),
+ )
+ ),
+ array(
+<<<EOT
+SELECT *
+WHERE
+ { ?x ?y ?z .
+ FILTER ( str(?z) = str("value"@en) ) .
+ }
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '=',
+ 'operand1' => array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array(
+ 'type' => 'value',
+ 'value' => '?z',
+ 'quoted' => false
+ )
+ )
+ ),
+ 'operand2' => array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array(
+ 'type' => 'value',
+ 'value' => 'value',
+ 'quoted' => true,
+ 'language' => 'en'
+ )
+ )
+ )
+ )
+ ),
+ array(
+<<<EOT
+SELECT * WHERE
+ { ?x ?y ?z .
+ FILTER ( str(?x) = str(<http://rdf.hp.com/r-1>) ) .
+ }
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '=',
+ 'operand1' => array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array(
+ 'type' => 'value',
+ 'value' => '?x',
+ 'quoted' => false
+ )
+ )
+ ),
+ 'operand2' => array(
+ 'type' => 'function',
+ 'name' => 'str',
+ 'parameter' => array(
+ array(
+ 'type' => 'value',
+ 'value' => '<http://rdf.hp.com/r-1>',
+ 'quoted' => false
+ )
+ )
+ )
+ )
+ ),
+ array(
+<<<EOT
+SELECT DISTINCT ?Res
+WHERE {
+?Res rdf:type ?_v1 FILTER (?Res = <ldap://ldap.seerose.biz/dc=biz,dc=seerose,ou=People>)
+}
+ORDER BY ?Res
+EOT
+,
+ array(
+ 'type' => 'equation',
+ 'operator' => '=',
+ 'operand1' => array('type' => 'value', 'value' => '?Res', 'quoted' => false),
+ 'operand2' => array(
+ 'type' => 'value',
+ 'value' => '<ldap://ldap.seerose.biz/dc=biz,dc=seerose,ou=People>',
+ 'quoted'=> false
+ )
+ )
+ ),
+);
+?>
\ No newline at end of file
Added: trunk/rdfapi-php/test/unit/Sparql/casesParserNested.php
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/casesParserNested.php (rev 0)
+++ trunk/rdfapi-php/test/unit/Sparql/casesParserNested.php 2007-06-21 15:52:53 UTC (rev 463)
@@ -0,0 +1,146 @@
+<?php
+/**
+* Nested queries parser test
+* While the result format might seem a bit strange, it helps
+* us to debug the results easily and spot what doesn't work at which place.
+*
+* @author Christian Weiske <cw...@cw...>
+*/
+$GLOBALS['testSparqlParserTestsNested'] = array(
+ array(<<<EOT
+SELECT ?name ?mbox
+WHERE
+{
+ ?a ?b ?c
+ {
+ {
+ ?g ?h ?i .
+ {
+ {?person <some://typ/e> 'asd'}
+ UNION
+ {?person3 <some://typ/es2> 'three'}
+ }
+ }
+ UNION
+ {?person2 <some://typ/es> '2'}
+ }
+ ?d ?e ?f
+}
+EOT
+ , <<<EOT
+GP #0
+ ?a, ?b, ?c
+ ?d, ?e, ?f
+ ?person2, Resource("some://typ/es"), Literal("2")
+GP #2 unionWith(0)
+ ?a, ?b, ?c
+ ?d, ?e, ?f
+ ?g, ?h, ?i
+ ?person, Resource("some://typ/e"), Literal("asd")
+GP #6 unionWith(0)
+ ?a, ?b, ?c
+ ?d, ?e, ?f
+ ?g, ?h, ?i
+ ?person3, Resource("some://typ/es2"), Literal("three")
+
+EOT
+ ),
+
+ /////next\\\\\
+ array( <<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-nss#>
+SELECT DISTINCT ?Res ?Attr ?Val
+WHERE
+{
+ {
+ ?Res rdf:type ?_v1 .
+ {
+ ?Res foaf:name ?_v2 FILTER regex(?_v2,"^Alexander Loeser$", "i")
+ }
+ UNION
+ {
+ ?Res rdfs:label ?_v3 FILTER regex(?_v3,"^Alexander Loeser$", "i")
+ }
+ }
+ ?Res ?Attr ?Val
+}
+ORDER BY ?Res
+EOT
+ , <<<EOT
+GP #0 filter(1)
+ ?Res, ?Attr, ?Val
+ ?Res, Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), ?_v1
+ ?Res, Resource("http://www.w3.org/1999/02/22-rdf-syntax-nss#label"), ?_v3
+GP #1 unionWith(0) filter(1)
+ ?Res, ?Attr, ?Val
+ ?Res, Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), ?_v1
+ ?Res, Resource("http://xmlns.com/foaf/0.1/name"), ?_v2
+
+EOT
+ ),
+
+ /////next\\\\\
+ array( <<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+
+SELECT ?name ?mbox
+WHERE
+ {
+ { ?person rdf:type foaf:Person } .
+ OPTIONAL { ?person foaf:name ?name } .
+ OPTIONAL {?person foaf:mbox ?mbox} .
+ }
+ UNION
+ {
+ { ?person2 rdf:kind foaf:Person } .
+ OPTIONAL {?person2 <asdf> ?mbox. ?person2 rdf:laughs ?atyou } .
+ }
+EOT
+ , <<<EOT
+GP #1
+ ?person, Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), Resource("http://xmlns.com/foaf/0.1/Person")
+GP #2 optionalTo(1)
+ ?person, Resource("http://xmlns.com/foaf/0.1/name"), ?name
+GP #3 optionalTo(1)
+ ?person, Resource("http://xmlns.com/foaf/0.1/mbox"), ?mbox
+
+EOT
+ ),
+
+ /////next\\\\\
+ array( <<<EOT
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+SELECT DISTINCT ?value
+WHERE {
+ {?s ?p ?value . FILTER (isIRI(?value)). OPTIONAL { ?s ?p ?value} }
+UNION {?s ?value ?o . FILTER (isIRI(?value)) }
+UNION {?value ?p ?o . FILTER (isIRI(?value)) }
+ }
+EOT
+ , <<<EOT
+GP #1 filter(1)
+ ?s, ?p, ?value
+GP #2 optionalTo(1)
+ ?s, ?p, ?value
+GP #3 unionWith(1) filter(1)
+ ?s, ?value, ?o
+GP #4 unionWith(3) filter(1)
+ ?value, ?p, ?o
+
+EOT
+ ),
+
+/*
+
+ /////next\\\\\
+ array( <<<EOT
+EOT
+ , <<<EOT
+EOT
+ ),
+*/
+);
+?>
\ No newline at end of file
Deleted: trunk/rdfapi-php/test/unit/Sparql/filterCases.php
===================================================================
--- trunk/rdfapi-php/test/unit/Sparql/filterCases.php 2007-06-21 14:48:58 UTC (rev 462)
+++ trunk/rdfapi-php/test/unit/Sparql/filterCases.php 2007-06-21 15:52:53 UTC (rev 463)
@@ -1,406 +0,0 @@
-<?php
-/**
-* Filter parser tests
-*/
-$GLOBALS['testSparqlParserTestsFilter'] = array(
- array(
-<<<EOT
-PREFIX foaf: <http://xmlns.com/foaf/0.1/>
-SELECT ?s, ?o
-{ ?s foaf:name ?o . FILTER (?s = ?o)}
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '=',
- 'operand1' => array('type' => 'value', 'value' => '?s', 'quoted' => false),
- 'operand2' => array('type' => 'value', 'value' => '?o', 'quoted' => false)
- )
- ),
-
- array(
-<<<EOT
-PREFIX foaf: <http://xmlns.com/foaf/0.1/>
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-SELECT ?s, ?o
-{ ?s foaf:name ?o . FILTER (! bound(?s))}
-EOT
-,
- array(
- 'negated' => true,
- 'type' => 'function',
- 'name' => 'bound',
- 'parameter' => array(
- array('type' => 'value', 'value' => '?s', 'quoted' => false)
- ),
- )
- ),
-
- array(
-<<<EOT
-PREFIX foaf: <http://xmlns.com/foaf/0.1/>
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-SELECT ?s, ?o
-{ ?s foaf:name ?o . FILTER(?date < xsd:dateTime("2005-01-01T00:00:00Z"))}
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '<',
- 'operand1' => array('type' => 'value', 'value' => '?date', 'quoted' => false),
- 'operand2' => array(
- 'type' => 'function',
- 'name' => 'xsd:dateTime',
- 'parameter' => array(
- array(
- 'type' => 'value',
- 'value' => '2005-01-01T00:00:00Z',
- 'quoted' => true
- )
- )
- )
- )
- ),
-
- array(
-<<<EOT
-PREFIX foaf: <http://xmlns.com/foaf/0.1/>
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-SELECT ?mbox1
-{ ?name1 foaf:mbox ?mbox1 . FILTER ( (?mbox1 = ?mbox2) && (?name1 != ?name2) )}
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '&&',
- 'operand1' => array(
- 'type' => 'equation',
- 'operator' => '=',
- 'operand1' => array('type' => 'value', 'value' => '?mbox1', 'quoted' => false),
- 'operand2' => array('type' => 'value', 'value' => '?mbox2', 'quoted' => false)
- ),
- 'operand2' => array(
- 'type' => 'equation',
- 'operator' => '!=',
- 'operand1' => array('type' => 'value', 'value' => '?name1', 'quoted' => false),
- 'operand2' => array('type' => 'value', 'value' => '?name2', 'quoted' => false)
- )
- )
- ),
-
- array(
-<<<EOT
-PREFIX foaf: <http://xmlns.com/foaf/0.1/>
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-SELECT ?mbox1
-{ ?name1 foaf:mbox ?mbox1 . FILTER ( ?mbox1 = ?mbox2 && ?name1 != ?name2 )}
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '&&',
- 'operand1' => array(
- 'type' => 'equation',
- 'operator' => '=',
- 'operand1' => array('type' => 'value', 'value' => '?mbox1', 'quoted' => false),
- 'operand2' => array('type' => 'value', 'value' => '?mbox2', 'quoted' => false)
- ),
- 'operand2' => array(
- 'type' => 'equation',
- 'operator' => '!=',
- 'operand1' => array('type' => 'value', 'value' => '?name1', 'quoted' => false),
- 'operand2' => array('type' => 'value', 'value' => '?name2', 'quoted' => false)
- )
- )
- ),
-
- array(
-<<<EOT
-PREFIX foaf: <http://xmlns.com/foaf/0.1/>
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-SELECT ?mbox1
-{ ?name1 foaf:mbox ?mbox1 . FILTER regex(str(?mbox), "@work.example")}
-EOT
-,
- array(
- 'type' => 'function',
- 'name' => 'regex',
- 'parameter' => array(
- array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array('type' => 'value', 'value' => '?mbox', 'quoted' => false)
- )
- ),
- array(
- 'type' => 'value',
- 'value' => '@work.example',
- 'quoted' => true
- )
- ),
- )
- ),
-
- array(
-<<<EOT
-PREFIX foaf: <http://xmlns.com/foaf/0.1/>
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-SELECT ?mbox1
-{ ?name1 foaf:mbox ?mbox1 . FILTER str(str(str(str(?mbox))))}
-EOT
-,
- array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array(
- 'type' => 'value',
- 'value' => '?mbox',
- 'quoted' => false
- )
- )
- )
- )
- )
- )
- )
- )
- )
- ),
-
- array(
-<<<EOT
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-PREFIX : <http://example.org/things#>
-SELECT ?x
-WHERE
- { ?x :p ?v .
- FILTER (?v = 1.0)
- }
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '=',
- 'operand1' => array('type' => 'value', 'value' => '?v', 'quoted' => false),
- 'operand2' => array('type' => 'value', 'value' => '1.0', 'quoted' => false),
- )
- ),
-
- array(
-<<<EOT
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-PREFIX : <http://example.org/ns#>
-SELECT ?a
-WHERE
- { ?a :p ?v .
- FILTER (?v) .
- }
-EOT
-,
- array(
- 'type' => 'value',
- 'value' => '?v',
- 'quoted' => false
- )
- ),
-
- array(
-<<<EOT
-PREFIX a: <http://www.w3.org/2000/10/annotation-ns#>
-PREFIX dc: <http://purl.org/dc/elements/1.1/>
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-
-SELECT ?annot
-WHERE { ?annot a:annotates <http://www.w3.org/TR/rdf-sparql-query/> .
- ?annot dc:created ?date .
- FILTER ( xsd:dateTime(?date) < xsd:dateTime("2005-01-01T00:00:00Z") )
- }
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '<',
- 'operand1' => array(
- 'type' => 'function',
- 'name' => 'xsd:dateTime',
- 'parameter' => array(
- array('type' => 'value', 'value' => '?date', 'quoted' => false),
- )
- ),
- 'operand2' => array(
- 'type' => 'function',
- 'name' => 'xsd:dateTime',
- 'parameter' => array(
- array(
- 'type' => 'value',
- 'value' => '2005-01-01T00:00:00Z',
- 'quoted' => true
- )
- )
- )
- )
- ),
-
- array(
-<<<EOT
-PREFIX foaf: <http://xmlns.com/foaf/0.1/>
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-
-SELECT ?p, ?o
- { ?s ?p ?o . FILTER (!!!isLiteral(?o)). }
-EOT
-,
- array(
- 'negated' => true,
- 'type' => 'function',
- 'name' => 'isLiteral',
- 'parameter' => array(
- array('type' => 'value', 'value' => '?o', 'quoted' => false)
- ),
- )
- ),
-
- array(
-<<<EOT
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-PREFIX : <http://example.org/ns#>
-SELECT ?a
-WHERE { ?a :p ?v . FILTER ( ! ?v ) . }
-EOT
-,
- array(
- 'negated' => true,
- 'type' => 'value',
- 'value' => '?v',
- 'quoted' => false
- )
- ),
-/**/
- array(
-<<<EOT
-PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
-PREFIX : <http://example.org/ns#>
-SELECT ?a
-WHERE { ?a :p ?v . FILTER ("true"^^xsd:boolean && ?v) .}
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '&&',
- 'operand1' => array(
- 'type' => 'value',
- 'value' => 'true',
- 'quoted' => true,
- 'datatype' => 'http://www.w3.org/2001/XMLSchema#boolean'
- ),
- 'operand2' => array('type' => 'value', 'value' => '?v', 'quoted' => false),
- )
- ),
- array(
-<<<EOT
-SELECT *
-WHERE
- { ?x ?y ?z .
- FILTER ( str(?z) = str("value"@en) ) .
- }
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '=',
- 'operand1' => array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array(
- 'type' => 'value',
- 'value' => '?z',
- 'quoted' => false
- )
- )
- ),
- 'operand2' => array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array(
- 'type' => 'value',
- 'value' => 'value',
- 'quoted' => true,
- 'language' => 'en'
- )
- )
- )
- )
- ),
- array(
-<<<EOT
-SELECT * WHERE
- { ?x ?y ?z .
- FILTER ( str(?x) = str(<http://rdf.hp.com/r-1>) ) .
- }
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '=',
- 'operand1' => array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array(
- 'type' => 'value',
- 'value' => '?x',
- 'quoted' => false
- )
- )
- ),
- 'operand2' => array(
- 'type' => 'function',
- 'name' => 'str',
- 'parameter' => array(
- array(
- 'type' => 'value',
- 'value' => '<http://rdf.hp.com/r-1>',
- 'quoted' => false
- )
- )
- )
- )
- ),
- array(
-<<<EOT
-SELECT DISTINCT ?Res
-WHERE {
-?Res rdf:type ?_v1 FILTER (?Res = <ldap://ldap.seerose.biz/dc=biz,dc=seerose,ou=People>)
-}
-ORDER BY ?Res
-EOT
-,
- array(
- 'type' => 'equation',
- 'operator' => '=',
- 'operand1' => array('type' => 'value', 'value' => '?Res', 'quoted' => false),
- 'operand2' => array(
- 'type' => 'value',
- 'value' => '<ldap://ldap.seerose.biz/dc=biz,dc=seerose,ou=People>',
- 'quoted'=> false
- )
- )
- ),
-);
-?>
\ No newline at end of file
Added: trunk/rdfapi-php/test/unit/sparqlParserTests.php
===================================================================
--- trunk/rdfapi-php/test/unit/sparqlParserTests.php (rev 0)
+++ trunk/rdfapi-php/test/unit/sparqlParserTests.php 2007-06-21 15:52:53 UTC (rev 463)
@@ -0,0 +1,34 @@
+<?php
+
+if (!@include_once(dirname(__FILE__) . '/../config.php')) {
+ die('Make a copy of test/config.php.dist, change it and save it as test/config.php');
+}
+
+require_once( SIMPLETEST_INCLUDE_DIR . 'unit_tester.php');
+require_once( SIMPLETEST_INCLUDE_DIR . 'reporter.php');
+require_once('show_passes.php');
+require(RDFAPI_INCLUDE_DIR . 'RdfAPI.php');
+
+$_SESSION['passes'] = 0;
+$_SESSION['fails'] = 0;
+
+if(LOG){
+ $file = fopen ("testlog.log", "a");
+ $time= strftime('%d.%m.%y %H:%M:%S' );
+ fputs($file,"\r\n".'-----'.$time.'-----'."\r\n");
+}
+
+$test_sparql= &new GroupTest('Sparql Parser Testcases');
+$test_sparql->addTestFile(RDFAPI_TEST_INCLUDE_DIR. 'test/unit/Sparql/SparqlParserTests_test.php');
+//$test_sparql->run(new ShowPasses());
+$test_sparql->run(new TextReporter());
+
+
+if(LOG){
+ $file = fopen ("testlog.log", "a");
+ $time= strftime('%d.%m.%y %H:%M:%S' );
+ fputs($file,"\r\n".' Passes: '.$_SESSION['passes'].' Fails: '.$_SESSION['fails']."\r\n");
+ fclose($file);
+}
+
+?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-21 14:48:59
|
Revision: 462
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=462&view=rev
Author: cweiske
Date: 2007-06-21 07:48:58 -0700 (Thu, 21 Jun 2007)
Log Message:
-----------
Fixing parser again and using query flattener in SparqlEngineDb
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 14:08:44 UTC (rev 461)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 14:48:58 UTC (rev 462)
@@ -35,6 +35,7 @@
self::dropEmpty($arPatterns);
$arPlan = $this->createPlan($arPatterns);
if (count($arPlan) == 0) {
+ $query->setResultPart($arPatterns);
return 0;
}
@@ -142,9 +143,8 @@
/**
- * Removes all empty graph patterns from the
- * array.
- * Modifies it directly
+ * Removes all empty graph patterns from the array.
+ * Modifies it directly.
*/
protected static function dropEmpty(&$arPatterns)
{
@@ -153,6 +153,13 @@
unset($arPatterns[$nId]);
}
}
+
+ foreach ($arPatterns as $nId => &$pattern) {
+ $nParent = $pattern->getSubpatternOf();
+ if (!isset($arPatterns[$nParent])) {
+ $arPatterns[$nId]->setSubpatternOf(null);
+ }
+ }
//FIXME: continued indexes?
}//protected static function dropEmpty(&$arPatterns)
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-06-21 14:08:44 UTC (rev 461)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb.php 2007-06-21 14:48:58 UTC (rev 462)
@@ -1,6 +1,7 @@
<?php
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngine.php';
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/Offsetter.php';
+require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/QuerySimplifier.php';
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/ResultConverter.php';
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/SqlGenerator.php';
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/SqlMerger.php';
@@ -115,6 +116,8 @@
{
$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);
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 14:08:44 UTC (rev 461)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 14:48:58 UTC (rev 462)
@@ -569,8 +569,6 @@
}
if (is_int($subpattern)) {
$pattern->setSubpatternOf($subpattern);
- } else {
- $subpattern = $pattern->getId();
}
if ($graph != false) {
$pattern->setGraphname($graph);
@@ -605,6 +603,10 @@
$this->_fastForward();
break;
case "{":
+ if (!is_int($subpattern)) {
+ $subpattern = $pattern->getId();
+ }
+
$this->parseGraphPattern(
false, false, false, false, false, $subpattern
);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-21 14:08:50
|
Revision: 461
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=461&view=rev
Author: cweiske
Date: 2007-06-21 07:08:44 -0700 (Thu, 21 Jun 2007)
Log Message:
-----------
Parser is finally parsing ldap2sparql-nested^2 sparql queries of death
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/GraphPattern.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/GraphPattern.php
===================================================================
--- trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 12:28:11 UTC (rev 460)
+++ trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 14:08:44 UTC (rev 461)
@@ -142,7 +142,7 @@
}
/**
- * Sets the List of QueryTriples to the GraphPattern.
+ * Adds List of QueryTriples to the GraphPattern.
*
* @param array $trpP
* @return void
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 12:28:11 UTC (rev 460)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 14:08:44 UTC (rev 461)
@@ -569,6 +569,8 @@
}
if (is_int($subpattern)) {
$pattern->setSubpatternOf($subpattern);
+ } else {
+ $subpattern = $pattern->getId();
}
if ($graph != false) {
$pattern->setGraphname($graph);
@@ -630,7 +632,7 @@
*/
protected function parseTriplePattern(&$pattern)
{
- $trp = Array();
+ $trp = array();
$prev = false;
$prevPred = false;
$cont = true;
@@ -655,6 +657,12 @@
$this->parseGraphPattern($pattern->getId(),false);
$cont = false;
break;
+ case "union":
+ $this->_fastForward();
+ $this->parseGraphPattern(
+ false, $this->tmp, false, false, false, $pattern->getId()
+ );
+ break;
case ";":
$prev = true;
$this->_fastForward();
@@ -732,7 +740,7 @@
} while ($cont);
if (count($trp) > 0) {
- $pattern->setTriplePatterns($trp);
+ $pattern->addTriplePatterns($trp);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-21 12:28:13
|
Revision: 460
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=460&view=rev
Author: cweiske
Date: 2007-06-21 05:28:11 -0700 (Thu, 21 Jun 2007)
Log Message:
-----------
Nested nested queries are flattened
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/GraphPattern.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
Modified: trunk/rdfapi-php/api/sparql/GraphPattern.php
===================================================================
--- trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 09:48:40 UTC (rev 459)
+++ trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 12:28:11 UTC (rev 460)
@@ -266,11 +266,8 @@
{
return
count($this->triplePatterns) == 0
- && $this->getGraphname() === null
&& count($this->constraints) == 0
- && $this->getOptional() === null
- && $this->getUnion() === null
- && $this->getSubpatternOf() === null
+ && $this->getGraphname() === null
;
}//public function isEmpty()
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 09:48:40 UTC (rev 459)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 12:28:11 UTC (rev 460)
@@ -32,6 +32,7 @@
public function simplify(Query $query)
{
$arPatterns = $query->getResultPart();
+ self::dropEmpty($arPatterns);
$arPlan = $this->createPlan($arPatterns);
if (count($arPlan) == 0) {
return 0;
@@ -61,7 +62,7 @@
foreach ($arNumbers as $nId => $nPatternCount) {
$nParent = $arPatterns[$nId]->getSubpatternOf();
- $arPlan[$nParent][] = $nId;
+ $arPlan[$nParent][$nId] = true;
}
return $arPlan;
@@ -71,13 +72,17 @@
/**
* Executes the plan
+ *
+ * @param array $arPatterns Array of GraphPatterns
+ * @param array $arPlan Plan array as returned by createPlan()
*/
protected function executePlan(&$arPatterns, &$arPlan)
{
foreach ($arPlan as $nParent => $arChildren) {
- $base = $arPatterns[$nParent];
- $nNextId = $nParent;
- foreach ($arChildren as $nChild) {
+ $base = $arPatterns[$nParent];
+ $grandParent = $base->getSubpatternOf();
+ $nNextId = $nParent;
+ foreach ($arChildren as $nChild => $null) {
$new = clone $base;
$new->addTriplePatterns($arPatterns[$nChild]->getTriplePatterns());
$new->addConstraints( $arPatterns[$nChild]->getConstraints());
@@ -87,6 +92,11 @@
}
$arPatterns[$nNextId] = $new;
+ if ($grandParent !== null) {
+ //dynamically adjust plan
+ $arPlan[$grandParent][$nNextId] = true;
+ }
+
$nNextId = $nChild;
}
//last one is not not needed anymore
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-21 09:48:42
|
Revision: 459
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=459&view=rev
Author: cweiske
Date: 2007-06-21 02:48:40 -0700 (Thu, 21 Jun 2007)
Log Message:
-----------
Simplifier nearly works, but the parser seems to have a bug
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/GraphPattern.php
trunk/rdfapi-php/api/sparql/SparqlEngine.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/GraphPattern.php
===================================================================
--- trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 09:10:50 UTC (rev 458)
+++ trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 09:48:40 UTC (rev 459)
@@ -24,7 +24,7 @@
* Array of QueryTriple objects
* @var array
*/
- protected $triplePatterns = null;
+ protected $triplePatterns = array();
/**
* A List of Constraint objects
@@ -69,11 +69,11 @@
/**
* Constructor
*/
- public function GraphPattern(){
- $this->open = true ;
+ public function GraphPattern() {
+ $this->open = true;
$this->isConstructPattern = false;
- $this->constraints = false;
- $this->triplePatterns = false;
+ $this->constraints = array();
+ $this->triplePatterns = array();
}
/**
@@ -137,7 +137,7 @@
* @param String $name
* @return void
*/
- public function setGraphname($name){
+ public function setGraphname($name) {
$this->graphname = $name;
}
@@ -148,7 +148,7 @@
* @return void
*/
public function addTriplePatterns($trpP) {
- $this->triplePatterns = array_merge($$this->triplePatterns, $trpP);
+ $this->triplePatterns = array_merge($this->triplePatterns, $trpP);
}
/**
@@ -165,39 +165,48 @@
* Adds a single Constraint to the GraphPattern.
*
* @param Constraint $cons
- * @return void
*/
- public function addConstraint(&$cons){
+ public function addConstraint(&$cons) {
$this->constraints[] = $cons;
}
+
/**
+ * Adds an array of Constraint objects to the GraphPattern.
+ *
+ * @param array $cons
+ */
+ public function addConstraints(&$cons) {
+ $this->constraints = array_merge($this->constraints, $cons);
+ }
+
+ /**
* Adds a pointer to an optional graphPattern.
*
- * @param integer $pattern
+ * @param integer $patternId
* @return void
*/
- public function addOptional($pattern){
- $this->optional = &$pattern;
+ public function setOptional($patternId) {
+ $this->optional = &$patternId;
}
/**
* Adds a pointer to a union graphPattern.
*
- * @param integer $pattern
+ * @param integer $patternId
* @return void
*/
- public function addUnion($pattern){
- $this->union = &$pattern;
+ public function setUnion($patternId) {
+ $this->union = &$patternId;
}
/**
* Adds a pointer to a pattern that
* this one is subpattern of
*
- * @param integer $pattern
+ * @param integer $patternId
*/
- public function setSubpatternOf($pattern){
- $this->subpatternOf = $pattern;
+ public function setSubpatternOf($patternId) {
+ $this->subpatternOf = $patternId;
}
@@ -256,9 +265,9 @@
public function isEmpty()
{
return
- $this->getTriplePatterns() === false
+ count($this->triplePatterns) == 0
&& $this->getGraphname() === null
- && $this->getConstraints() === false
+ && count($this->constraints) == 0
&& $this->getOptional() === null
&& $this->getUnion() === null
&& $this->getSubpatternOf() === null
@@ -272,11 +281,15 @@
*/
public function __clone()
{
- foreach ($this->triplePatterns as $nId => $pattern) {
- $this->triplePatterns[$nId] = clone $this->triplePatterns[$nId];
+ if (count($this->triplePatterns) > 0) {
+ foreach ($this->triplePatterns as $nId => $pattern) {
+ $this->triplePatterns[$nId] = clone $this->triplePatterns[$nId];
+ }
}
- foreach ($this->constraints as $nId => $constraint) {
- $this->constraints[$nId] = clone $this->constraints[$nId];
+ if (count($this->constraints) > 0) {
+ foreach ($this->constraints as $nId => $constraint) {
+ $this->constraints[$nId] = clone $this->constraints[$nId];
+ }
}
}
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine.php 2007-06-21 09:10:50 UTC (rev 458)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine.php 2007-06-21 09:48:40 UTC (rev 459)
@@ -153,7 +153,7 @@
// generate an empty result set
$finalRes = null;
// if the GraphPattern has triple patterns
- if($graphPattern->getTriplePatterns()>0){
+ if (count($graphPattern->getTriplePatterns()) > 0) {
// check if the pattern has a GRAPH clause and if this Iri is in $graphlist
$newGraphList = $this->_checkGraphs($graphPattern,$graphlist);
if($newGraphList){
@@ -189,7 +189,7 @@
$patternlist[$un]['hasUnion']++;
$constraint = $graphPattern->getConstraints();
- if($constraint != null){
+ if(count($constraint) > 0){
foreach($constraint as $constr){
if($constr->isOuterFilter()){
$patternlist[$graphPattern->getId()]['outerFilter'][] = $constr;
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 09:10:50 UTC (rev 458)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 09:48:40 UTC (rev 459)
@@ -52,15 +52,15 @@
*/
protected function createPlan(&$arPatterns)
{
- list($arNumbers, $nNotZero) = $this->getNumbers($arPatterns);
+ $arNumbers = $this->getNumbers($arPatterns);
if (count($arNumbers) == 0) {
return array();
}
$arPlan = array();
- foreach ($arNumbers as $nId => $nNumber) {
- $nParent = $pattern->getSubpatternOf();
+ foreach ($arNumbers as $nId => $nPatternCount) {
+ $nParent = $arPatterns[$nId]->getSubpatternOf();
$arPlan[$nParent][] = $nId;
}
@@ -69,6 +69,9 @@
+ /**
+ * Executes the plan
+ */
protected function executePlan(&$arPatterns, &$arPlan)
{
foreach ($arPlan as $nParent => $arChildren) {
@@ -76,11 +79,18 @@
$nNextId = $nParent;
foreach ($arChildren as $nChild) {
$new = clone $base;
- $new->addTriplePatterns($arPatterns[$nChild]->getTriplePattern());
+ $new->addTriplePatterns($arPatterns[$nChild]->getTriplePatterns());
+ $new->addConstraints( $arPatterns[$nChild]->getConstraints());
+ $new->setId($nNextId);
+ if ($nParent != $nNextId) {
+ $new->setUnion($nParent);
+ }
$arPatterns[$nNextId] = $new;
$nNextId = $nChild;
}
+ //last one is not not needed anymore
+ unset($arPatterns[$nNextId]);
}
}//protected function executePlan(&$arPatterns, &$arPlan)
@@ -114,7 +124,7 @@
}
}
- rsort($arNumbers);
+ arsort($arNumbers);
return $arNumbers;
}//protected function getNumbers(&$arPatterns)
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 09:10:50 UTC (rev 458)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 09:48:40 UTC (rev 459)
@@ -560,12 +560,12 @@
){
$pattern = $this->query->getNewPattern($constr);
if (is_int($optional)) {
- $pattern->addOptional($optional);
+ $pattern->setOptional($optional);
} else {
$this->tmp = $pattern->getId();
}
if (is_int($union)) {
- $pattern->addUnion($union);
+ $pattern->setUnion($union);
}
if (is_int($subpattern)) {
$pattern->setSubpatternOf($subpattern);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-21 09:10:52
|
Revision: 458
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=458&view=rev
Author: cweiske
Date: 2007-06-21 02:10:50 -0700 (Thu, 21 Jun 2007)
Log Message:
-----------
Big BC breaking commit:
- Query::getTriplePattern renamed to getTriplePatterns
- Query::getConstraint renamed to getConstraints
- GraphPattern::addTriplePattern -> setTriplePatterns
- isVariable moved from SqlGenerator to SparqlVariable.php
!! Custom renderers will need to adjust getTriplePattern calls!
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/GraphPattern.php
trunk/rdfapi-php/api/sparql/QueryTriple.php
trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/Default.php
trunk/rdfapi-php/api/sparql/SparqlEngine.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Added Paths:
-----------
trunk/rdfapi-php/api/sparql/SparqlVariable.php
Modified: trunk/rdfapi-php/api/sparql/GraphPattern.php
===================================================================
--- trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -21,14 +21,16 @@
protected $graphname = null;
/**
- * @var array The TriplePattern.
+ * Array of QueryTriple objects
+ * @var array
*/
- protected $triplePattern = null;
+ protected $triplePatterns = null;
/**
- * @var array A List of Constraints.
+ * A List of Constraint objects
+ * @var array
*/
- protected $constraint = array();
+ protected $constraints = array();
/**
* @var int Pointer to optional pattern.
@@ -70,8 +72,8 @@
public function GraphPattern(){
$this->open = true ;
$this->isConstructPattern = false;
- $this->constraint = false;
- $this->triplePattern = false;
+ $this->constraints = false;
+ $this->triplePatterns = false;
}
/**
@@ -88,8 +90,8 @@
*
* @return Array
*/
- public function getTriplePattern(){
- return $this->triplePattern;
+ public function getTriplePatterns(){
+ return $this->triplePatterns;
}
/**
@@ -97,8 +99,8 @@
*
* @return Constraint
*/
- public function getConstraint() {
- return $this->constraint;
+ public function getConstraints() {
+ return $this->constraints;
}
/**
@@ -138,24 +140,35 @@
public function setGraphname($name){
$this->graphname = $name;
}
+
/**
- * Adds a List of QueryTriples to the GraphPattern.
+ * Sets the List of QueryTriples to the GraphPattern.
*
* @param array $trpP
* @return void
*/
- public function addTriplePatterns($trpP){
- $this->triplePattern = $trpP;
+ public function addTriplePatterns($trpP) {
+ $this->triplePatterns = array_merge($$this->triplePatterns, $trpP);
}
/**
- * Adds a Constraint to the GraphPattern.
+ * Sets the List of QueryTriples to the GraphPattern.
*
+ * @param array $trpP
+ * @return void
+ */
+ public function setTriplePatterns($trpP) {
+ $this->triplePatterns = $trpP;
+ }
+
+ /**
+ * Adds a single Constraint to the GraphPattern.
+ *
* @param Constraint $cons
* @return void
*/
public function addConstraint(&$cons){
- $this->constraint[] = $cons;
+ $this->constraints[] = $cons;
}
/**
* Adds a pointer to an optional graphPattern.
@@ -220,7 +233,7 @@
{
$arVars = array();
- foreach ($this->triplePattern as $pattern) {
+ foreach ($this->triplePatterns as $pattern) {
$arVars = array_merge($arVars, $pattern->getVariables());
}
@@ -243,14 +256,29 @@
public function isEmpty()
{
return
- $this->getTriplePattern() === false
- && $this->getGraphname() === null
- && $this->getConstraint() === false
- && $this->getOptional() === null
- && $this->getUnion() === null
- && $this->getSubpatternOf() === null
+ $this->getTriplePatterns() === false
+ && $this->getGraphname() === null
+ && $this->getConstraints() === false
+ && $this->getOptional() === null
+ && $this->getUnion() === null
+ && $this->getSubpatternOf() === null
;
}//public function isEmpty()
+
+
+ /**
+ * When cloning, we need to clone some subobjects, too
+ */
+ public function __clone()
+ {
+ foreach ($this->triplePatterns as $nId => $pattern) {
+ $this->triplePatterns[$nId] = clone $this->triplePatterns[$nId];
+ }
+ foreach ($this->constraints as $nId => $constraint) {
+ $this->constraints[$nId] = clone $this->constraints[$nId];
+ }
+ }
+
}// end class: GraphPattern.php
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/sparql/QueryTriple.php
===================================================================
--- trunk/rdfapi-php/api/sparql/QueryTriple.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/QueryTriple.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -2,7 +2,7 @@
// ---------------------------------------------
// Class: QueryTriple
// ---------------------------------------------
-require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/SqlGenerator.php';
+require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlVariable.php';
/**
* Represents a query triple with subject, predicate and object.
@@ -97,15 +97,26 @@
$arVars = array();
foreach (array('subject', 'predicate', 'object') as $strVar) {
- if (SparqlEngineDb_SqlGenerator::isVariable($this->$strVar)) {
+ if (SparqlVariable::isVariable($this->$strVar)) {
$arVars[] = $this->$strVar;
}
}
return $arVars;
- }
+ }//public function getVariables()
-}
+
+ public function __clone()
+ {
+ foreach (array('subject', 'predicate', 'object') as $strVar) {
+ if (is_object($this->$strVar)) {
+ $this->$strVar = clone $this->$strVar;
+ }
+ }
+ }//public function __clone()
+
+}//class QueryTriple extends Object
+
// end class: QueryTriple.php
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/Default.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/Default.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine/ResultRenderer/Default.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -83,7 +83,7 @@
return $resultGraph;
}
- $tp = $constructPattern->getTriplePattern();
+ $tp = $constructPattern->getTriplePatterns();
$bnode = 0;
foreach ($arVartable as $value) {
Modified: trunk/rdfapi-php/api/sparql/SparqlEngine.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngine.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/SparqlEngine.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -153,11 +153,11 @@
// generate an empty result set
$finalRes = null;
// if the GraphPattern has triple patterns
- if($graphPattern->getTriplePattern()>0){
+ if($graphPattern->getTriplePatterns()>0){
// check if the pattern has a GRAPH clause and if this Iri is in $graphlist
$newGraphList = $this->_checkGraphs($graphPattern,$graphlist);
if($newGraphList){
- $qt = $graphPattern->getTriplePattern();
+ $qt = $graphPattern->getTriplePatterns();
$resultSet = $this->findTuplesMatchingOnePattern($qt[0], $newGraphList);
for ($i=1; $i<count($qt); $i++) {
$rs = $this->findTuplesMatchingOnePattern($qt[$i], $newGraphList);
@@ -188,7 +188,7 @@
if(is_int($un))
$patternlist[$un]['hasUnion']++;
- $constraint = $graphPattern->getConstraint();
+ $constraint = $graphPattern->getConstraints();
if($constraint != null){
foreach($constraint as $constr){
if($constr->isOuterFilter()){
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -1,4 +1,5 @@
<?php
+require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlVariable.php';
/**
* Generates SQL from Sparql FILTER parts
@@ -141,7 +142,7 @@
protected function createValue($tree, $bDumbParent)
{
$strValue = stripslashes($tree['value']);
- if (SparqlEngineDb_SqlGenerator::isVariable($strValue)) {
+ if (SparqlVariable::isVariable($strValue)) {
if (!isset($this->sg->arUnionVarAssignments[$this->nUnionCount][$strValue])) {
throw new SparqlEngineDb_SqlGeneratorException(
'Unknown variable in filter: ' . $strValue
@@ -775,7 +776,7 @@
{
return $tree['type'] == 'value'
&& $tree['type']['quoted'] === false
- && !SparqlEngineDb_SqlGenerator::isVariable($tree['value']);
+ && !SparqlVariable::isVariable($tree['value']);
}//protected function isValueButNotVariableNorString($tree)
@@ -790,7 +791,7 @@
{
return $tree['type'] == 'value'
&& $tree['quoted'] === false
- && SparqlEngineDb_SqlGenerator::isVariable($tree['value'])
+ && SparqlVariable::isVariable($tree['value'])
&& isset($this->sg->arUnionVarAssignments[$this->nUnionCount][$tree['value']]);
}//protected function isVariable($tree)
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -69,6 +69,23 @@
+ protected function executePlan(&$arPatterns, &$arPlan)
+ {
+ foreach ($arPlan as $nParent => $arChildren) {
+ $base = $arPatterns[$nParent];
+ $nNextId = $nParent;
+ foreach ($arChildren as $nChild) {
+ $new = clone $base;
+ $new->addTriplePatterns($arPatterns[$nChild]->getTriplePattern());
+ $arPatterns[$nNextId] = $new;
+
+ $nNextId = $nChild;
+ }
+ }
+ }//protected function executePlan(&$arPatterns, &$arPlan)
+
+
+
/**
* Returns an array of id-value pairs determining
* which pattern IDs (array id) are deepest nested
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/ResultRenderer/Default.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -291,7 +291,7 @@
return $resultGraph;
}
- $tp = $constructPattern->getTriplePattern();
+ $tp = $constructPattern->getTriplePatterns();
$bnode = 0;
foreach ($arVartable as $value) {
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -1,4 +1,5 @@
<?php
+require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlVariable.php';
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/TypeSorter.php';
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/FilterGenerator.php';
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/SqlGeneratorException.php';
@@ -182,7 +183,7 @@
$this->arUnionVarAssignments[$this->nUnionCount] = array();
}
$this->nTriplePatternCount = 0;
- $arTriplePattern = $graphPattern->getTriplePattern();
+ $arTriplePattern = $graphPattern->getTriplePatterns();
if ($arTriplePattern != null) {
foreach ($arTriplePattern as $triplePattern) {
list (
@@ -213,7 +214,7 @@
if ($graphPattern->getUnion() !== null) {
++$this->nUnionCount;
}
- $arConstraints = $graphPattern->getConstraint();
+ $arConstraints = $graphPattern->getConstraints();
if ($arConstraints != null) {
foreach ($arConstraints as $constraint) {
$arWhere[$this->nUnionCount][count($arWhere[$this->nUnionCount]) - 1]
@@ -304,7 +305,7 @@
* SELECT part
* We do select only the columns we need for variables
*/
- if (self::isVariable($subject)) {
+ if (SparqlVariable::isVariable($subject)) {
if (isset($this->arUnionVarAssignments[$this->nUnionCount][$subject])) {
//already selected -> add equality check
$strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
@@ -334,7 +335,7 @@
}
}
- if (self::isVariable($predicate)) {
+ if (SparqlVariable::isVariable($predicate)) {
if (isset($this->arUnionVarAssignments[$this->nUnionCount][$predicate])) {
//already selected -> add equality check
$strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
@@ -362,7 +363,7 @@
}
}
- if (self::isVariable($object)) {
+ if (SparqlVariable::isVariable($object)) {
if (isset($this->arUnionVarAssignments[$this->nUnionCount][$object])) {
//already selected -> add equality check
$strWhereEquality .= ' AND ' . self::getSqlEqualityCondition(
@@ -589,7 +590,7 @@
function getSqlCondition($bject, $strTablePrefix, $strType)
{
if (is_string($bject)) {
- if (self::isVariable($bject)) {
+ if (SparqlVariable::isVariable($bject)) {
//variable?
if (self::isPreparedVariable($bject)) {
//no, not really
@@ -737,20 +738,6 @@
/**
- * Checks if the given subject/predicate/object
- * is a variable name.
- *
- * @return boolean
- */
- public static function isVariable($bject)
- {
- return is_string($bject) && strlen($bject) >= 2
- && ($bject[0] == '?' || $bject[0] == '$');
- }//public static function isVariable($bject)
-
-
-
- /**
* Checks if the given variable is a replacement
* for a prepared statement.
*
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 07:09:49 UTC (rev 457)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -730,8 +730,9 @@
}
} while ($cont);
+
if (count($trp) > 0) {
- $pattern->addTriplePatterns($trp);
+ $pattern->setTriplePatterns($trp);
}
}
Added: trunk/rdfapi-php/api/sparql/SparqlVariable.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlVariable.php (rev 0)
+++ trunk/rdfapi-php/api/sparql/SparqlVariable.php 2007-06-21 09:10:50 UTC (rev 458)
@@ -0,0 +1,39 @@
+<?php
+require_once RDFAPI_INCLUDE_DIR . '/model/Node.php';
+require_once RDFAPI_INCLUDE_DIR . '/util/Object.php';
+
+/**
+* Object representation of a SPARQL variable.
+*/
+class SparqlVariable extends Object
+{
+ public $name;
+
+ public function __construct($name)
+ {
+ $this->name = $name;
+ }
+
+
+
+ public function __toString()
+ {
+ return $this->name;
+ }
+
+
+
+ /**
+ * Checks if the given subject/predicate/object
+ * is a variable name.
+ *
+ * @return boolean
+ */
+ public static function isVariable($bject)
+ {
+ return is_string($bject) && strlen($bject) >= 2
+ && ($bject[0] == '?' || $bject[0] == '$');
+ }//public static function isVariable($bject)
+
+}
+?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-21 07:09:51
|
Revision: 457
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=457&view=rev
Author: cweiske
Date: 2007-06-21 00:09:49 -0700 (Thu, 21 Jun 2007)
Log Message:
-----------
Submitting before lightning strikes my compzter
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/GraphPattern.php
trunk/rdfapi-php/api/sparql/Query.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Added Paths:
-----------
trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
Modified: trunk/rdfapi-php/api/sparql/GraphPattern.php
===================================================================
--- trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-20 22:56:21 UTC (rev 456)
+++ trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-21 07:09:49 UTC (rev 457)
@@ -97,7 +97,7 @@
*
* @return Constraint
*/
- public function getConstraint(){
+ public function getConstraint() {
return $this->constraint;
}
@@ -106,7 +106,7 @@
*
* @return integer
*/
- public function getOptional(){
+ public function getOptional() {
return $this->optional;
}
@@ -116,7 +116,7 @@
*
* @return integer
*/
- public function getSubpatternOf(){
+ public function getSubpatternOf() {
return $this->subpatternOf;
}
@@ -125,7 +125,7 @@
*
* @return integer
*/
- public function getUnion(){
+ public function getUnion() {
return $this->union;
}
@@ -227,5 +227,30 @@
return array_unique($arVars);
}//public function getVariables()
+
+
+ /**
+ * Checks if the graph pattern is empty (contains no
+ * usable data).
+ * Occurs when using "{}" without pre- or suffixes
+ * WHERE
+ * {
+ * { ?person rdf:type foaf:Person } .
+ * }
+ *
+ * @return boolean True if the pattern is empty.
+ */
+ public function isEmpty()
+ {
+ return
+ $this->getTriplePattern() === false
+ && $this->getGraphname() === null
+ && $this->getConstraint() === false
+ && $this->getOptional() === null
+ && $this->getUnion() === null
+ && $this->getSubpatternOf() === null
+ ;
+ }//public function isEmpty()
+
}// end class: GraphPattern.php
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/sparql/Query.php
===================================================================
--- trunk/rdfapi-php/api/sparql/Query.php 2007-06-20 22:56:21 UTC (rev 456)
+++ trunk/rdfapi-php/api/sparql/Query.php 2007-06-21 07:09:49 UTC (rev 457)
@@ -289,7 +289,17 @@
$this->resultForm = strtolower($form);
}
+
/**
+ * Sets the result part.
+ *
+ * @param array Array of graph patterns
+ */
+ public function setResultPart($resultPart) {
+ $this->resultPart = $resultPart;
+ }
+
+ /**
* Adds a graph pattern to the result part.
*
* @param GraphPattern $pattern
Added: trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php (rev 0)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/QuerySimplifier.php 2007-06-21 07:09:49 UTC (rev 457)
@@ -0,0 +1,124 @@
+<?php
+
+/**
+* Simplifies ("flattens") Query objects that have graph
+* patterns which are subpatterns of other patterns.
+*
+* Example:
+* ?g ?h ?i .
+* {
+* {?person <some://typ/e> 'asd'}
+* UNION
+* {?person3 <some://typ/es2> 'three'}
+* }
+* is represented internally as three graph patterns, the latter
+* two referencing the first to be their pattern (they are subpatternOf).
+* Now this can be flattened to this which is the same:
+* {?g ?h ?i . ?person <some://typ/e> 'asd'}
+* UNION
+* {?g ?h ?i .?person3 <some://typ/es2> 'three'}
+*
+* This class does this.
+*
+* @author Christian Weiske <cw...@cw...>
+*/
+class SparqlEngineDb_QuerySimplifier
+{
+
+ /**
+ * Simplify the query by flattening out subqueries.
+ * Modifies the passed query object directly.
+ */
+ public function simplify(Query $query)
+ {
+ $arPatterns = $query->getResultPart();
+ $arPlan = $this->createPlan($arPatterns);
+ if (count($arPlan) == 0) {
+ return 0;
+ }
+
+ $this->executePlan($arPatterns, $arPlan);
+ $query->setResultPart($arPatterns);
+ }//public function simplify(Query $query)
+
+
+
+ /**
+ * Creates a plan what to do.
+ *
+ * @return array Array of arrays. Key is the parent pattern id,
+ * value is an array of subpatterns that belong to
+ * that parental pattern.
+ */
+ protected function createPlan(&$arPatterns)
+ {
+ list($arNumbers, $nNotZero) = $this->getNumbers($arPatterns);
+ if (count($arNumbers) == 0) {
+ return array();
+ }
+
+ $arPlan = array();
+
+ foreach ($arNumbers as $nId => $nNumber) {
+ $nParent = $pattern->getSubpatternOf();
+ $arPlan[$nParent][] = $nId;
+ }
+
+ return $arPlan;
+ }//protected function createPlan(&$arPatterns)
+
+
+
+ /**
+ * Returns an array of id-value pairs determining
+ * which pattern IDs (array id) are deepest nested
+ * (higher value).
+ * Array is sorted in reverse order, highest values
+ * first.
+ *
+ * @param array $arPatterns Array with GraphPatterns
+ * @return array Array with key-value pairs
+ */
+ protected function getNumbers(&$arPatterns)
+ {
+ $arNumbers = array();
+ foreach ($arPatterns as $nId => &$pattern) {
+ $nParent = $pattern->getSubpatternOf();
+ if ($nParent !== null) {
+ $arNumbers[$nId] = $arNumbers[$nParent] + 1;
+ } else {
+ $arNumbers[$nId] = 0;
+ }
+ }
+ //remove the not so interesting ones
+ foreach ($arNumbers as $nId => $nNumber) {
+ if ($nNumber == 0) {
+ unset($arNumbers[$nId]);
+ }
+ }
+
+ rsort($arNumbers);
+
+ return $arNumbers;
+ }//protected function getNumbers(&$arPatterns)
+
+
+
+ /**
+ * Removes all empty graph patterns from the
+ * array.
+ * Modifies it directly
+ */
+ protected static function dropEmpty(&$arPatterns)
+ {
+ foreach ($arPatterns as $nId => &$pattern) {
+ if ($pattern->isEmpty()) {
+ unset($arPatterns[$nId]);
+ }
+ }
+ //FIXME: continued indexes?
+ }//protected static function dropEmpty(&$arPatterns)
+
+}//class SparqlEngineDb_QuerySimplifier
+
+?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-20 22:56:21 UTC (rev 456)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-21 07:09:49 UTC (rev 457)
@@ -172,7 +172,7 @@
$this->arUnionVarAssignments[0] = array();
foreach ($this->query->getResultPart() as $graphPattern) {
- if (self::isEmptyPattern($graphPattern)) {
+ if ($graphPattern->isEmpty()) {
continue;
}
if ($graphPattern->getUnion() !== null) {
@@ -815,31 +815,6 @@
/**
- * Checks if the graph pattern is empty (contains no
- * usable data).
- * Occurs when using "{}" without pre- or suffixes
- * WHERE
- * {
- * { ?person rdf:type foaf:Person } .
- * }
- *
- * @param GraphPattern $graphPattern Graph pattern to check
- * @return boolean True if the pattern is empty.
- */
- protected static function isEmptyPattern(GraphPattern $graphPattern)
- {
- return
- $graphPattern->getTriplePattern() === false
- && $graphPattern->getGraphname() === null
- && $graphPattern->getConstraint() === false
- && $graphPattern->getOptional() === null
- && $graphPattern->getUnion() === null
- ;
- }//protected static function isEmptyPattern(GraphPattern $graphPattern)
-
-
-
- /**
* Removes all NULL values from an array and returns it.
*
* @param array $array Some array
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-20 22:56:21 UTC (rev 456)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-21 07:09:49 UTC (rev 457)
@@ -640,6 +640,7 @@
$tmpPred = "";
$obj = "";
do {
+//echo strtolower(current($this->tokens)) . "\n";
switch (strtolower(current($this->tokens))) {
case false:
$cont = false;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-20 22:56:22
|
Revision: 456
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=456&view=rev
Author: cweiske
Date: 2007-06-20 15:56:21 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
oops, debug statement
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-20 22:41:24 UTC (rev 455)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-20 22:56:21 UTC (rev 456)
@@ -640,7 +640,6 @@
$tmpPred = "";
$obj = "";
do {
-echo strtolower(current($this->tokens)) . "\n";
switch (strtolower(current($this->tokens))) {
case false:
$cont = false;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-20 22:41:26
|
Revision: 455
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=455&view=rev
Author: cweiske
Date: 2007-06-20 15:41:24 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Fix subquery parsing
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-20 21:56:27 UTC (rev 454)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-20 22:41:24 UTC (rev 455)
@@ -640,6 +640,7 @@
$tmpPred = "";
$obj = "";
do {
+echo strtolower(current($this->tokens)) . "\n";
switch (strtolower(current($this->tokens))) {
case false:
$cont = false;
@@ -680,6 +681,7 @@
$this->parseGraphPattern(
false, false, false, false, false, $pattern->getId()
);
+ break;
case "[":
$prev = true;
$tmp = $this->parseNode($this->query->getBlanknodeLabel());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-20 21:56:31
|
Revision: 454
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=454&view=rev
Author: cweiske
Date: 2007-06-20 14:56:27 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Adding support for subqueries
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/GraphPattern.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/GraphPattern.php
===================================================================
--- trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-20 21:19:09 UTC (rev 453)
+++ trunk/rdfapi-php/api/sparql/GraphPattern.php 2007-06-20 21:56:27 UTC (rev 454)
@@ -8,181 +8,208 @@
* or union graph patterns and filters.
*
* @author Tobias Gauss <tob...@we...>
-* @version $Id$
+* @version $Id$
*
* @package sparql
*/
class GraphPattern extends Object{
- /**
- * Graphname. 0 if its in the default graph.
- */
- protected $graphname;
+ /**
+ * Graphname. 0 if its in the default graph.
+ */
+ protected $graphname = null;
- /**
- * @var array The TriplePattern.
- */
- protected $triplePattern;
+ /**
+ * @var array The TriplePattern.
+ */
+ protected $triplePattern = null;
- /**
- * @var array A List of Constraints.
- */
- protected $constraint = array();
+ /**
+ * @var array A List of Constraints.
+ */
+ protected $constraint = array();
- /**
- * @var int Pointer to optional patterns.
- */
- protected $optional;
+ /**
+ * @var int Pointer to optional pattern.
+ */
+ protected $optional = null;
- /**
- * @var int Pointer to union patterns.
- */
- protected $union;
+ /**
+ * @var int Pointer to union pattern.
+ */
+ protected $union = null;
- /**
- * @var boolean TRUE if the pattern is open- FALSE if closed.
- */
- public $open;
+ /**
+ * ID of the pattern in the pattern list that
+ * this pattern is subpattern of.
+ * @var int
+ */
+ protected $subpatternOf = null;
- /**
- * @var boolean TRUE if the GraphPattern is a construct pattern.
- */
- public $isConstructPattern;
+ /**
+ * @var boolean TRUE if the pattern is open- FALSE if closed.
+ */
+ public $open = false;
+ /**
+ * @var boolean TRUE if the GraphPattern is a construct pattern.
+ */
+ public $isConstructPattern = false;
- /**
- * @var int The GraphPatterns id.
- */
- public $patternId;
+ /**
+ * @var int The GraphPatterns id.
+ */
+ public $patternId = null;
- /**
- * Constructor
- */
- public function GraphPattern(){
- $this->open = true ;
- $this->isConstructPattern = false;
- $this->constraint = false;
- $this->triplePattern = false;
- }
- /**
- * Returns the graphname.
- *
- * @return String
- */
- public function getGraphname(){
- return $this->graphname;
- }
+ /**
+ * Constructor
+ */
+ public function GraphPattern(){
+ $this->open = true ;
+ $this->isConstructPattern = false;
+ $this->constraint = false;
+ $this->triplePattern = false;
+ }
- /**
- * Returns the triple pattern of the graph pattern.
- *
- * @return Array
- */
- public function getTriplePattern(){
- return $this->triplePattern;
- }
+ /**
+ * Returns the graphname.
+ *
+ * @return String
+ */
+ public function getGraphname(){
+ return $this->graphname;
+ }
- /**
- * Returns a constraint if there is one false if not.
- *
- * @return Constraint
- */
- public function getConstraint(){
- return $this->constraint;
- }
+ /**
+ * Returns the triple pattern of the graph pattern.
+ *
+ * @return Array
+ */
+ public function getTriplePattern(){
+ return $this->triplePattern;
+ }
- /**
- * Returns a pointer to an optional graph pattern.
- *
- * @return integer
- */
- public function getOptional(){
- return $this->optional;
- }
+ /**
+ * Returns a constraint if there is one false if not.
+ *
+ * @return Constraint
+ */
+ public function getConstraint(){
+ return $this->constraint;
+ }
- /**
- * Returns a pointer to a union graph pattern.
- *
- * @return integer
- */
- public function getUnion(){
- return $this->union;
- }
+ /**
+ * Returns a pointer to an optional graph pattern.
+ *
+ * @return integer
+ */
+ public function getOptional(){
+ return $this->optional;
+ }
- /**
- * Sets the graphname.
- *
- * @param String $name
- * @return void
- */
- public function setGraphname($name){
- $this->graphname = $name;
- }
- /**
- * Adds a List of QueryTriples to the GraphPattern.
- *
- * @param array $trpP
- * @return void
- */
- public function addTriplePattern($trpP){
- $this->triplePattern = $trpP;
- }
+ /**
+ * Returns a pointer to the parent pattern this pattern
+ * is subpattern of.
+ *
+ * @return integer
+ */
+ public function getSubpatternOf(){
+ return $this->subpatternOf;
+ }
- /**
- * Adds a Constraint to the GraphPattern.
- *
- * @param Constraint $cons
- * @return void
- */
- public function addConstraint(&$cons){
- $this->constraint[] = $cons;
- }
- /**
- * Adds a pointer to an optional graphPattern.
- *
- * @param integer $pattern
- * @return void
- */
- public function addOptional($pattern){
- $this->optional = &$pattern;
- }
+ /**
+ * Returns a pointer to a union graph pattern.
+ *
+ * @return integer
+ */
+ public function getUnion(){
+ return $this->union;
+ }
- /**
- * Adds a pointer to a union graphPattern.
- *
- * @param integer $pattern
- * @return void
- */
- public function addUnion($pattern){
- $this->union = &$pattern;
- }
+ /**
+ * Sets the graphname.
+ *
+ * @param String $name
+ * @return void
+ */
+ public function setGraphname($name){
+ $this->graphname = $name;
+ }
+ /**
+ * Adds a List of QueryTriples to the GraphPattern.
+ *
+ * @param array $trpP
+ * @return void
+ */
+ public function addTriplePatterns($trpP){
+ $this->triplePattern = $trpP;
+ }
+ /**
+ * Adds a Constraint to the GraphPattern.
+ *
+ * @param Constraint $cons
+ * @return void
+ */
+ public function addConstraint(&$cons){
+ $this->constraint[] = $cons;
+ }
+ /**
+ * Adds a pointer to an optional graphPattern.
+ *
+ * @param integer $pattern
+ * @return void
+ */
+ public function addOptional($pattern){
+ $this->optional = &$pattern;
+ }
- /**
- * Sets the GraphPatterns Id.
- *
- * @param integer $id
- * @return void
- */
- public function setId($id){
- $this->patternId = $id;
- }
+ /**
+ * Adds a pointer to a union graphPattern.
+ *
+ * @param integer $pattern
+ * @return void
+ */
+ public function addUnion($pattern){
+ $this->union = &$pattern;
+ }
- /**
- * Returns the GraphPatterns id.
- *
- * @return integer
- */
- public function getId(){
- return $this->patternId;
- }
+ /**
+ * Adds a pointer to a pattern that
+ * this one is subpattern of
+ *
+ * @param integer $pattern
+ */
+ public function setSubpatternOf($pattern){
+ $this->subpatternOf = $pattern;
+ }
+ /**
+ * Sets the GraphPatterns Id.
+ *
+ * @param integer $id
+ * @return void
+ */
+ public function setId($id){
+ $this->patternId = $id;
+ }
/**
+ * Returns the GraphPatterns id.
+ *
+ * @return integer
+ */
+ public function getId(){
+ return $this->patternId;
+ }
+
+
+
+ /**
* Returns an array of all variables used in this
* graph pattern.
* All variables are listed only once (unique).
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-20 21:19:09 UTC (rev 453)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-20 21:56:27 UTC (rev 454)
@@ -549,19 +549,28 @@
* @param int $union Union graph pattern
* @param string $graph Graphname
* @param boolean $constr TRUE if the pattern is a construct pattern
+ * @param boolean $external If the parsed pattern shall be returned
+ * @param int $subpattern If the new pattern is subpattern of the
+ * pattern with the given id
* @return void
*/
- protected function parseGraphPattern($optional = false, $union = false, $graph = false,$constr = false, $external = false){
+ protected function parseGraphPattern(
+ $optional = false, $union = false, $graph = false,
+ $constr = false, $external = false, $subpattern = false
+ ){
$pattern = $this->query->getNewPattern($constr);
- if(is_int($optional)){
+ if (is_int($optional)) {
$pattern->addOptional($optional);
- }else{
+ } else {
$this->tmp = $pattern->getId();
}
- if(is_int($union)){
+ if (is_int($union)) {
$pattern->addUnion($union);
}
- if($graph != false){
+ if (is_int($subpattern)) {
+ $pattern->setSubpatternOf($subpattern);
+ }
+ if ($graph != false) {
$pattern->setGraphname($graph);
}
@@ -574,21 +583,29 @@
break;
case "union":
$this->_fastForward();
- $this->parseGraphPattern(false,$this->tmp);
+ $this->parseGraphPattern(
+ false, $this->tmp, false, false, false, $subpattern
+ );
break;
case "optional":
$this->_fastForward();
- $this->parseGraphPattern($this->tmp,false);
+ $this->parseGraphPattern(
+ $this->tmp, false, false, false, false, $subpattern
+ );
break;
case "filter":
- $this->parseConstraint($pattern,true);
+ $this->parseConstraint(
+ $pattern, true, false, false, false, $subpattern
+ );
$this->_fastForward();
break;
case ".":
$this->_fastForward();
break;
case "{":
- $this->parseGraphPattern(false,false);
+ $this->parseGraphPattern(
+ false, false, false, false, false, $subpattern
+ );
break;
case "}":
$pattern->open = false;
@@ -658,6 +675,11 @@
$pattern->open = false;
$cont = false;
break;
+ case '{':
+ //subpatterns opens
+ $this->parseGraphPattern(
+ false, false, false, false, false, $pattern->getId()
+ );
case "[":
$prev = true;
$tmp = $this->parseNode($this->query->getBlanknodeLabel());
@@ -707,7 +729,7 @@
}
} while ($cont);
if (count($trp) > 0) {
- $pattern->addTriplePattern($trp);
+ $pattern->addTriplePatterns($trp);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-20 21:19:10
|
Revision: 453
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=453&view=rev
Author: cweiske
Date: 2007-06-20 14:19:09 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Adding string magic
Modified Paths:
--------------
trunk/rdfapi-php/api/model/Blanknode.php
trunk/rdfapi-php/api/model/Literal.php
trunk/rdfapi-php/api/model/Resource.php
Modified: trunk/rdfapi-php/api/model/Blanknode.php
===================================================================
--- trunk/rdfapi-php/api/model/Blanknode.php 2007-06-20 10:33:05 UTC (rev 452)
+++ trunk/rdfapi-php/api/model/Blanknode.php 2007-06-20 21:19:09 UTC (rev 453)
@@ -104,6 +104,16 @@
return false;
}
+
+ /**
+ * Doing string magic in PHP5
+ * @return string String representation of this Blank Node
+ */
+ function __toString()
+ {
+ return $this->toString();
+ }
+
} // end: BlankNode
Modified: trunk/rdfapi-php/api/model/Literal.php
===================================================================
--- trunk/rdfapi-php/api/model/Literal.php 2007-06-20 10:33:05 UTC (rev 452)
+++ trunk/rdfapi-php/api/model/Literal.php 2007-06-20 21:19:09 UTC (rev 453)
@@ -167,6 +167,17 @@
}
+
+ /**
+ * Doing string magic in PHP5
+ * @return string String representation of this Literal
+ */
+ function __toString()
+ {
+ return $this->toString();
+ }
+
+
} // end: Literal
?>
\ No newline at end of file
Modified: trunk/rdfapi-php/api/model/Resource.php
===================================================================
--- trunk/rdfapi-php/api/model/Resource.php 2007-06-20 10:33:05 UTC (rev 452)
+++ trunk/rdfapi-php/api/model/Resource.php 2007-06-20 21:19:09 UTC (rev 453)
@@ -126,6 +126,17 @@
}
+
+
+ /**
+ * Doing string magic in PHP5
+ * @return string String representation of this Resource
+ */
+ function __toString()
+ {
+ return $this->toString();
+ }
+
}
?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-20 10:33:12
|
Revision: 452
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=452&view=rev
Author: cweiske
Date: 2007-06-20 03:33:05 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Fix change in behavior of mysql-5.0.42 that makes decimal default to 0
digits after decimal point
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php 2007-06-20 09:13:20 UTC (rev 451)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php 2007-06-20 10:33:05 UTC (rev 452)
@@ -230,7 +230,7 @@
'('
. "(($cType = '' || $cType = '$xsd#string') AND $cValue != '')"
. " OR ($cType = '$xsd#boolean' AND $cValue != 'false')"
- . " OR (($cType = '$xsd#integer' || $cType = '$xsd#double') AND CAST($cValue AS DECIMAL) != 0)"
+ . " OR (($cType = '$xsd#integer' || $cType = '$xsd#double') AND CAST($cValue AS DECIMAL(15,10)) != 0)"
//plain check for all unknown datatypes
. " OR ($cType != '' AND $cType != '$xsd#string' AND $cType != '$xsd#boolean' AND $cType != '$xsd#integer' AND $cType != '$xsd#double' AND $cValue != '')"
. ')',
@@ -304,7 +304,7 @@
. ' OR ' . $strColDatatype . ' = "' . self::$typeXsdInteger . '"'
. ')';
return $strIsNull . '('
- . 'CAST(' . $val1 . ' AS DECIMAL)'
+ . 'CAST(' . $val1 . ' AS DECIMAL(15,10))'
. ' ' . $tree['operator'] . ' '
. $val2
. $strExtra
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-20 09:13:20 UTC (rev 451)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/SqlGenerator.php 2007-06-20 10:33:05 UTC (rev 452)
@@ -628,7 +628,7 @@
if ($bject->dtype == 'http://www.w3.org/2001/XMLSchema#integer'
|| $bject->dtype == 'http://www.w3.org/2001/XMLSchema#double'
) {
- $strVariable = 'CAST(' . $strTablePrefix . '.' . $strType . ' AS DECIMAL)';
+ $strVariable = 'CAST(' . $strTablePrefix . '.' . $strType . ' AS DECIMAL(15,10))';
$strValue = $bject->getLabel();
} else {
$strVariable = $strTablePrefix . '.' . $strType;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-06-20 09:13:21
|
Revision: 451
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=451&view=rev
Author: cweiske
Date: 2007-06-20 02:13:20 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
- clarify addVar and addVariable meaning by renaming them
- Document QueryTriple better
- Throw correct exception class
Modified Paths:
--------------
trunk/rdfapi-php/api/sparql/Query.php
trunk/rdfapi-php/api/sparql/QueryTriple.php
trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php
trunk/rdfapi-php/api/sparql/SparqlParser.php
Modified: trunk/rdfapi-php/api/sparql/Query.php
===================================================================
--- trunk/rdfapi-php/api/sparql/Query.php 2007-06-19 17:04:46 UTC (rev 450)
+++ trunk/rdfapi-php/api/sparql/Query.php 2007-06-20 09:13:20 UTC (rev 451)
@@ -272,7 +272,7 @@
* @param String $var
* @return void
*/
- public function addVariable($var){
+ public function addResultVar($var){
$this->resultVars[]= $var;
$this->varLanguages[$var] = self::getLanguageTag($var);
$this->varDatatypes[$var] = $this->getDatatype($var);
@@ -367,7 +367,7 @@
* @param String $var
* @return void
*/
- public function addVar($var){
+ public function addUsedVar($var){
$this->usedVars[$var]=true;
}
Modified: trunk/rdfapi-php/api/sparql/QueryTriple.php
===================================================================
--- trunk/rdfapi-php/api/sparql/QueryTriple.php 2007-06-19 17:04:46 UTC (rev 450)
+++ trunk/rdfapi-php/api/sparql/QueryTriple.php 2007-06-20 09:13:20 UTC (rev 451)
@@ -5,73 +5,88 @@
require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/SqlGenerator.php';
/**
-* Represents a query triple.
+* Represents a query triple with subject, predicate and object.
*
* @author Tobias Gauss <tob...@we...>
* @version $Id$
*
* @package sparql
*/
-Class QueryTriple extends Object{
+class QueryTriple extends Object
+{
- /**
- * The QueryTriples Subject.
- */
- protected $subject;
+ /**
+ * The QueryTriples Subject.
+ * Can be a BlankNode or Resource, string in
+ * case of a variable
+ * @var Node/string
+ */
+ protected $subject;
- /**
- * The QueryTriples Predicate.
- */
- protected $predicate;
+ /**
+ * The QueryTriples Predicate.
+ * Normally only a Resource, string in
+ * case of a variable
+ * @var Node/string
+ */
+ protected $predicate;
- /**
- * The QueryTriples Object.
- */
- protected $object;
+ /**
+ * The QueryTriples Object.
+ * Can be BlankNode, Resource or Literal, string in
+ * case of a variable
+ * @var Node/string
+ */
+ protected $object;
- /**
- * Constructor
- */
- public function QueryTriple($sub,$pred,$ob)
- {
- $this->subject = $sub;
- $this->predicate = $pred;
- $this->object = $ob;
- }
- /**
- * Returns the Triples Subject.
- *
- * @return Node
- */
- public function getSubject()
- {
- return $this->subject;
- }
+ /**
+ * Constructor
+ *
+ * @param Node $sub Subject
+ * @param Node $pred Predicate
+ * @param Node $ob Object
+ */
+ public function QueryTriple($sub,$pred,$ob)
+ {
+ $this->subject = $sub;
+ $this->predicate = $pred;
+ $this->object = $ob;
+ }
- /**
- * Returns the Triples Predicate.
- *
- * @return Node
- */
- public function getPredicate()
- {
- return $this->predicate;
- }
+ /**
+ * Returns the Triples Subject.
+ *
+ * @return Node
+ */
+ public function getSubject()
+ {
+ return $this->subject;
+ }
- /**
- * Returns the Triples Object.
- *
- * @return Node
- */
- public function getObject()
- {
- return $this->object;
- }
+ /**
+ * Returns the Triples Predicate.
+ *
+ * @return Node
+ */
+ public function getPredicate()
+ {
+ return $this->predicate;
+ }
+ /**
+ * Returns the Triples Object.
+ *
+ * @return Node
+ */
+ public function getObject()
+ {
+ return $this->object;
+ }
+
/**
* Returns an array of all variables in this triple.
*
Modified: trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php 2007-06-19 17:04:46 UTC (rev 450)
+++ trunk/rdfapi-php/api/sparql/SparqlEngineDb/FilterGenerator.php 2007-06-20 09:13:20 UTC (rev 451)
@@ -118,8 +118,8 @@
$sql = $this->createFunction($tree);
break;
default:
- var_dump($tree);
- throw new Exception('Unsupported tree type: ' . $tree['type']);
+ //var_dump($tree);
+ throw new SparqlEngineDb_SqlGeneratorException('Unsupported tree type: ' . $tree['type']);
break;
}
Modified: trunk/rdfapi-php/api/sparql/SparqlParser.php
===================================================================
--- trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-19 17:04:46 UTC (rev 450)
+++ trunk/rdfapi-php/api/sparql/SparqlParser.php 2007-06-20 09:13:20 UTC (rev 451)
@@ -299,7 +299,7 @@
if ($this->varCheck(current($this->tokens))
| strtolower(current($this->tokens)) == '*'
){
- $this->query->addVariable(current($this->tokens));
+ $this->query->addResultVar(current($this->tokens));
if (!$this->query->getResultForm()) {
$this->query->setResultForm('select');
}
@@ -310,7 +310,7 @@
if ($this->varCheck(current($this->tokens))
| strtolower(current($this->tokens))=='*'
) {
- $this->query->addVariable(current($this->tokens));
+ $this->query->addResultVar(current($this->tokens));
} else {
throw new SparqlParserException(
"Variable or '*' expected.",
@@ -344,7 +344,7 @@
while(strtolower(current($this->tokens))!='from'& strtolower(current($this->tokens))!='where'){
$this->_fastForward();
if($this->varCheck(current($this->tokens))|$this->iriCheck(current($this->tokens))){
- $this->query->addVariable(current($this->tokens));
+ $this->query->addResultVar(current($this->tokens));
if(!$this->query->getResultForm())
$this->query->setResultForm('describe');
}
@@ -444,7 +444,7 @@
protected function varCheck($token)
{
if (isset($token[0]) && ($token{0} == '$' || $token{0} == '?')) {
- $this->query->addVar($token);
+ $this->query->addUsedVar($token);
return true;
}
return false;
@@ -1234,12 +1234,12 @@
}
if ($this->bNodeCheck($node)) {
$node = '?'.$node;
- $this->query->addVar($node);
+ $this->query->addUsedVar($node);
return $node;
}
if ($node == '[') {
$node = '?' . substr($this->query->getBlanknodeLabel(), 1);
- $this->query->addVar($node);
+ $this->query->addUsedVar($node);
$this->_fastForward();
if(current($this->tokens)!=']') {
prev($this->tokens);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|