public function descriptionProvider() { #0 Disjunction $description = new Disjunction(); $description->addDescription(new NamespaceDescription(NS_HELP)); $description->addDescription(new NamespaceDescription(NS_MAIN)); $expectedDisjunction = new \stdClass(); $expectedDisjunction->type = 3; $expectedDisjunction->components = array(1 => true, 2 => true); $provider[] = array($description, $expectedDisjunction); #1 Conjunction $description = new Conjunction(); $description->addDescription(new NamespaceDescription(NS_HELP)); $description->addDescription(new NamespaceDescription(NS_MAIN)); $expectedConjunction = new \stdClass(); $expectedConjunction->type = 4; $expectedConjunction->components = array(1 => true, 2 => true); $provider[] = array($description, $expectedConjunction); #2 No query $description = new Conjunction(); $description->addDescription(new ThingDescription()); $expectedConjunction = new \stdClass(); $expectedConjunction->type = 0; $expectedConjunction->components = array(); $provider[] = array($description, $expectedConjunction); return $provider; }
public function testConjunctiveNamespaceQueryThatIncludesSubobject() { $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__); $this->subjects[] = $semanticData->getSubject(); $factsheet = $this->fixturesProvider->getFactsheet('Berlin'); $factsheet->setTargetSubject($semanticData->getSubject()); $demographicsSubobject = $factsheet->getDemographics(); $this->subjects[] = $demographicsSubobject->getSemanticData()->getSubject(); $semanticData->addPropertyObjectValue($demographicsSubobject->getProperty(), $demographicsSubobject->getContainer()); $populationValue = $factsheet->getPopulationValue(); $semanticData->addDataValue($populationValue); $this->getStore()->updateData($semanticData); $someProperty = new SomeProperty($populationValue->getProperty(), new ValueDescription($populationValue->getDataItem(), null, SMW_CMP_EQ)); /** * @query [[Population::SomeDistinctPopulationValue]][[:+]] */ $description = new Conjunction(); $description->addDescription($someProperty); $description->addDescription(new NamespaceDescription(NS_MAIN)); $query = new Query($description, false, false); $query->querymode = Query::MODE_INSTANCES; $queryResult = $this->getStore()->getQueryResult($query); $this->assertEquals(2, $queryResult->getCount()); $this->queryResultValidator->assertThatQueryResultHasSubjects($this->subjects, $queryResult); }
public function testPrune() { $descriptions = array(new ValueDescription(new DIWikiPage('Foo', NS_MAIN)), new ValueDescription(new DIWikiPage('Bar', NS_MAIN))); $instance = new Conjunction($descriptions); $maxsize = 1; $maxDepth = 1; $log = array(); $this->assertEquals(new ValueDescription(new DIWikiPage('Foo', NS_MAIN)), $instance->prune($maxsize, $maxDepth, $log)); $maxsize = 0; $maxDepth = 1; $log = array(); $this->assertEquals(new ThingDescription(), $instance->prune($maxsize, $maxDepth, $log)); }
/** * {{#ask: [[Category:HappyPlaces]] [[LocatedIn.MemberOf::Wonderland]] }} */ public function testConjunctionForCategoryAndPropertyChainSubqueryThatComparesEqualToSpecifiedValue() { /** * Page ...-neverland annotated with [[LocatedIn::BananaWonderland]] */ $semanticDataOfNeverland = $this->semanticDataFactory->setTitle(__METHOD__ . '-neverland')->newEmptySemanticData(); $semanticDataOfNeverland->addPropertyObjectValue(DIProperty::newFromUserLabel('LocatedIn')->setPropertyTypeId('_wpg'), new DIWikiPage('BananaWonderland', NS_MAIN)); $this->getStore()->updateData($semanticDataOfNeverland); /** * Page ...-dreamland annotated with [[Category:HappyPlaces]] [[LocatedIn::BananaWonderland]] */ $semanticDataOfDreamland = $this->semanticDataFactory->setTitle(__METHOD__ . '-dreamland')->newEmptySemanticData(); $semanticDataOfDreamland->addPropertyObjectValue(DIProperty::newFromUserLabel('LocatedIn')->setPropertyTypeId('_wpg'), new DIWikiPage('BananaWonderland', NS_MAIN)); $semanticDataOfDreamland->addPropertyObjectValue(new DIProperty('_INST'), new DIWikiPage('HappyPlaces', NS_CATEGORY)); $this->getStore()->updateData($semanticDataOfDreamland); /** * Page BananaWonderland annotated with [[MemberOf::Wonderland]] */ $semanticDataOfWonderland = $this->semanticDataFactory->setTitle('BananaWonderland')->newEmptySemanticData(); $semanticDataOfWonderland->addPropertyObjectValue(DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), new DIWikiPage('Wonderland', NS_MAIN)); $this->getStore()->updateData($semanticDataOfWonderland); $someProperty = new SomeProperty(DIProperty::newFromUserLabel('LocatedIn')->setPropertyTypeId('_wpg'), new SomeProperty(DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), new ValueDescription(new DIWikiPage('Wonderland', NS_MAIN, ''), DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), SMW_CMP_EQ))); $classDescription = new ClassDescription(new DIWikiPage('HappyPlaces', NS_CATEGORY, '')); $description = new Conjunction(); $description->addDescription($classDescription); $description->addDescription($someProperty); $this->assertEquals($description, $this->queryParser->getQueryDescription('[[Category:HappyPlaces]] [[LocatedIn.MemberOf::Wonderland]]')); $this->assertEquals($description, $this->queryParser->getQueryDescription('[[Category:HappyPlaces]] [[LocatedIn::<q>[[MemberOf::Wonderland]]</q>]]')); $query = new Query($description, false, false); $query->querymode = Query::MODE_INSTANCES; $queryResult = $this->getStore()->getQueryResult($query); $expectedSubjects = array($semanticDataOfDreamland->getSubject()); $this->assertEquals(1, $queryResult->getCount()); $this->queryResultValidator->assertThatQueryResultHasSubjects($expectedSubjects, $queryResult); $this->subjectsToBeCleared = array($semanticDataOfWonderland->getSubject(), $semanticDataOfDreamland->getSubject(), $semanticDataOfNeverland->getSubject()); }
public function testConjunctionForCategoryPropertyChainDescription() { $someProperty = new SomeProperty(DIProperty::newFromUserLabel('One')->setPropertyTypeId('_wpg'), new SomeProperty(DIProperty::newFromUserLabel('Two')->setPropertyTypeId('_wpg'), new ValueDescription(new DIWikiPage('Bar', NS_MAIN, ''), DIProperty::newFromUserLabel('Two')->setPropertyTypeId('_wpg'), SMW_CMP_EQ))); $classDescription = new ClassDescription(new DIWikiPage('Foo', NS_CATEGORY, '')); $description = new Conjunction(); $description->addDescription($classDescription); $description->addDescription($someProperty); $this->assertEquals($description, $this->queryParser->getQueryDescription('[[Category:Foo]] [[One.Two::Bar]]')); $this->assertEquals($description, $this->queryParser->getQueryDescription('[[Category:Foo]] [[One::<q>[[Two::Bar]]</q>]]')); }