/** * ProfileAnnotator::addAnnotation * * @since 1.9 */ public function addAnnotation() { $this->subobject->setEmptyContainerForId('_QUERY' . $this->queryId); // $this->getSemanticData()->addPropertyObjectValue( // new DIProperty( '_ASKID' ), // new DIBlob( $this->queryId ) // ); }
public function testMethodAccess() { $subobject = new Subobject(DIWikiPage::newFromText(__METHOD__)->getTitle()); $instance = new NullProfileAnnotator($subobject, '_QUERYadcb944aa33b2c972470b73964c547c0'); $instance->addAnnotation(); $this->assertInstanceOf('\\SMW\\DIProperty', $instance->getProperty()); $this->assertInstanceOf('\\SMWDIContainer', $instance->getContainer()); $this->assertInstanceOf('\\SMWContainerSemanticData', $instance->getSemanticData()); $this->assertEmpty($instance->getErrors()); $this->assertEquals('_QUERYadcb944aa33b2c972470b73964c547c0', $subobject->getSubobjectId()); }
public function testRoundtripOfSerializedSemanticDataAfterStoreUpdate() { $subject = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__)); $semanticDataBeforeUpdate = new SemanticData($subject); $subobject = new Subobject($subject->getTitle()); $subobject->setEmptyContainerForId('SomeSubobjectToSerialize'); $subobject->getSemanticData()->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Foo', 'Bar')); $semanticDataBeforeUpdate->addSubobject($subobject); $this->getStore()->updateData($semanticDataBeforeUpdate); $semanticDataAfterUpdate = $this->getStore()->getSemanticData($subject); $serializerFactory = new SerializerFactory(); $this->assertEquals($semanticDataAfterUpdate->getHash(), $serializerFactory->deserialize($serializerFactory->serialize($semanticDataAfterUpdate))->getHash()); }
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 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; }
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()); }
protected function addPropertyValuesFromExifData($rawExif) { $formattedExif = FormatMetadata::getFormattedData($rawExif); foreach ($formattedExif as $key => $value) { $dataItem = null; $propertyId = PropertyRegistry::getInstance()->getPropertyId($key); if ($propertyId === null) { continue; } $dataItemType = PropertyRegistry::getInstance()->getPropertyType($key); switch ($dataItemType) { case DataItem::TYPE_NUMBER: $dataItem = is_numeric($rawExif[$key]) ? new DINumber($rawExif[$key]) : null; break; case DataItem::TYPE_BLOB: $dataItem = new DIBlob($value); break; case DataItem::TYPE_TIME: $dataItem = $this->makeDataItemTime($rawExif[$key]); } if ($dataItem !== null) { $this->subobject->getSemanticData()->addPropertyObjectValue(new DIProperty($propertyId), $dataItem); } } }
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; }
/** * @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 * * @param Subobject $subobject */ public function addSubobject(Subobject $subobject) { $this->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); }
/** * {{#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()); }
/** * @return SubobjectParserFunction */ private function acquireInstance(Subobject $subobject, ParserOutput $parserOutput = null) { if ($parserOutput === null) { $parserOutput = new ParserOutput(); } return new SubobjectParserFunction(new ParserData($subobject->getTitle(), $parserOutput), $subobject, new MessageFormatter($subobject->getTitle()->getPageLanguage())); }
/** * @return Subobject */ private function acquireInstanceForId(Title $title, $id = '') { $instance = new Subobject($title); if ($id === '' && $id !== null) { $id = '_abcdef'; } $instance->setEmptyContainerForId($id); return $instance; }
/** * @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 testExportSubobject() { $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__); $subobject = new Subobject($semanticData->getSubject()->getTitle()); $subobject->setEmptyContainerForId('Foo'); $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $exportData = Exporter::getInstance()->makeExportData($semanticData); $expectedProperty = new ExpNsResource($this->transformPropertyLabelToAuxiliary($subobject->getProperty()), Exporter::getInstance()->getNamespaceUri('property'), 'property', new DIWikiPage('Has_subobject', SMW_NS_PROPERTY)); $this->assertTrue(Exporter::getInstance()->hasHelperExpElement($subobject->getProperty())); $this->assertCount(1, $exportData->getValues($expectedProperty)); $this->exportDataValidator->assertThatExportDataContainsProperty($expectedProperty, $exportData); $expectedResource = new ExpNsResource(Escaper::encodePage($subobject->getSemanticData()->getSubject()) . '-23' . 'Foo', Exporter::getInstance()->getNamespaceUri('wiki'), 'wiki', $subobject->getSemanticData()->getSubject()); $this->exportDataValidator->assertThatExportDataContainsResource($expectedResource, $expectedProperty, $exportData); }
/** * @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; }
public function testNoDeleteTaskForSubobjectsDuringUpdate() { $expectedSubjectForDeleteTask = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__)); $subobject = new Subobject($expectedSubjectForDeleteTask->getTitle()); $subobject->setEmptyContainerForId('Foo'); $semanticData = $this->semanticDataFactory->setSubject($expectedSubjectForDeleteTask)->newEmptySemanticData(); $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $repositoryResult = $this->getMockBuilder('\\SMW\\SPARQLStore\\QueryEngine\\RepositoryResult')->disableOriginalConstructor()->getMock(); $connection = $this->getMockBuilder('\\SMW\\SPARQLStore\\RepositoryConnectors\\GenericHttpRepositoryConnector')->disableOriginalConstructor()->getMock(); $connection->expects($this->atLeastOnce())->method('select')->will($this->returnValue($repositoryResult)); $connection->expects($this->atLeastOnce())->method('insertData'); $instance = $this->getMockBuilder('\\SMW\\SPARQLStore\\SPARQLStore')->disableOriginalConstructor()->setMethods(array('doSparqlDataDelete', 'getConnection'))->getMock(); $instance->expects($this->once())->method('doSparqlDataDelete')->with($this->equalTo($expectedSubjectForDeleteTask)); $instance->expects($this->atLeastOnce())->method('getConnection')->will($this->returnValue($connection)); $instance->doSparqlDataUpdate($semanticData); }
/** * {{#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()); }
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; }
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()); }
public function testAddSubobjectToSemanticDataForStorage() { $this->subjects[] = $subject = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__)); $semanticData = new SemanticData($subject); $subobject = new Subobject($subject->getTitle()); $subobject->setEmptyContainerForId('SomeSubobject'); $subobject->getSemanticData()->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Foo', 'Bar')); $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $this->getStore()->updateData($semanticData); $expected = array('propertyCount' => 2, 'properties' => array(new DIProperty('Foo'), new DIProperty('_SKEY')), 'propertyValues' => array('Bar', __METHOD__)); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $this->getStore()->getSemanticData($subject)->findSubSemanticData('SomeSubobject')); }
/** * ProfileAnnotator::addAnnotation * * @since 1.9 */ public function addAnnotation() { $this->subobject->setEmptyContainerForId($this->queryId); }