Example #1
0
 /**
  * Constructs a result graph.
  *
  * @param  Array         $vartable 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($vartable, $constructPattern)
 {
     $resultGraph = new MemModel();
     if (!$vartable) {
         return $resultGraph;
     }
     $tp = $constructPattern->getTriplePattern();
     $bnode = 0;
     foreach ($vartable 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;
 }