Esempio n. 1
0
 /**
  * Static function for creating a new property object from a property
  * identifier (string) as it might be used internally. This might be
  * the DB key version of some property title text or the id of a
  * predefined property (such as '_TYPE').
  * @note This function strictly requires an internal identifier, i.e.
  * predefined properties must be referred to by their ID, and '-' is
  * not supported for indicating inverses.
  * @note The resulting property object might be invalid if
  * the provided name is not allowed. An object is returned
  * in any case.
  */
 public static function makeProperty($propertyid)
 {
     $diProperty = new SMWDIProperty($propertyid);
     $dvProperty = new SMWPropertyValue('__pro');
     $dvProperty->setDataItem($diProperty);
     return $dvProperty;
 }
Esempio n. 2
0
 /**
  * @since 2.1
  *
  * @param DIProperty $property
  *
  * @return PrintRequest
  */
 public function newPropertyPrintRequest(DIProperty $property)
 {
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($property);
     $instance = new PrintRequest(PrintRequest::PRINT_PROP, $propertyValue->getWikiValue(), $propertyValue);
     return $instance;
 }
 private function searchForResultsThatCompareEqualToClassOf($categoryName)
 {
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem(new DIProperty('_INST'));
     $description = new ClassDescription(new DIWikiPage($categoryName, NS_CATEGORY, ''));
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     return $this->getStore()->getQueryResult($query);
 }
 private function searchForResultsThatCompareEqualToOnlySingularPropertyOf(DIProperty $property)
 {
     $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);
     $query->querymode = Query::MODE_INSTANCES;
     return $this->getStore()->getQueryResult($query);
 }
