Example #1
0
 /**
  *   Simplify the query by flattening out subqueries.
  *   Modifies the passed query object directly.
  */
 public function simplify(Query $query)
 {
     $arPatterns = $query->getResultPart();
     self::dropEmpty($arPatterns);
     $arPlan = $this->createPlan($arPatterns);
     if (count($arPlan) == 0) {
         $query->setResultPart($arPatterns);
         return 0;
     }
     $this->executePlan($arPatterns, $arPlan);
     $query->setResultPart($arPatterns);
 }
Example #2
0
 /**
  * Matches all graph Patterns against the dataset and generates an array which
  * contains the result sets for every given GraphPattern.
  *
  * @param  Array      $graphlist   the graphlist which contains the names of the named
  *                    graphs which has to be queried.
  * @return Array
  */
 protected function matchPatterns($graphlist)
 {
     $patternlist = array();
     // get the result part from the query
     $resultPart = $this->query->getResultPart();
     // for each GrapPattern in the result part
     if ($resultPart) {
         foreach ($resultPart as $graphPattern) {
             $this->matchPattern($patternlist, $graphlist, $graphPattern);
         }
     }
     return $patternlist;
 }
Example #3
0
 /**
  *   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;
 }