Exemplo n.º 1
0
 /**
  * ProfileAnnotator::addAnnotation
  *
  * @since 1.9
  */
 public function addAnnotation()
 {
     $this->subobject->setEmptyContainerForId('_QUERY' . $this->queryId);
     //	$this->getSemanticData()->addPropertyObjectValue(
     //		new DIProperty( '_ASKID' ),
     //		new DIBlob( $this->queryId )
     //	);
 }
Exemplo n.º 2
0
 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);
         }
     }
 }
 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;
 }
 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 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());
 }
Exemplo n.º 8
0
 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 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);
 }
Exemplo n.º 10
0
 /**
  * {{#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 Subobject
  */
 private function acquireInstanceForId(Title $title, $id = '')
 {
     $instance = new Subobject($title);
     if ($id === '' && $id !== null) {
         $id = '_abcdef';
     }
     $instance->setEmptyContainerForId($id);
     return $instance;
 }
 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'));
 }
 /**
  * {{#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());
 }
 /**
  * @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 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::addAnnotation
  *
  * @since 1.9
  */
 public function addAnnotation()
 {
     $this->subobject->setEmptyContainerForId($this->queryId);
 }