/** * @since 1.9 * * @param ParserParameterProcessor $params * * @return string|null */ public function parse(ParserParameterProcessor $parameters) { if ($this->addDataValuesToSubobject($parameters) && !$this->subobject->getSemanticData()->isEmpty()) { $this->parserData->getSemanticData()->addSubobject($this->subobject); } $this->parserData->pushSemanticDataToParserOutput(); return $this->messageFormatter->addFromArray($this->subobject->getErrors())->addFromArray($this->parserData->getErrors())->addFromArray($parameters->getErrors())->getHtml(); }
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 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); } } }
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()); }
public function testThatChangingDataDoesEnforceDifferentHash() { $instance = new SemanticData(new DIWikiPage('Foo', NS_MAIN)); $firstHash = $instance->getHash(); $instance->addDataValue($this->dataValueFactory->newDataValueByText('Foo', 'Bar')); $secondHash = $instance->getHash(); $this->assertNotEquals($firstHash, $secondHash); $subobject = new Subobject(Title::newFromText('Foo')); $subobject->setEmptyContainerForId('Foo'); $subobject->addDataValue($this->dataValueFactory->newDataValueByText('Foo', 'Bar')); $instance->addSubSemanticData($subobject->getSemanticData()); $thirdHash = $instance->getHash(); $this->assertNotEquals($secondHash, $thirdHash); // Remove the data added in the third step and expect // the hash from the second $instance->removeSubSemanticData($subobject->getSemanticData()); $this->assertEquals($secondHash, $instance->getHash()); }
public function testGetSemanticDataInvalidSemanticDataThrowsException() { $instance = new Subobject(Title::newFromText(__METHOD__)); $this->setExpectedException('\\SMW\\InvalidSemanticDataException'); $instance->getSemanticData(); }
/** * @return array */ public function incompleteSubobjectDataProvider() { $provider = array(); $title = \Title::newFromText(__METHOD__); $subobject = new Subobject($title); $subobject->setSemanticData('Foo'); $foo = new SemanticData(DIWikiPage::newFromTitle($title)); $foo->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fooQuex', 'Bar')); $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getSemanticData()->getSubject()); $provider[] = array($foo); 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); }
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')); }
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()); }
/** * ProfileAnnotator::getSemanticData * * @since 1.9 * * @return SemanticData */ public function getSemanticData() { return $this->subobject->getSemanticData(); }
/** * {{#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()); }