/**
  * Create a Condition from a ConceptDescription
  *
  * @param ConceptDescription $description
  * @param string $joinVariable
  * @param DIProperty|null $orderByProperty
  *
  * @return Condition
  */
 public function buildCondition(Description $description, $joinVariable, $orderByProperty = null)
 {
     $conceptDescription = $this->getConceptDescription($description->getConcept());
     if ($conceptDescription === '') {
         return new FalseCondition();
     }
     return $this->compoundConditionBuilder->mapDescriptionToCondition($conceptDescription, $joinVariable, $orderByProperty);
 }
 /**
  * @since 2.2
  *
  * @return QueryEngine
  */
 public function newMasterQueryEngine()
 {
     $circularReferenceGuard = new CircularReferenceGuard('sparql-query');
     $circularReferenceGuard->setMaxRecursionDepth(2);
     $compoundConditionBuilder = new CompoundConditionBuilder();
     $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard);
     $queryEngine = new QueryEngine($this->store->getConnection('sparql'), $compoundConditionBuilder, new QueryResultFactory($this->store), new EngineOptions());
     return $queryEngine;
 }
 /**
  * Create an Condition from a NamespaceDescription
  *
  * @param NamespaceDescription $description
  * @param string $joinVariable
  * @param DIProperty|null $orderByProperty
  *
  * @return Condition
  */
 public function buildCondition(Description $description, $joinVariable, $orderByProperty = null)
 {
     $nspropExpElement = $this->exporter->getSpecialNsResource('swivt', 'wikiNamespace');
     $nsExpElement = new ExpLiteral(strval($description->getNamespace()), 'http://www.w3.org/2001/XMLSchema#integer');
     $nsName = TurtleSerializer::getTurtleNameForExpElement($nsExpElement);
     $condition = "{ ?{$joinVariable} " . $nspropExpElement->getQName() . " {$nsName} . }\n";
     $result = new WhereCondition($condition, true, array());
     $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, DataItem::TYPE_WIKIPAGE);
     return $result;
 }
 /**
  * @dataProvider namespaceProvider
  */
 public function testNamespaceCondition($description, $orderByProperty, $expectedConditionType, $expectedConditionString)
 {
     $resultVariable = 'result';
     $compoundConditionBuilder = new CompoundConditionBuilder();
     $compoundConditionBuilder->setResultVariable($resultVariable);
     $instance = new NamespaceConditionBuilder();
     $instance->setCompoundConditionBuilder($compoundConditionBuilder);
     $condition = $instance->buildCondition($description, $resultVariable, $orderByProperty);
     $this->assertInstanceOf($expectedConditionType, $condition);
     $this->assertEquals($expectedConditionString, $compoundConditionBuilder->convertConditionToString($condition));
 }
 /**
  * @dataProvider comparatorProvider
  */
 public function testValueConditionForDifferentComparators($description, $expectedConditionType, $expectedConditionString)
 {
     $resultVariable = 'result';
     $compoundConditionBuilder = new CompoundConditionBuilder();
     $compoundConditionBuilder->setResultVariable($resultVariable);
     $compoundConditionBuilder->setJoinVariable($resultVariable);
     $instance = new ValueDescriptionInterpreter($compoundConditionBuilder);
     $condition = $instance->interpretDescription($description);
     $this->assertInstanceOf($expectedConditionType, $condition);
     $this->assertEquals($expectedConditionString, $compoundConditionBuilder->convertConditionToString($condition));
 }
 /**
  * Create an Condition from an ClassDescription.
  *
  * @param ClassDescription $description
  * @param string $joinVariable
  * @param DIProperty|null $orderByProperty
  *
  * @return Condition
  */
 public function buildCondition(Description $description, $joinVariable, $orderByProperty = null)
 {
     list($condition, $namespaces) = $this->mapCategoriesToConditionElements($description->getCategories(), $joinVariable);
     // empty disjunction: always false, no results to order
     if ($condition === '') {
         return new FalseCondition();
     }
     $result = new WhereCondition($condition, true, $namespaces);
     $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, DataItem::TYPE_WIKIPAGE);
     return $result;
 }
 /**
  * @since 2.2
  *
  * @return QueryEngine
  */
 public function newMasterQueryEngine()
 {
     $engineOptions = new EngineOptions();
     $hierarchyFinder = new HierarchyFinder($this->store, ApplicationFactory::getInstance()->newCacheFactory()->newFixedInMemoryCache(500));
     $circularReferenceGuard = new CircularReferenceGuard('sparql-query');
     $circularReferenceGuard->setMaxRecursionDepth(2);
     $compoundConditionBuilder = new CompoundConditionBuilder($engineOptions);
     $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard);
     $compoundConditionBuilder->setHierarchyFinder($hierarchyFinder);
     $queryEngine = new QueryEngine($this->store->getConnection('sparql'), $compoundConditionBuilder, new QueryResultFactory($this->store), $engineOptions);
     return $queryEngine;
 }
 /**
  * @dataProvider descriptionProvider
  */
 public function testThingDescriptionInterpreter($description, $orderByProperty, $expectedConditionType, $expectedConditionString)
 {
     $resultVariable = 'result';
     $compoundConditionBuilder = new CompoundConditionBuilder();
     $compoundConditionBuilder->setResultVariable($resultVariable);
     $compoundConditionBuilder->setJoinVariable($resultVariable);
     $compoundConditionBuilder->setOrderByProperty($orderByProperty);
     $instance = new ThingDescriptionInterpreter($compoundConditionBuilder);
     $condition = $instance->interpretDescription($description);
     $this->assertInstanceOf($expectedConditionType, $condition);
     $this->assertEquals($expectedConditionString, $compoundConditionBuilder->convertConditionToString($condition));
 }
 /**
  * @since 2.2
  *
  * @return QueryEngine
  */
 public function newMasterQueryEngine()
 {
     $engineOptions = new EngineOptions();
     $circularReferenceGuard = new CircularReferenceGuard('sparql-queryengine');
     $circularReferenceGuard->setMaxRecursionDepth(2);
     $compoundConditionBuilder = new CompoundConditionBuilder(new DescriptionInterpreterFactory(), $engineOptions);
     $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard);
     $compoundConditionBuilder->setPropertyHierarchyLookup($this->applicationFactory->newPropertyHierarchyLookup());
     $queryEngine = new QueryEngine($this->store->getConnection('sparql'), $compoundConditionBuilder, new QueryResultFactory($this->store), $engineOptions);
     $cachedQueryResultPrefetcher = ApplicationFactory::getInstance()->singleton('CachedQueryResultPrefetcher');
     $cachedQueryResultPrefetcher->setQueryEngine($queryEngine);
     return $cachedQueryResultPrefetcher;
 }
 /**
  * @since 2.2
  *
  * @return QueryEngine
  */
 public function newMasterQueryEngine()
 {
     $engineOptions = new EngineOptions();
     $propertyHierarchyLookup = new PropertyHierarchyLookup($this->store, $this->applicationFactory->newCacheFactory()->newFixedInMemoryCache(500));
     $propertyHierarchyLookup->setSubcategoryDepth($this->applicationFactory->getSettings()->get('smwgQSubcategoryDepth'));
     $propertyHierarchyLookup->setSubpropertyDepth($this->applicationFactory->getSettings()->get('smwgQSubpropertyDepth'));
     $circularReferenceGuard = new CircularReferenceGuard('sparql-query');
     $circularReferenceGuard->setMaxRecursionDepth(2);
     $compoundConditionBuilder = new CompoundConditionBuilder($engineOptions);
     $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard);
     $compoundConditionBuilder->setPropertyHierarchyLookup($propertyHierarchyLookup);
     $queryEngine = new QueryEngine($this->store->getConnection('sparql'), $compoundConditionBuilder, new QueryResultFactory($this->store), $engineOptions);
     return $queryEngine;
 }
 private function getDebugQueryResult(Query $query, Condition $compoundCondition)
 {
     $entries = array();
     if ($this->isSingletonConditionWithElementMatch($compoundCondition)) {
         if ($compoundCondition->condition === '') {
             // all URIs exist, no querying
             $sparql = 'None (no conditions).';
         } else {
             $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
             $namespaces = $compoundCondition->namespaces;
             $sparql = $this->connection->getSparqlForAsk($condition, $namespaces);
         }
     } elseif ($compoundCondition instanceof FalseCondition) {
         $sparql = 'None (conditions can not be satisfied by anything).';
     } else {
         $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
         $namespaces = $compoundCondition->namespaces;
         $options = $this->getOptions($query, $compoundCondition);
         $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);
 }
 public function testHierarchyPattern()
 {
     $category = new DIWikiPage('Foo', NS_CATEGORY);
     $categoryName = \SMWTurtleSerializer::getTurtleNameForExpElement(\SMWExporter::getInstance()->getResourceElementForWikiPage($category));
     $propertyHierarchyLookup = $this->getMockBuilder('\\SMW\\PropertyHierarchyLookup')->disableOriginalConstructor()->getMock();
     $propertyHierarchyLookup->expects($this->once())->method('hasSubcategoryFor')->with($this->equalTo($category))->will($this->returnValue(true));
     $resultVariable = 'result';
     $compoundConditionBuilder = new CompoundConditionBuilder($this->descriptionInterpreterFactory);
     $compoundConditionBuilder->setPropertyHierarchyLookup($propertyHierarchyLookup);
     $compoundConditionBuilder->setResultVariable($resultVariable);
     $compoundConditionBuilder->setJoinVariable($resultVariable);
     $instance = new ClassDescriptionInterpreter($compoundConditionBuilder);
     $condition = $instance->interpretDescription(new ClassDescription($category));
     $expected = UtilityFactory::getInstance()->newStringBuilder()->addString('{')->addNewLine()->addString("?sc1 rdfs:subClassOf* {$categoryName} .")->addNewLine()->addString('?result rdf:type ?sc1 . }')->addNewLine()->getString();
     $this->assertEquals($expected, $compoundConditionBuilder->convertConditionToString($condition));
 }
