/**
  * Build the condition (WHERE) string for a given Condition.
  * The function also expresses the single value of
  * SingletonCondition objects in the condition, which may
  * lead to additional namespaces for serializing its URI.
  *
  * @param Condition $condition
  *
  * @return string
  */
 public function convertConditionToString(Condition &$condition)
 {
     $conditionAsString = $condition->getWeakConditionString();
     if ($conditionAsString === '' && !$condition->isSafe()) {
         $swivtPageResource = Exporter::getInstance()->getSpecialNsResource('swivt', 'page');
         $conditionAsString = '?' . $this->resultVariable . ' ' . $swivtPageResource->getQName() . " ?url .\n";
     }
     $conditionAsString .= $condition->getCondition();
     if ($condition instanceof SingletonCondition) {
         // prepare for ASK, maybe rather use BIND?
         $matchElement = $condition->matchElement;
         if ($matchElement instanceof ExpElement) {
             $matchElementName = TurtleSerializer::getTurtleNameForExpElement($matchElement);
         } else {
             $matchElementName = $matchElement;
         }
         if ($matchElement instanceof ExpNsResource) {
             $condition->namespaces[$matchElement->getNamespaceId()] = $matchElement->getNamespace();
         }
         $conditionAsString = str_replace('?' . $this->resultVariable . ' ', "{$matchElementName} ", $conditionAsString);
     }
     return $conditionAsString;
 }
 /**
  * @see https://www.w3.org/TR/rdf-sparql-query/#func-bound
  *
  * Remove entities that contain a "swivt:redirectsTo" predicate
  */
 private function addFilterToRemoveEntitiesThatContainRedirectPredicate(Condition &$condition)
 {
     $rediExpElement = Exporter::getInstance()->getSpecialPropertyResource('_REDI');
     $namespaces[$rediExpElement->getNamespaceId()] = $rediExpElement->getNamespace();
     $boundVariable = '?' . $this->getNextVariable('o');
     $cogentCondition = " OPTIONAL { ?{$this->resultVariable} " . $rediExpElement->getQName() . " {$boundVariable} } .\n FILTER ( !bound( {$boundVariable} ) ) .\n";
     $condition->addNamespaces($namespaces);
     $condition->cogentConditions[$boundVariable] = $cogentCondition;
 }