public function semanticDataProvider() { // Is a dataprovider therefore can't use the setUp $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); $this->dataValueFactory = DataValueFactory::getInstance(); $title = Title::newFromText('Foo'); #0 Empty container $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData(); $provider[] = array($foo); #1 Single entry $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData(); $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar')); $provider[] = array($foo); // #2 Single + single subobject entry $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData(); $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar')); $subobject = new Subobject($title); $subobject->setSemanticData('Foo'); $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has subobjects', 'Bam')); $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $provider[] = array($foo); #3 Multiple entries $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData(); $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar')); $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has queez', 'Xeey')); $subobject = new Subobject($title); $subobject->setSemanticData('Foo'); $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has subobjects', 'Bam')); $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Fuz')); $subobject->setSemanticData('Bar'); $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Fuz')); $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $provider[] = array($foo); return $provider; }
protected function addDataValuesToSubobject(ParserParameterProcessor $parameters) { $subject = $this->parserData->getSemanticData()->getSubject(); // Named subobjects containing a "." in the first five characters are reserved to be // used by extensions only in order to separate them from user land and avoid them // accidentally to refer to the same named ID // (i.e. different access restrictions etc.) if (strpos(mb_substr($parameters->getFirst(), 0, 5), '.') !== false) { return $this->addErrorWithMsg($subject, wfMessage('smw-subobject-parser-invalid-naming-scheme', $parameters->getFirst())->escaped()); } $this->subobject->setEmptyContainerForId($this->createSubobjectId($parameters)); foreach ($this->transformParametersToArray($parameters) as $property => $values) { if ($property === self::PARAM_SORTKEY) { $property = DIProperty::TYPE_SORTKEY; } if ($property === self::PARAM_CATEGORY) { $property = DIProperty::TYPE_CATEGORY; } foreach ($values as $value) { $dataValue = $this->dataValueFactory->newPropertyValue($property, $value, false, $subject); $this->subobject->addDataValue($dataValue); } } return true; }
protected function addDataValuesToSubobject(ParserParameterProcessor $parserParameterProcessor) { // Named subobjects containing a "." in the first five characters are reserved to be // used by extensions only in order to separate them from user land and avoid having // them accidentally to refer to the same named ID // (i.e. different access restrictions etc.) if (strpos(mb_substr($parserParameterProcessor->getFirst(), 0, 5), '.') !== false) { return $this->parserData->addError(Message::encode(array('smw-subobject-parser-invalid-naming-scheme', $parserParameterProcessor->getFirst()))); } list($parameters, $id) = $this->getParameters($parserParameterProcessor); $this->subobject->setEmptyContainerForId($id); $subject = $this->subobject->getSubject(); foreach ($parameters as $property => $values) { if ($property === self::PARAM_SORTKEY) { $property = DIProperty::TYPE_SORTKEY; } if ($property === self::PARAM_CATEGORY) { $property = DIProperty::TYPE_CATEGORY; } foreach ($values as $value) { $dataValue = DataValueFactory::getInstance()->newDataValueByText($property, $value, false, $subject); $this->subobject->addDataValue($dataValue); } } $this->doAugmentSortKeyForWhenDisplayTitleIsAccessible($this->subobject->getSemanticData()); return true; }
protected function addDataValuesToSubobject(ArrayFormatter $parameters) { $subject = $this->parserData->getSemanticData()->getSubject(); $this->subobject->setEmptyContainerForId($this->createSubobjectId($parameters)); foreach ($this->transformParametersToArray($parameters) as $property => $values) { if ($property === self::PARAM_SORTKEY) { $property = DIProperty::TYPE_SORTKEY; } foreach ($values as $value) { $dataValue = $this->dataValueFactory->newPropertyValue($property, $value, false, $subject); $this->subobject->addDataValue($dataValue); } } }
public function testResultDataFoSubobjectExtendedSemanticData() { $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__); $semanticData->addDataValue($this->dataValueFactory->newPropertyValue(__METHOD__, 'Bar')); $subobject = new Subobject($semanticData->getSubject()->getTitle()); $subobject->setEmptyContainerForId('Foo'); $subobject->addDataValue($this->dataValueFactory->newPropertyValue(__METHOD__, 'Bam')); $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $this->getStore()->updateData($semanticData); $resultData = $this->newBrowseBySubject(__METHOD__)->getResultData(); $this->assertInternalType('array', $resultData); $this->assertInstanceOf('\\SMW\\SemanticData', $this->serializerFactory->getDeserializerFor($resultData['query'])->deserialize($resultData['query'])); $this->assertInternalType('array', $this->newBrowseBySubject(__METHOD__, true)->getResultData()); }
/** * @dataProvider specialCharactersNameProvider */ public function testSpecialCharactersInQuery($subject, $subobjectId, $property, $dataItem) { $dataValue = $this->dataValueFactory->newDataItemValue($dataItem, $property); $semanticData = $this->semanticDataFactory->newEmptySemanticData($subject); $semanticData->addDataValue($dataValue); $subobject = new Subobject($semanticData->getSubject()->getTitle()); $subobject->setEmptyContainerForId($subobjectId); $subobject->addDataValue($dataValue); $semanticData->addSubobject($subobject); $this->getStore()->updateData($semanticData); $propertyValue = new PropertyValue('__pro'); $propertyValue->setDataItem($property); $description = new SomeProperty($property, new ThingDescription()); $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue)); $query = new Query($description, false, false); $query->querymode = Query::MODE_INSTANCES; $this->queryResultValidator->assertThatQueryResultHasSubjects(array($semanticData->getSubject(), $subobject->getSubject()), $this->getStore()->getQueryResult($query)); $this->queryResultValidator->assertThatQueryResultContains($dataValue, $this->getStore()->getQueryResult($query)); $this->subjectsToBeCleared = array($semanticData->getSubject(), $subobject->getSubject(), $property->getDIWikiPage()); }
/** * @since 2.1 * * @see https://en.wikipedia.org/wiki/Demographics_of_Paris * * @return Subobject */ public function getDemographics() { if ($this->targetSubject === null) { throw new RuntimeException('Expected a target subject'); } $subobject = new Subobject($this->targetSubject->getTitle()); $subobject->setEmptyContainerForId('Paris#Demographics'); $yearProperty = new YearProperty(); $yearDataValue = $this->dataValueFactory->newPropertyObjectValue($yearProperty->getProperty(), '2009'); $subobject->addDataValue($yearDataValue); $subobject->addDataValue($this->getAreaValue()); $subobject->addDataValue($this->getPopulationValue()); $subobject->addDataValue($this->getPopulationDensityValue()); return $subobject; }
private function newSubobject(Title $title, $property = 'Quuy', $value = 'Xeer') { $subobject = new Subobject($title); $subobject->setEmptyContainerForId('Foo'); $subobject->addDataValue(DataValueFactory::getInstance()->newPropertyValue($property, $value)); return $subobject; }
/** * {{#ask: [[LocatedIn.Has subobject.MemberOf::+]] }} */ public function testSubqueryForCombinedSubobjectPropertyChainForWilcardSearch() { /** * Page ...-dreamland annotated with [[LocatedIn::BananaWonderland]] */ $semanticDataOfDreamland = $this->semanticDataFactory->setTitle(__METHOD__ . '-dreamland')->newEmptySemanticData(); $semanticDataOfDreamland->addDataValue($this->newDataValueForPagePropertyValue('LocatedIn', 'BananaWonderland')); /** * Page ...-fairyland annotated with [[LocatedIn::BananaWonderland]] */ $semanticDataOfFairyland = $this->semanticDataFactory->setTitle(__METHOD__ . '-fairyland')->newEmptySemanticData(); $semanticDataOfFairyland->addDataValue($this->newDataValueForPagePropertyValue('LocatedIn', 'BananaWonderland')); /** * Page BananaWonderland annotated with [[Has subobject.MemberOf::Wonderland]] */ $semanticDataOfWonderland = $this->semanticDataFactory->setTitle('BananaWonderland')->newEmptySemanticData(); $subobject = new Subobject($semanticDataOfWonderland->getSubject()->getTitle()); $subobject->setEmptyContainerForId('SomeSubobjectOnWonderland'); $subobject->addDataValue($this->newDataValueForPagePropertyValue('MemberOf', 'Wonderland')); $semanticDataOfWonderland->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $this->getStore()->updateData($semanticDataOfDreamland); $this->getStore()->updateData($semanticDataOfFairyland); $this->getStore()->updateData($semanticDataOfWonderland); $description = new SomeProperty(DIProperty::newFromUserLabel('LocatedIn')->setPropertyTypeId('_wpg'), new SomeProperty(DIProperty::newFromUserLabel('_SOBJ')->setPropertyTypeId('__sob'), new SomeProperty(DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), new ThingDescription()))); $this->assertEquals($description, $this->queryParser->getQueryDescription('[[LocatedIn.Has subobject.MemberOf::+]]')); $query = new Query($description, false, false); $query->querymode = Query::MODE_INSTANCES; $queryResult = $this->getStore()->getQueryResult($query); $expectedSubjects = array($semanticDataOfDreamland->getSubject(), $semanticDataOfFairyland->getSubject()); $this->assertEquals(2, $queryResult->getCount()); $this->queryResultValidator->assertThatQueryResultHasSubjects($expectedSubjects, $queryResult); $this->subjectsToBeCleared = array($semanticDataOfWonderland->getSubject(), $semanticDataOfDreamland->getSubject(), $semanticDataOfFairyland->getSubject()); }
public function testAddDataValueWithInvalidSemanticDataThrowsException() { $dataValue = $this->getMockBuilder('\\SMWDataValue')->disableOriginalConstructor()->getMockForAbstractClass(); $instance = new Subobject(Title::newFromText(__METHOD__)); $this->setExpectedException('\\SMW\\InvalidSemanticDataException'); $instance->addDataValue($dataValue); }
/** * @return array */ public function typeChangeSemanticDataProvider() { $provider = array(); $title = \Title::newFromText(__METHOD__); // #0 Single entry $foo = new SemanticData(DIWikiPage::newFromTitle($title)); $foo->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fooQuex', 'Bar')); $provider[] = array($foo, 'Has_fooQuex'); // #1 Single subobject entry $foo = new SemanticData(DIWikiPage::newFromTitle($title)); $subobject = new Subobject($title); $subobject->setSemanticData('Foo'); $subobject->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fomQuex', 'Bam')); $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $provider[] = array($foo, 'Has_fomQuex'); // #2 Combined $foo = new SemanticData(DIWikiPage::newFromTitle($title)); $foo->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fooQuex', 'Bar')); $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $provider[] = array($foo, 'Has_fomQuex'); return $provider; }
public function testQuerySubobjects_afterUpdatingWithEmptyContainerAllAssociatedEntitiesGetRemovedFromGraph() { $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__); $subobject = new Subobject($semanticData->getSubject()->getTitle()); $subobject->setEmptyContainerForId('SubobjectToTestReferenceAfterUpdate'); $property = new DIProperty('SomeNumericPropertyToCompareReference'); $property->setPropertyTypeId('_num'); $dataItem = new DINumber(99999); $subobject->addDataValue($this->dataValueFactory->newDataItemValue($dataItem, $property)); $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $this->store->doSparqlDataUpdate($semanticData); $description = new SomeProperty($property, new ValueDescription($dataItem, null, SMW_CMP_EQ)); $query = new Query($description, false, false); $query->querymode = Query::MODE_INSTANCES; $this->assertSame(1, $this->store->getQueryResult($query)->getCount()); $this->queryResultValidator->assertThatQueryResultHasSubjects($subobject->getSemanticData()->getSubject(), $this->store->getQueryResult($query)); $this->store->doSparqlDataUpdate($this->semanticDataFactory->newEmptySemanticData(__METHOD__)); $this->assertSame(0, $this->store->getQueryResult($query)->getCount()); }
/** * {{#ask: [[SomeNumericPropertyToDifferentSubject::9999]] * |?SomeNumericPropertyToDifferentSubject * }} */ public function testQueryToCompareEqualNumericPropertyValuesAssignedToDifferentSubject() { $semanticDataWithSubobject = $this->semanticDataFactory->setTitle(__METHOD__ . '-withSobj')->newEmptySemanticData(); $semanticDataWithoutSubobject = $this->semanticDataFactory->setTitle(__METHOD__ . '-wwithoutSobj')->newEmptySemanticData(); $expectedDataValueToMatchCondition = $this->newDataValueForNumericPropertyValue('SomeNumericPropertyToDifferentSubject', 9999); $dataValueWithSamePropertyButDifferentValue = $this->newDataValueForNumericPropertyValue('SomeNumericPropertyToDifferentSubject', 1111); $subobject = new Subobject($semanticDataWithSubobject->getSubject()->getTitle()); $subobject->setEmptyContainerForId('SomeSubobjectToDifferentSubject'); $subobject->addDataValue($expectedDataValueToMatchCondition); $semanticDataWithSubobject->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $semanticDataWithSubobject->addDataValue($dataValueWithSamePropertyButDifferentValue); $semanticDataWithoutSubobject->addDataValue($expectedDataValueToMatchCondition); $this->getStore()->updateData($semanticDataWithSubobject); $this->getStore()->updateData($semanticDataWithoutSubobject); $property = new DIProperty('SomeNumericPropertyToDifferentSubject'); $property->setPropertyTypeId('_num'); $dataItem = new DINumber(9999); $description = new SomeProperty($property, new ValueDescription($dataItem, null, SMW_CMP_EQ)); $propertyValue = new PropertyValue('__pro'); $propertyValue->setDataItem($property); $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue)); $query = new Query($description, false, false); $queryResult = $this->getStore()->getQueryResult($query); $this->assertEquals(2, $queryResult->getCount()); $this->queryResultValidator->assertThatQueryResultContains($expectedDataValueToMatchCondition, $queryResult); $expectedSubjects = array($subobject->getSemanticData()->getSubject(), $semanticDataWithoutSubobject->getSubject()); $this->queryResultValidator->assertThatQueryResultHasSubjects($expectedSubjects, $queryResult); $this->subjectsToBeCleared = array($semanticDataWithoutSubobject->getSubject(), $semanticDataWithSubobject->getSubject()); }