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); }
/** * 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('[', ':', ' '), $sparql); $entries['SPARQL Query'] = "<pre>{$sparql}</pre>"; return QueryOutputFormatter::formatDebugOutput('SPARQLStore', $entries, $query); }
/** * @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)); }
/** * @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)); }
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 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)); }
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); }
/** * '[[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($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)); }
public function testConceptDescriptionInterpreterForAnyValueConceptUsingMockedStore() { $circularReferenceGuard = $this->getMockBuilder('\\SMW\\CircularReferenceGuard')->disableOriginalConstructor()->getMock(); $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); $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard); $compoundConditionBuilder->setJoinVariable($resultVariable); $compoundConditionBuilder->setOrderByProperty($orderByProperty); $instance = new ConceptDescriptionInterpreter($compoundConditionBuilder); $condition = $instance->interpretDescription($description); $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)); }