Example #1
0
 /**
  *   Query the database with the given SPARQL query.
  *
  *
  *   @param  Dataset       $dataset    RDF Dataset
  *   @param  Query         $query      Parsed SPARQL query
  *   @param  string        $resultform Result form. If set to 'xml' the result will be
  *                                   SPARQL Query Results XML Format as described in http://www.w3.org/TR/rdf-sparql-XMLres/ .
  *
  *   @return array/string  array of triple arrays, or XML. Format depends on
  *                                   $resultform parameter.
  */
 public function queryModel($dataset, Query $query, $resultform = false)
 {
     if (isset($GLOBALS['debugSparql']) && $GLOBALS['debugSparql']) {
         echo "\n" . 'SPARQL query: ' . $query->getQueryString() . "\n";
     }
     $this->query = $query;
     $this->dataset = $dataset;
     $qsimp = new SparqlEngineDb_QuerySimplifier();
     $qsimp->simplify($this->query);
     $this->sg = new SparqlEngineDb_SqlGenerator($this->query, $this->dbConn, $this->arModelIds);
     $this->rc = new SparqlEngineDb_ResultConverter($this->query, $this->sg, $this);
     $this->ts = new SparqlEngineDb_TypeSorter($this->query, $this->dbConn);
     $this->setOptions();
     if ($this->query->isEmpty()) {
         $vartable[0]['patternResult'] = null;
         return $this->returnResult($vartable, $resultform);
     }
     $arSqls = $this->sg->createSql();
     $this->ts->setData($this->sg);
     return SparqlEngineDb_ResultConverter::convertFromDbResults($this->queryMultiple($this->ts->getOrderifiedSqls($arSqls)), $this, $resultform);
 }
 function testParseNested()
 {
     //echo "<b>Nested queries tests</b><br/>\n";
     foreach ($GLOBALS['testSparqlParserTestsNested'] as $arNestedTest) {
         list($query, $strExpected) = $arNestedTest;
         $p = new SparqlParser();
         $q = $p->parse($query);
         $qs = new SparqlEngineDb_QuerySimplifier();
         $qs->simplify($q);
         $strRendResult = SparqlTestHelper::renderResult($q);
         $this->assertEqual($strExpected, $strRendResult);
     }
 }