Exemple #13
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;
     $sparqlCondition = $this->compoundConditionBuilder->setSortKeys($this->sortkeys)->buildCondition($query->getDescription());
     $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('&#x005B;', '&#x003A;', '&#x0020;'), $sparql);
     $entries['SPARQL Query'] = "<pre>{$sparql}</pre>";
     return QueryOutputFormatter::formatDebugOutput('SPARQLStore', $entries, $query);
 }
 public function testHierarchyPattern()
 {
     $property = new DIProperty('Foo');
     $propertyHierarchyExaminer = $this->getMockBuilder('\\SMW\\PropertyHierarchyExaminer')->disableOriginalConstructor()->getMock();
     $propertyHierarchyExaminer->expects($this->once())->method('hasSubpropertyFor')->with($this->equalTo($property))->will($this->returnValue(true));
     $resultVariable = 'result';
     $compoundConditionBuilder = new CompoundConditionBuilder();
     $compoundConditionBuilder->setPropertyHierarchyExaminer($propertyHierarchyExaminer);
     $compoundConditionBuilder->setResultVariable($resultVariable);
     $compoundConditionBuilder->setJoinVariable($resultVariable);
     $instance = new SomePropertyInterpreter($compoundConditionBuilder);
     $description = new SomeProperty($property, new ThingDescription());
     $condition = $instance->interpretDescription($description);
     $expected = UtilityFactory::getInstance()->newStringBuilder()->addString('?result ?sp2 ?v1 .')->addNewLine()->addString('{ ')->addNewLine()->addString('?sp2 rdfs:subPropertyOf* property:Foo .')->addNewLine()->addString('}')->addNewLine()->getString();
     $this->assertEquals($expected, $compoundConditionBuilder->convertConditionToString($condition));
 }
 public function testConceptConditionBuilderForAnyValueConceptUsingMockedStore()
 {
     $semanticData = $this->getMockBuilder('\\SMW\\SemanticData')->disableOriginalConstructor()->getMock();
     $semanticData->expects($this->once())->method('getPropertyValues')->with($this->equalTo(new DIProperty('_CONC')))->will($this->returnValue(array(new DIConcept('[[Foo::+]]', 'Bar', 1, 0, 0))));
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $store->expects($this->any())->method('getSemanticData')->with($this->equalTo(new DIWikiPage('Foo', SMW_NS_CONCEPT)))->will($this->returnValue($semanticData));
     $this->applicationFactory = ApplicationFactory::getInstance();
     $this->applicationFactory->registerObject('Store', $store);
     $description = new ConceptDescription(new DIWikiPage('Foo', SMW_NS_CONCEPT));
     $orderByProperty = null;
     $resultVariable = 'result';
     $compoundConditionBuilder = new CompoundConditionBuilder();
     $compoundConditionBuilder->setResultVariable($resultVariable);
     $instance = new ConceptConditionBuilder();
     $instance->setCompoundConditionBuilder($compoundConditionBuilder);
     $condition = $instance->buildCondition($description, $resultVariable, $orderByProperty);
     $expectedConditionString = UtilityFactory::getInstance()->newStringBuilder()->addString('?result property:Foo ?v1 .')->addNewLine()->getString();
     $this->assertInstanceOf('\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition', $condition);
     $this->assertEquals($expectedConditionString, $compoundConditionBuilder->convertConditionToString($condition));
 }
 /**
  * @since 2.2
  *
  * {@inheritDoc}
  */
 public function interpretDescription(Description $description)
 {
     $joinVariable = $this->compoundConditionBuilder->getJoinVariable();
     $orderByProperty = $this->compoundConditionBuilder->getOrderByProperty();
     $conceptDescription = $this->getConceptDescription($description->getConcept());
     if ($conceptDescription === '') {
         return new FalseCondition();
     }
     $hash = 'concept-' . $conceptDescription->getQueryString();
     $this->compoundConditionBuilder->getCircularReferenceGuard()->mark($hash);
     if ($this->compoundConditionBuilder->getCircularReferenceGuard()->isCircularByRecursionFor($hash)) {
         $this->compoundConditionBuilder->addError(wfMessage('smw-query-condition-circular', $conceptDescription->getQueryString())->text());
         return new FalseCondition();
     }
     $this->compoundConditionBuilder->setJoinVariable($joinVariable);
     $this->compoundConditionBuilder->setOrderByProperty($orderByProperty);
     $condition = $this->compoundConditionBuilder->mapDescriptionToCondition($conceptDescription);
     $this->compoundConditionBuilder->getCircularReferenceGuard()->unmark($hash);
     return $condition;
 }
 private function doResolveInnerConditionRecursively(DIProperty $property, Description $description)
 {
     $innerOrderByProperty = null;
     // Find out if we should order by the values of this property
     if (array_key_exists($property->getKey(), $this->compoundConditionBuilder->getSortKeys())) {
         $innerOrderByProperty = $property;
     }
     // Prepare inner condition
     $innerJoinVariable = $this->compoundConditionBuilder->getNextVariable();
     $innerCondition = $this->compoundConditionBuilder->mapDescriptionToCondition($description, $innerJoinVariable, $innerOrderByProperty);
     return array($innerOrderByProperty, $innerCondition, $innerJoinVariable);
 }
 private function doResolveSubDescriptionsRecursively($subDescriptions, $joinVariable)
 {
     // Using a stdClass as data container for simpler handling in follow-up tasks
     // and as the class is not exposed publicly we don't need to create
     // an extra "real" class to manage its elements
     $subConditionElements = new \stdClass();
     $subConditionElements->condition = '';
     $subConditionElements->filter = '';
     $subConditionElements->singletonMatchElement = null;
     $namespaces = $weakConditions = $orderVariables = array();
     $singletonMatchElementName = '';
     $hasSafeSubconditions = false;
     foreach ($subDescriptions as $subDescription) {
         $this->compoundConditionBuilder->setJoinVariable($joinVariable);
         $this->compoundConditionBuilder->setOrderByProperty(null);
         $subCondition = $this->compoundConditionBuilder->mapDescriptionToCondition($subDescription);
         if ($subCondition instanceof FalseCondition) {
             return new FalseCondition();
         } elseif ($subCondition instanceof TrueCondition) {
             // ignore true conditions in a conjunction
         } elseif ($subCondition instanceof WhereCondition) {
             $subConditionElements->condition .= $subCondition->condition;
         } elseif ($subCondition instanceof FilterCondition) {
             $subConditionElements->filter .= ($subConditionElements->filter ? ' && ' : '') . $subCondition->filter;
         } elseif ($subCondition instanceof SingletonCondition) {
             $matchElement = $subCondition->matchElement;
             if ($matchElement instanceof ExpElement) {
                 $matchElementName = TurtleSerializer::getTurtleNameForExpElement($matchElement);
             } else {
                 $matchElementName = $matchElement;
             }
             if ($matchElement instanceof ExpNsResource) {
                 $namespaces[$matchElement->getNamespaceId()] = $matchElement->getNamespace();
             }
             if ($subConditionElements->singletonMatchElement !== null && $singletonMatchElementName !== $matchElementName) {
                 return new FalseCondition();
             }
             $subConditionElements->condition .= $subCondition->condition;
             $subConditionElements->singletonMatchElement = $subCondition->matchElement;
             $singletonMatchElementName = $matchElementName;
         }
         $hasSafeSubconditions = $hasSafeSubconditions || $subCondition->isSafe();
         $namespaces = array_merge($namespaces, $subCondition->namespaces);
         $weakConditions = array_merge($weakConditions, $subCondition->weakConditions);
         $orderVariables = array_merge($orderVariables, $subCondition->orderVariables);
     }
     $subConditionElements->hasSafeSubconditions = $hasSafeSubconditions;
     $subConditionElements->namespaces = $namespaces;
     $subConditionElements->weakConditions = $weakConditions;
     $subConditionElements->orderVariables = $orderVariables;
     return $subConditionElements;
 }
 /**
  * @note rdfs:subPropertyOf* where * means a property path of arbitrary length
  * can be found using the "zero or more" will resolve the complete path
  *
  * @see http://www.w3.org/TR/sparql11-query/#propertypath-arbitrary-length
  */
 private function tryToAddPropertyPathForSaturatedHierarchy(&$condition, DIProperty $property, &$propertyName)
 {
     if (!$this->compoundConditionBuilder->canUseQFeature(SMW_SPARQL_QF_SUBP) || !$property->isUserDefined()) {
         return null;
     }
     if ($this->compoundConditionBuilder->getPropertyHierarchyLookup() == null || !$this->compoundConditionBuilder->getPropertyHierarchyLookup()->hasSubpropertyFor($property)) {
         return null;
     }
     $subPropExpElement = $this->exporter->getSpecialPropertyResource('_SUBP', SMW_NS_PROPERTY);
     $propertyByVariable = '?' . $this->compoundConditionBuilder->getNextVariable('sp');
     $condition->weakConditions[$propertyName] = "\n" . "{$propertyByVariable} " . $subPropExpElement->getQName() . "*" . " {$propertyName} .\n" . "";
     $propertyName = $propertyByVariable;
 }
 private function tryToAddClassHierarchyPattern($category, &$categoryExpName)
 {
     if (!$this->compoundConditionBuilder->canUseQFeature(SMW_SPARQL_QF_SUBC)) {
         return '';
     }
     if ($this->compoundConditionBuilder->getPropertyHierarchyLookup() === null || !$this->compoundConditionBuilder->getPropertyHierarchyLookup()->hasSubcategoryFor($category)) {
         return '';
     }
     $subClassExpElement = $this->exporter->getSpecialPropertyResource('_SUBC');
     $classHierarchyByVariable = "?" . $this->compoundConditionBuilder->getNextVariable('sc');
     $condition = "{$classHierarchyByVariable} " . $subClassExpElement->getQName() . "*" . " {$categoryExpName} .\n";
     $categoryExpName = "{$classHierarchyByVariable}";
     return $condition;
 }
 private function createConditionFromSubConditionElements($subConditionElements, $joinVariable)
 {
     if ($subConditionElements->unionCondition === '') {
         return $this->createFilterCondition($subConditionElements);
     }
     if ($subConditionElements->filter === '') {
         return $this->createWhereCondition($subConditionElements);
     }
     $subJoinVariable = $this->compoundConditionBuilder->getNextVariable();
     $subConditionElements->unionCondition = str_replace("?{$joinVariable} ", "?{$subJoinVariable} ", $subConditionElements->unionCondition);
     $subConditionElements->filter .= " || ?{$joinVariable} = ?{$subJoinVariable}";
     $subConditionElements->hasSafeSubconditions = false;
     $subConditionElements->unionCondition = "OPTIONAL { {$subConditionElements->unionCondition} }\n FILTER( {$subConditionElements->filter} )\n";
     return $this->createWhereCondition($subConditionElements);
 }
 private function createFilterConditionToMatchRegexPattern($dataItem, &$joinVariable, $comparator, $pattern)
 {
     if ($dataItem instanceof DIBlob) {
         return new FilterCondition("{$comparator}( ?{$joinVariable}, \"{$pattern}\", \"s\")", array());
     }
     if ($dataItem instanceof DIUri) {
         return new FilterCondition("{$comparator}( str( ?{$joinVariable} ), \"{$pattern}\", \"i\")", array());
     }
     // Pattern search for a wikipage object can only be done on the sortkey
     // literal and not on it's resource
     $skeyExpElement = Exporter::getInstance()->getSpecialPropertyResource('_SKEY');
     $expElement = $this->exporter->getDataItemExpElement($dataItem->getSortKeyDataItem());
     $condition = new SingletonCondition($expElement);
     $filterVariable = $this->compoundConditionBuilder->getNextVariable();
     $condition->condition = "?{$joinVariable} " . $skeyExpElement->getQName() . " ?{$filterVariable} .\n";
     $condition->matchElement = "?{$joinVariable}";
     $filterCondition = new FilterCondition("{$comparator}( ?{$filterVariable}, \"{$pattern}\", \"s\")", array());
     $condition->weakConditions = array($filterVariable => $filterCondition->getCondition());
     return $condition;
 }
 private function getDebugQueryResult(Query $query, Condition $compoundCondition)
 {
     $entries = array();
     if ($this->isSingletonConditionWithElementMatch($compoundCondition)) {
         if ($compoundCondition->condition === '') {
             // all URIs exist, no querying
             $sparql = 'None (no conditions).';
         } else {
             $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
             $namespaces = $compoundCondition->namespaces;
             $sparql = $this->connection->getSparqlForAsk($condition, $namespaces);
         }
     } elseif ($compoundCondition instanceof FalseCondition) {
         $sparql = 'None (conditions can not be satisfied by anything).';
     } else {
         $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
         $namespaces = $compoundCondition->namespaces;
         $options = $this->getOptions($query, $compoundCondition);
         $options['DISTINCT'] = true;
         $sparql = $this->connection->getSparqlForSelect('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces);
     }
     $entries['SPARQL Query'] = QueryDebugOutputFormatter::doFormatSPARQLStatement($sparql);
     return QueryDebugOutputFormatter::getStringFrom('SPARQLStore', $entries, $query);
 }
 public function testTryToFindRedirectVariableForNonWpgDataItem()
 {
     $instance = new CompoundConditionBuilder();
     $this->assertNull($instance->tryToFindRedirectVariableForDataItem(new DINumber(1)));
 }
 /**
  * Create an Condition from a ThingDescription
  *
  * @param ThingDescription $description
  * @param string $joinVariable
  * @param DIProperty|null $orderByProperty
  *
  * @return Condition
  */
 public function buildCondition(Description $description, $joinVariable, $orderByProperty = null)
 {
     return $this->compoundConditionBuilder->buildTrueCondition($joinVariable, $orderByProperty);
 }
 public function testAddOrderByData_ForWikiPageType()
 {
     $condition = $this->getMockBuilder('\\SMW\\SPARQLStore\\QueryEngine\\Condition\\Condition')->disableOriginalConstructor()->getMockForAbstractClass();
     $instance = new CompoundConditionBuilder();
     $instance->addOrderByData($condition, 'foo', DataItem::TYPE_WIKIPAGE);
     $this->assertEquals('foosk', $condition->orderByVariable);
     $expectedConditionString = $this->stringBuilder->addString('?foo swivt:wikiPageSortKey ?foosk .')->addNewLine()->getString();
     $this->assertEquals($expectedConditionString, $condition->weakConditions['foosk']);
 }
 public function testSingletonLikeConditionForSolitaryWpgValue()
 {
     $description = new ValueDescription(new DIWikiPage("Foo*", NS_MAIN), null, SMW_CMP_LIKE);
     $instance = new CompoundConditionBuilder($this->descriptionInterpreterFactory);
     $condition = $instance->getConditionFrom($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()->addString(' OPTIONAL { ?result swivt:redirectsTo ?o2 } .')->addNewLine()->addString(' FILTER ( !bound( ?o2 ) ) .')->addNewLine()->getString();
     $this->assertEquals($expectedConditionString, $instance->convertConditionToString($condition));
 }
 /**
  * @since 2.2
  *
  * {@inheritDoc}
  */
 public function interpretDescription(Description $description)
 {
     return $this->compoundConditionBuilder->newTrueCondition($this->compoundConditionBuilder->getJoinVariable(), $this->compoundConditionBuilder->getOrderByProperty());
 }