Esempio n. 5
0
 public function testSetLabel()
 {
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem(new DIProperty('Foo'));
     $instance = new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue);
     $this->assertEquals(null, $instance->getLabel());
     $this->assertEquals(null, $instance->getWikiText());
     $instance->setLabel('Bar');
     $this->assertEquals('Bar', $instance->getLabel());
     $this->assertEquals('Bar', $instance->getWikiText());
 }
 public function testCreatePageWithSubobjectParserFunctionForQueryResultLookup()
 {
     $this->titles[] = Title::newFromText('CreatePageWithSubobjectParserFunction');
     $pageCreator = new PageCreator();
     $pageCreator->createPage(Title::newFromText('Has subobject parser function test', SMW_NS_PROPERTY))->doEdit('[[Has type::Page]]');
     $property = DIProperty::newFromUserLabel('Has subobject parser function test');
     $pageCreator->createPage($this->titles[0])->doEdit('{{#subobject:|Has subobject parser function test=WXYZ|@sortkey=B}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=A}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=A}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=C}}');
     $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_COUNT;
     $result = $this->getStore()->getQueryResult($query);
     $this->assertEquals(3, $result instanceof \SMWQueryResult ? $result->getCountValue() : $result);
     $query->querymode = Query::MODE_INSTANCES;
     $this->assertCount(3, $this->getStore()->getQueryResult($query)->getResults());
 }
 public function testUserDefinedBlobProperty()
 {
     $property = new DIProperty('SomeBlobProperty');
     $property->setPropertyTypeId('_txt');
     $dataItem = new DIBlob('SomePropertyBlobValue');
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $semanticData->addDataValue($this->dataValueFactory->newDataItemValue($dataItem, $property));
     $this->getStore()->updateData($semanticData);
     $this->assertArrayHasKey($property->getKey(), $this->getStore()->getSemanticData($semanticData->getSubject())->getProperties());
     $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;
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->queryResultValidator->assertThatQueryResultContains($dataItem, $queryResult);
 }
 /**
  * @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());
 }
 public function testRandomOrder()
 {
     $factsheet = $this->fixturesProvider->getFactsheet('Berlin');
     $populationValue = $factsheet->getPopulationValue();
     $this->getStore()->updateData($factsheet->asEntity());
     /**
      * @query [[Population::+]]
      */
     $property = $this->fixturesProvider->getProperty('Population');
     $description = new SomeProperty($property, new ThingDescription());
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($property);
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $query->sort = true;
     $query->sortkeys = array('Population' => 'RANDOM');
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->assertEquals(3, $queryResult->getCount());
 }
 public function testSortableRecordQuery()
 {
     $this->getStore()->updateData($this->fixturesProvider->getFactsheet('Berlin')->asEntity());
     $this->getStore()->updateData($this->fixturesProvider->getFactsheet('Paris')->asEntity());
     /**
      * PopulationDensity is specified as `_rec`
      *
      * @query {{#ask: [[PopulationDensity::SomeDistinctValue]] }}
      */
     $populationDensityValue = $this->fixturesProvider->getFactsheet('Berlin')->getPopulationDensityValue();
     $description = new SomeProperty($populationDensityValue->getProperty(), $populationDensityValue->getQueryDescription($populationDensityValue->getWikiValue()));
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($populationDensityValue->getProperty());
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $query->sortkeys = array($populationDensityValue->getProperty()->getKey() => 'ASC');
     $query->setLimit(100);
     $query->setExtraPrintouts(array(new PrintRequest(PrintRequest::PRINT_THIS, ''), new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue)));
     $expected = array($this->fixturesProvider->getFactsheet('Berlin')->asSubject(), $this->fixturesProvider->getFactsheet('Berlin')->getDemographics()->getSubject());
     $this->queryResultValidator->assertThatQueryResultHasSubjects($expected, $this->getStore()->getQueryResult($query));
 }
 public function testSubpropertyToQueryFromTopHierarchy()
 {
     if (!$this->getStore() instanceof \SMWSQLStore3) {
         $this->markTestSkipped("Subproperty/property hierarchies are currently only supported by the SQLStore");
     }
     $semanticDataOfSpouse = $this->semanticDataFactory->setSubject(new DIWikiPage('Spouse', SMW_NS_PROPERTY, ''))->newEmptySemanticData();
     $property = new DIProperty('Wife');
     $property->setPropertyTypeId('_wpg');
     $this->addPropertyHierarchy($property, 'Spouse');
     $dataValue = $this->dataValueFactory->newPropertyObjectValue($property, 'Lien');
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $semanticData->addDataValue($dataValue);
     $this->getStore()->updateData($semanticDataOfSpouse);
     $this->getStore()->updateData($semanticData);
     $description = new SomeProperty(new DIProperty('Spouse'), new ThingDescription());
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($property);
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->queryResultValidator->assertThatQueryResultContains($dataValue, $queryResult);
     $this->subjectsToBeCleared = array($semanticData->getSubject(), $semanticDataOfSpouse->getSubject(), $property->getDiWikiPage());
 }
 private function createQuery($queryString, $mode, array $printouts = array())
 {
     $description = $this->queryParser->getQueryDescription($queryString);
     foreach ($printouts as $printout) {
         $property = DIProperty::newFromUserLabel($printout);
         $propertyValue = new PropertyValue('__pro');
         $propertyValue->setDataItem($property);
         $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue));
     }
     $query = new Query($description, false, false);
     $query->setUnboundlimit($this->queryLimit);
     $query->setOffset($this->queryOffset);
     $query->querymode = $mode;
     return $query;
 }
 /**
  * {{#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());
 }
 /**
  * #576
  */
 public function testSortableDateQuery()
 {
     $this->getStore()->updateData($this->fixturesProvider->getFactsheet('Berlin')->asEntity());
     // #576 introduced resource caching, therefore make sure that the
     // instance is cleared after data have been created before further
     // tests are carried out
     Exporter::clear();
     /**
      * @query {{#ask: [[Founded::SomeDistinctValue]] }}
      */
     $foundedValue = $this->fixturesProvider->getFactsheet('Berlin')->getFoundedValue();
     $description = new SomeProperty($foundedValue->getProperty(), new ValueDescription($foundedValue->getDataItem(), null, SMW_CMP_EQ));
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($foundedValue->getProperty());
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $query->sortkeys = array($foundedValue->getProperty()->getLabel() => 'ASC');
     // Be aware of
     // Virtuoso 22023 Error SR353: Sorted TOP clause specifies more then
     // 10001 rows to sort. Only 10000 are allowed. Either decrease the
     // offset and/or row count or use a scrollable cursor
     $query->setLimit(100);
     $query->setExtraPrintouts(array(new PrintRequest(PrintRequest::PRINT_THIS, ''), new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue)));
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->queryResultValidator->assertThatQueryResultHasSubjects($this->fixturesProvider->getFactsheet('Berlin')->asSubject(), $queryResult);
 }
 /**
  * @since 2.2
  *
  * @return array
  */
 public function getExtraPrintouts()
 {
     $extraPrintouts = array();
     if (!isset($this->contents['printouts']) || $this->contents['printouts'] === array()) {
         return $extraPrintouts;
     }
     foreach ($this->contents['printouts'] as $printout) {
         $propertyValue = new PropertyValue('__pro');
         $propertyValue->setDataItem(DIProperty::newFromUserLabel($printout));
         $extraPrintouts[] = new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue);
     }
     return $extraPrintouts;
 }
 /**
  * @dataProvider formattedLabelProvider
  */
 public function testFormattedLabelLabel($property, $linker, $expected)
 {
     $propertyValue = new PropertyValue();
     $propertyValue->setOption(PropertyValue::OPT_CONTENT_LANGUAGE, 'en');
     $propertyValue->setOption(PropertyValue::OPT_USER_LANGUAGE, 'en');
     $propertyValue->setDataItem($property);
     $instance = new PropertyValueFormatter($propertyValue);
     $expected = $this->testEnvironment->getLocalizedTextByNamespace(SMW_NS_PROPERTY, $expected);
     $this->assertEquals($expected, $instance->format(PropertyValue::FORMAT_LABEL, $linker));
 }
 public function createQueryForSamplePagesThatContain($property, array &$expectedSubjects)
 {
     foreach ($expectedSubjects as $key => $expectedSubject) {
         $subjectTitle = $expectedSubject->getTitle()->getText() . '-' . __METHOD__;
         $semanticData = $this->semanticDataFactory->newEmptySemanticData($subjectTitle);
         $semanticData->addPropertyObjectValue($property, $expectedSubject);
         $this->subjectsToBeCleared[] = $semanticData->getSubject();
         $expectedSubjects[$key] = $semanticData->getSubject();
         $this->getStore()->updateData($semanticData);
     }
     $description = new SomeProperty($property, new ThingDescription());
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($property);
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     return $query;
 }