Source for file Default.php
Documentation is available at Default.php
require_once RDFAPI_INCLUDE_DIR .
'sparql/SparqlEngineDb/ResultRenderer.php';
* Default RAP result renderer.
* @author Christian Weiske <cweiske@cweiske.de>
* Defines the methods needed to create the types
* Key is the type (e.g. "s" for subject), and
* value the method's name.
'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.
$this->sg =
$engine->getSqlGenerator();
$strResultForm =
$this->query->getResultForm();
switch ($strResultForm) {
//some result forms need more modification
switch ($strResultForm) {
$this->query->getConstructPattern()
$arResult =
$this->describeGraph($arResult);
if (count($arRecordSets) >
1) {
'More than one result set for a '
.
$strResultForm .
' query!'
$dbRecordSet =
reset($arRecordSets);
foreach ($dbRecordSet as $row) {
$nCount =
intval($row['count']);
if ($strResultForm ==
'ask') {
throw
new Exception('Unsupported result form: ' .
$strResultForm);
}//public function convertFromDbResults($arRecordSets, Query $query, SparqlEngineDb $engine)
foreach ($arRecordSets as $dbRecordSet) {
}//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
switch ($strResultForm) {
$arResultVars =
$this->query->getConstructPatternVariables();
$arResultVars =
$this->query->getResultVars();
$arResultVars =
array_keys($this->sg->arVarAssignments);
//work around bug in adodb:
// ADORecordSet_empty does not implement php5 iterators
if ($dbRecordSet->RowCount() <=
0) {
foreach ($dbRecordSet as $row) {
foreach ($arResultVars as $strVarName) {
if (!isset
($this->sg->arVarAssignments[$strVarName])) {
//variable is in select, but not in result (test: q-select-2)
$arResultRow[$strVarName] =
'';
$arVarSettings =
$this->sg->arVarAssignments[$strVarName];
$arResultRow[$strVarName] =
$this->$strMethod($dbRecordSet, $arVarSettings[0], $strVarName);
$arResult[] =
$arResultRow;
}//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)
* 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
if ($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_value']] ===
null) {
//FIXME: should be NULL, but doesn't pass test
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
$subject =
new Resource ($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_value']]);
$subject =
new BlankNode($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_value']]);
}//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
if ($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_value']] ===
null) {
//FIXME: should be NULL, but doesn't pass test
$predicate =
new Resource ($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
if ($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_value']] ===
null) {
//FIXME: should be NULL, but doesn't pass test
switch ($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_is']]) {
$object =
new Resource ($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_value']]);
$object =
new BlankNode($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_value']]);
$dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_value']],
$dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_lang']]
if ($dbRecordSet->fields[$strVarBase .
'.' .
$this->sg->arVarAssignments[$strVarName]['sql_type']]) {
$object->setDatatype($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
$tp =
$constructPattern->getTriplePattern();
foreach ($arVartable as $value) {
foreach ($tp as $triple) {
$sub =
$triple->getSubject();
$pred =
$triple->getPredicate();
$obj =
$triple->getObject();
if ($sub !==
"" &&
$pred !==
"" &&
$obj !==
"") {
$resultGraph->add(new Statement($sub,$pred,$obj));
}//protected function constructGraph($arVartable, $constructPattern)
}//class SparqlEngineDb_ResultRenderer_Default implements SparqlEngineDb_ResultRenderer
Documentation generated on Fri, 1 Jun 2007 16:49:00 +0200 by phpDocumentor 1.3.2