Example #1
0
 /**
  * Get the output string for a query in debugging mode.
  *
  * @param Query $query
  *
  * @return string
  */
 public function getDebugQueryResult(Query $query)
 {
     $this->sortkeys = $query->sortkeys;
     $this->compoundConditionBuilder->setSortKeys($this->sortkeys);
     $sparqlCondition = $this->compoundConditionBuilder->buildCondition($query->getDescription());
     $query->addErrors($this->compoundConditionBuilder->getErrors());
     $entries = array();
     if ($sparqlCondition instanceof SingletonCondition) {
         if ($sparqlCondition->condition === '') {
             // all URIs exist, no querying
             $sparql = 'None (no conditions).';
         } else {
             $condition = $this->compoundConditionBuilder->convertConditionToString($sparqlCondition);
             $namespaces = $sparqlCondition->namespaces;
             $sparql = $this->connection->getSparqlForAsk($condition, $namespaces);
         }
     } elseif ($sparqlCondition instanceof FalseCondition) {
         $sparql = 'None (conditions can not be satisfied by anything).';
     } else {
         $condition = $this->compoundConditionBuilder->convertConditionToString($sparqlCondition);
         $namespaces = $sparqlCondition->namespaces;
         $options = $this->getOptions($query, $sparqlCondition);
         $options['DISTINCT'] = true;
         $sparql = $this->connection->getSparqlForSelect('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces);
     }
     $sparql = str_replace(array('[', ':', ' '), array('[', ':', ' '), $sparql);
     $entries['SPARQL Query'] = '<div class="smwpre">' . $sparql . '</div>';
     return DebugOutputFormatter::formatOutputFor('SPARQLStore', $entries, $query);
 }
 /**
  * @since  2.0
  * @param  Query $query
  *
  * @return QueryResult|string
  */
 public function getQueryResult(Query $query)
 {
     if ((!$this->engineOptions->get('smwgIgnoreQueryErrors') || $query->getDescription() instanceof ThingDescription) && $query->querymode != Query::MODE_DEBUG && count($query->getErrors()) > 0) {
         return $this->queryResultFactory->newEmptyQueryResult($query, false);
     }
     // don't query, but return something to the printer
     if ($query->querymode == Query::MODE_NONE || $query->getLimit() < 1) {
         return $this->queryResultFactory->newEmptyQueryResult($query, true);
     }
     $this->compoundConditionBuilder->setSortKeys($query->sortkeys);
     $compoundCondition = $this->compoundConditionBuilder->buildCondition($query->getDescription());
     $query->addErrors($this->compoundConditionBuilder->getErrors());
     if ($query->querymode == Query::MODE_DEBUG) {
         return $this->getDebugQueryResult($query, $compoundCondition);
     } elseif ($query->querymode == Query::MODE_COUNT) {
         return $this->getCountQueryResult($query, $compoundCondition);
     }
     return $this->getInstanceQueryResult($query, $compoundCondition);
 }
 /**
  * '[[LocatedIn.MemberOf::Wonderland]]'
  */
 public function testPropertyChain()
 {
     $description = new SomeProperty(DIProperty::newFromUserLabel('LocatedIn'), new SomeProperty(DIProperty::newFromUserLabel('MemberOf'), new ValueDescription(new DIWikiPage('Wonderland', NS_MAIN, ''), DIProperty::newFromUserLabel('MemberOf'), SMW_CMP_EQ)));
     $instance = new CompoundConditionBuilder();
     $condition = $instance->buildCondition($description);
     $this->assertInstanceOf('\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition', $condition);
     $expectedConditionString = $this->stringBuilder->addString('?result property:LocatedIn ?v1 .')->addNewLine()->addString('{ ?v1 property:MemberOf wiki:Wonderland .')->addNewLine()->addString('}')->addNewLine()->getString();
     $this->assertEquals($expectedConditionString, $instance->convertConditionToString($condition));
 }
 public function testSingletonLikeConditionForSolitaryWpgValue()
 {
     $description = new ValueDescription(new DIWikiPage("Foo*", NS_MAIN), null, SMW_CMP_LIKE);
     $instance = new CompoundConditionBuilder();
     $condition = $instance->buildCondition($description);
     $this->assertInstanceOf('\\SMW\\SPARQLStore\\QueryEngine\\Condition\\SingletonCondition', $condition);
     $expectedConditionString = $this->stringBuilder->addString('FILTER( regex( ?v1, "^Foo.*$", "s") )')->addNewLine()->addString('?result swivt:wikiPageSortKey ?v1 .')->addNewLine()->getString();
     $this->assertEquals($expectedConditionString, $instance->convertConditionToString($condition));
 }