/** * Checks if the given tree element is a variable * * @param array $tree Tree element * @return boolean True if the element is a variable */ protected function isVariable($tree) { require_once 'Erfurt/Sparql/Variable.php'; return $tree['type'] == 'value' && $tree['quoted'] === false && Erfurt_Sparql_Variable::isVariable($tree['value']) && isset($this->sg->arUnionVarAssignments[$this->nUnionCount][$tree['value']]); }
/** * Returns an array of all variables in this triple. * * @return array Array of variable names. */ public function getVariables() { $arVars = array(); require_once 'Erfurt/Sparql/Variable.php'; if (Erfurt_Sparql_Variable::isVariable($this->_subject)) { $arVars[] = $this->_subject; } if (Erfurt_Sparql_Variable::isVariable($this->_predicate)) { $arVars[] = $this->_predicate; } if (Erfurt_Sparql_Variable::isVariable($this->_object)) { $arVars[] = $this->_object; } return $arVars; }
/** * Creates an SQL statement that checks for the value * of some subject/predicate/object * * @param mixed $bject subject|predicate|object * @param string $strTablePrefix Table prefix (e.g. "t0") * @param string $strType Type of $bject ('subject'|'predicate'|'object') * @return string Part of the SQL query (prefixed with AND) */ function getSqlCondition($bject, $strTablePrefix, $strType) { require_once 'Erfurt/Sparql/Variable.php'; if (is_string($bject)) { if (Erfurt_Sparql_Variable::isVariable($bject)) { //variable? if (self::isPreparedVariable($bject)) { //no, not really $value = $this->getPreparedVariablePlaceholder($bject); } else { //yes return null; } } else { $value = $this->_qstr($bject); } //literal return ' AND ' . $strTablePrefix . '.' . $strType . '=' . $value; } if ($bject instanceof Erfurt_Rdf_Resource && $bject->isBlankNode()) { //Blank node require_once 'Erfurt/Sparql/EngineDb/SqlGeneratorException.php'; throw new Erfurt_Sparql_EngineDb_SqlGeneratorException('FIXME: Querying for blank nodes not supported'); } else { if ($bject instanceof Erfurt_Rdf_Resource) { //Resource $r = ' AND ' . $strTablePrefix . '.' . $strType . '=' . $this->_qstr($bject->getUri()); if ($strType !== 'p') { $r .= ' AND ' . $strTablePrefix . '.' . $strType . 't=0'; } return $r; } else { if ($bject instanceof Erfurt_Rdf_Literal) { //Literal //I'm doubling Filter code here, but what the hell $strColDatatype = $strTablePrefix . '.od'; if ($bject->getDatatype() == 'http://www.w3.org/2001/XMLSchema#integer' || $bject->getdatatype() == 'http://www.w3.org/2001/XMLSchema#double') { $strVariable = 'CAST(' . $strTablePrefix . '.' . $strType . ' AS DECIMAL(15,10))'; $strValue = $bject->getLabel(); } else { $strVariable = $strTablePrefix . '.' . $strType; $strValue = $this->_qstr($bject->getLabel()); } $r = ' AND ' . $strVariable . '=' . $strValue; if ($strType !== 'p') { $r .= ' AND ' . $strTablePrefix . '.' . $strType . 't=2'; } if ($strType == 'o') { if ($bject->getDatatype() == '' || $bject->getDatatype() == 'http://www.w3.org/2001/XMLSchema#string') { //string $r .= ' AND (' . $strColDatatype . '=""' . ' OR ' . $strColDatatype . '="http://www.w3.org/2001/XMLSchema#string"' . ')'; } else { $r .= ' AND ' . $strColDatatype . '="' . $bject->getDatatype() . '"'; } } if ($bject->getLanguage() !== false) { $strColLanguage = $strTablePrefix . '.ol'; $r .= ' AND ' . $strColLanguage . '=' . $this->_qstr($bject->getLanguage()); } else { $strColLanguage = $strTablePrefix . '.ol'; $r .= ' AND ' . $strColLanguage . '=""'; } return $r; } else { require_once 'Erfurt/Sparql/EngineDb/SqlGeneratorException.php'; throw new Erfurt_Sparql_EngineDb_SqlGeneratorException('Unsupported sentence part: ' . get_class($bject)); } } } }