/** * @since 2.4 * * @param DIProperty $property * @param array|string $errorMsg * * @return DIContainer */ public function getContainerFor(DIProperty $property = null, $errorMsg = '') { if ($property !== null && $property->isInverse()) { $property = new DIProperty($property->getKey()); } $errorMsg = is_array($errorMsg) ? implode(' ', $errorMsg) : $errorMsg; $subject = new DIWikiPage($this->subject->getDBkey(), $this->subject->getNamespace(), $this->subject->getInterwiki(), '_ERR' . md5(($property !== null ? $property->getKey() : 'UNKNOWN') . $errorMsg)); // Encode brackets to avoid an annotion is created/included return $this->newDiContainer($subject, $property, InTextAnnotationParser::obscureAnnotation($errorMsg)); }
public function testPredefinedProperty() { $instance = new HashBuilder(); $property = new DIProperty('_MDAT'); $dataItem = $property->getDiWikiPage(); $this->assertEquals($dataItem, $instance->newDiWikiPageFromHash($instance->getHashIdForDiWikiPage($dataItem))); $this->assertEquals($dataItem, $instance->newDiWikiPageFromHash($instance->createHashIdFromSegments($property->getKey(), SMW_NS_PROPERTY))); }
/** * Create some initial DB entries for important built-in properties. Having the DB contents predefined * allows us to safe DB calls when certain data is needed. At the same time, the entries in the DB * make sure that DB-based functions work as with all other properties. */ private function doCheckInternalPropertyIndices($connection) { $this->messageReporter->reportMessage("\nSetting up internal property indices ...\n"); $this->doCheckPredefinedPropertyBorder($connection); // now write actual properties; do that each time, it is cheap enough and we can update sortkeys by current language $this->messageReporter->reportMessage(" ... writing entries for internal properties ...\n"); foreach (SMWSql3SmwIds::$special_ids as $prop => $id) { $property = new DIProperty($prop); $connection->replace(SQLStore::ID_TABLE, array('smw_id'), array('smw_id' => $id, 'smw_title' => $property->getKey(), 'smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => $this->store->getObjectIds()->getPropertyInterwiki($property), 'smw_subobject' => '', 'smw_sortkey' => $property->getCanonicalLabel()), __METHOD__); } $this->messageReporter->reportMessage(" ... done.\n"); }
/** * @since 2.4 * * @param DIWikiPage $subject * @param DIProperty $property * @param RequestOptions|null $requestOptions * * @return array */ public function getPropertyValues(DIWikiPage $subject, DIProperty $property, RequestOptions $requestOptions = null) { $key = $property->getKey() . ':' . $subject->getSubobjectName() . ':' . ($requestOptions !== null ? $requestOptions->getHash() : null); $container = $this->blobStore->read($this->getRootHashFrom($subject)); if ($container->has($key)) { return $container->get($key); } $dataItems = $this->store->getPropertyValues($subject, $property, $requestOptions); $container->set($key, $dataItems); $this->blobStore->save($container); return $dataItems; }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $diSubject = $expData->getSubject()->getDataItem(); if ($diSubject === null) { return; } $expNsResource = $this->exporter->getSpecialPropertyResource($property->getKey(), $diSubject->getNamespace()); $expElement = $this->exporter->getDataItemExpElement($dataItem); if ($expElement === null || $expNsResource === null) { return; } $expData->addPropertyObjectValue($expNsResource, $expElement); $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $expElement = $this->exporter->getDataItemExpElement($dataItem); if ($expElement === null) { return; } if ($property->getKey() === $property->findPropertyTypeID()) { // Ensures that Boolean remains Boolean and not localized canonical // representation such as "Booléen" when the content languageis not // English $expNsResource = $this->getResourceElementForProperty(new DIProperty($property->getCanonicalDiWikiPage()->getDBKey())); } else { $expNsResource = $this->getResourceElementHelperForProperty($property); } $expData->addPropertyObjectValue($expNsResource, $expElement); $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $diSubject = $expData->getSubject()->getDataItem(); if ($diSubject === null) { return; } $expNsResource = $this->exporter->getSpecialPropertyResource($property->getKey(), $diSubject->getNamespace()); if ($expNsResource === null) { return; } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property); if (!$dataValue instanceof ImportValue) { return; } $expData->addPropertyObjectValue($expNsResource, $this->exporter->getDataItemExpElement(new DIBlob($dataValue->getImportReference()))); $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * Returns DataItemId for a property * * @note findPropertyTypeID is calling the Store to find the * typeId reference this is costly but at the moment there is no other * way to determine the typeId * * This check is to ensure that during unserialization the correct item * in terms of its definition is being sought otherwise inconsistencies * can occur due to type changes of a property between the time of * the serialization and the deserialization (e.g for when the * serialization object is stored in cache, DB etc.) * * @return integer */ protected function getDataItemId(DIProperty $property) { if (!isset($this->dataItemTypeIdCache[$property->getKey()])) { $this->dataItemTypeIdCache[$property->getKey()] = DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID()); } return $this->dataItemTypeIdCache[$property->getKey()]; }
/** * Retrieve the id of the property table that is to be used for storing * values for the given property object. * * @since 1.8 * @param DIProperty $diProperty * @return string */ public function findPropertyTableID(DIProperty $diProperty) { $propertyKey = $diProperty->getKey(); // This is needed to initialize the $fixedPropertyTableIds field $this->getPropertyTables(); if (array_key_exists($propertyKey, self::$fixedPropertyTableIds)) { return self::$fixedPropertyTableIds[$propertyKey]; } else { return $this->findTypeTableId($diProperty->findPropertyTypeID()); } }
private function doExchangeForWhenInversePropertyIsUsed(DIProperty $property, $objectName, $joinVariable) { $subjectName = '?' . $joinVariable; $nonInverseProperty = $property; // Exchange arguments when property is inverse // don't check if this really makes sense if ($property->isInverse()) { $subjectName = $objectName; $objectName = '?' . $joinVariable; $nonInverseProperty = new DIProperty($property->getKey(), false); } return array($subjectName, $objectName, $nonInverseProperty); }
private function doMatchProperty(&$subjects, DIProperty $property) { if ($property->isInverse()) { $property = new DIProperty($property->getKey()); } $subject = $property->getCanonicalDiWikiPage(); if ($this->propertyHierarchyLookup->hasSubpropertyFor($property)) { $this->doMatchSubproperty($subjects, $subject, $property); } // Use the key here do match against pre-defined properties (e.g. _MDAT) $key = str_replace(' ', '_', $property->getKey()); if (!isset($this->propertyDependencyExemptionlist[$key])) { $subjects[$subject->getHash()] = $subject; } }
private function assertContainsPropertyLabels($labels, DIProperty $property) { $this->assertContains($property->getLabel(), $labels, __METHOD__ . " asserts property label for '{$property->getKey()}' with ({$this->formatAsString($labels)})"); }
private function doMatchProperty(&$subjects, DIProperty $property) { if ($property->isInverse()) { $property = new DIProperty($property->getKey()); } if ($this->propertyHierarchyLookup->hasSubpropertyFor($property)) { $this->doMatchSubproperty($subjects, $property); } $key = str_replace(' ', '_', $property->getKey()); if (!isset($this->propertyDependencyDetectionBlacklist[$key])) { $subjects[] = $property->getDiWikiPage(); } }
/** * @since 2.5 * * @param array|string $errorMsg * @param DIProperty|null $property * * @return DIContainer|null */ public function getErrorContainerFromMsg($error, DIProperty $property = null) { if ($property !== null && $property->isInverse()) { $property = new DIProperty($property->getKey()); } $error = Message::encode($error); $hash = $error; if ($property !== null) { $hash .= $property->getKey(); } $containerSemanticData = $this->newContainerSemanticData($hash); $this->addToContainerSemanticData($containerSemanticData, $property, $error); return new DIContainer($containerSemanticData); }
/** * @since 2.5 * * {@inheritDoc} */ public function isResourceBuilderFor(DIProperty $property) { return $property->getKey() === '_CONC'; }
protected static function hasSpecialPropertyResource(DIProperty $property) { return $property->getKey() === '_SKEY' || $property->getKey() === '_INST' || $property->getKey() === '_MDAT' || $property->getKey() === '_SUBC' || $property->getKey() === '_SUBP' || $property->getKey() === '_TYPE' || $property->getKey() === '_IMPO' || $property->getKey() === '_URI'; }
private function doMapSomeProperty(SomeProperty $description, &$exact) { $result = new ExpData(new ExpResource('')); $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('rdf', 'type'), new ExpData($this->exporter->getSpecialNsResource('owl', 'Restriction'))); $property = $description->getProperty(); if ($property->isInverse()) { $property = new DIProperty($property->getKey()); } $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'onProperty'), new ExpData($this->exporter->getResourceElementForProperty($property))); $subdata = $this->getExpDataFromDescription($description->getDescription(), $exact); if ($description->getDescription() instanceof ValueDescription && $description->getDescription()->getComparator() === SMW_CMP_EQ) { $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'hasValue'), $subdata); } else { if ($subdata === false) { $owltype = $this->exporter->getOWLPropertyType($description->getProperty()->findPropertyTypeID()); if ($owltype == 'ObjectProperty') { $subdata = new ExpData($this->exporter->getSpecialNsResource('owl', 'Thing')); } elseif ($owltype == 'DatatypeProperty') { $subdata = new ExpData($this->exporter->getSpecialNsResource('rdfs', 'Literal')); } else { // no restrictions at all with annotation properties ... return new ExpData($this->exporter->getSpecialNsResource('owl', 'Thing')); } } $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'someValuesFrom'), $subdata); } return $result; }
/** * Get the array of all stored values for some property. * * @since 1.8 * * @param DIProperty $property * * @return array of SMWDataItem */ public function getPropertyValues(DIProperty $property) { if ($property->isInverse()) { // we never have any data for inverses return array(); } if (array_key_exists($property->getKey(), $this->mStubPropVals)) { // Not catching exception here; the $this->unstubProperty($property->getKey(), $property); $propertyTypeId = $property->findPropertyTypeID(); $propertyDiId = DataTypeRegistry::getInstance()->getDataItemId($propertyTypeId); foreach ($this->mStubPropVals[$property->getKey()] as $dbkeys) { try { $diHandler = $this->store->getDataItemHandlerForDIType($propertyDiId); $di = $diHandler->dataItemFromDBKeys($dbkeys); if ($this->mNoDuplicates) { $this->mPropVals[$property->getKey()][$di->getHash()] = $di; } else { $this->mPropVals[$property->getKey()][] = $di; } } catch (SMWDataItemException $e) { // ignore data } } unset($this->mStubPropVals[$property->getKey()]); } return parent::getPropertyValues($property); }
/** * @since 2.4 * * @param DIProperty $property * * @return integer|false */ public function getAllowedValuesBy(DIProperty $property) { $allowsValues = array(); $key = 'al:' . $property->getKey(); // Guard against high frequency lookup if ($this->intermediaryMemoryCache->contains($key)) { return $this->intermediaryMemoryCache->fetch($key); } $dataItems = $this->cachedPropertyValuesPrefetcher->getPropertyValues($property->getCanonicalDiWikiPage(), new DIProperty('_PVAL')); if (is_array($dataItems) && $dataItems !== array()) { $allowsValues = $dataItems; } $this->intermediaryMemoryCache->save($key, $allowsValues); return $allowsValues; }
/** * Retrieve the id of the property table that is to be used for storing * values for the given property object. * * @since 2.2 * * @param DIProperty $property * * @return string */ public function findTableIdForProperty(DIProperty $property) { if ($this->fixedPropertyTableIds === null) { $this->buildDefinitionsForPropertyTables(); } $propertyKey = $property->getKey(); if (array_key_exists($propertyKey, $this->fixedPropertyTableIds)) { return $this->fixedPropertyTableIds[$propertyKey]; } return $this->findTableIdForDataTypeTypeId($property->findPropertyTypeID()); }
/** * @since 2.3 * * @param DIProperty $property * * @return DIWikiPage[]|[] */ public function findSubpropertListFor(DIProperty $property) { return $this->findMatchesFor('_SUBP', $property->getKey(), $property->getDiWikiPage()); }
/** * Remove a value for a property identified by its SMWDataItem object. * This method removes a property-value specified by the property and * dataitem. If there are no more property-values for this property it * also removes the property from the mProperties. * * @note There is no check whether the type of the given data item * agrees with the type of the property. Since property types can * change, all parts of SMW are prepared to handle mismatched data item * types anyway. * * @param $property DIProperty * @param $dataItem SMWDataItem * * @since 1.8 */ public function removePropertyObjectValue(DIProperty $property, SMWDataItem $dataItem) { //delete associated subSemanticData if ($dataItem instanceof SMWDIContainer) { $this->removeSubSemanticData($dataItem->getSemanticData()); $dataItem = $dataItem->getSemanticData()->getSubject(); } if ($property->isInverse()) { // inverse properties cannot be used for annotation return; } if (!array_key_exists($property->getKey(), $this->mPropVals) || !array_key_exists($property->getKey(), $this->mProperties)) { return; } if ($this->mNoDuplicates) { //this didn't get checked for my tests, but should work unset($this->mPropVals[$property->getKey()][$dataItem->getHash()]); } else { foreach ($this->mPropVals[$property->getKey()] as $index => $di) { if ($di->equals($dataItem)) { unset($this->mPropVals[$property->getKey()][$index]); } } $this->mPropVals[$property->getKey()] = array_values($this->mPropVals[$property->getKey()]); } if ($this->mPropVals[$property->getKey()] === array()) { unset($this->mProperties[$property->getKey()]); unset($this->mPropVals[$property->getKey()]); } }
/** * @note There are different ways to find out whether a property * has a subproperty or not. * * In SPARQL one could try using FILTER NOT EXISTS { ?s my:property ?o } * * @since 2.3 * * @param DIProperty $property * * @return boolean */ public function hasSubpropertyFor(DIProperty $property) { return $this->hasMatchFor('_SUBP', $property->getKey(), $property->getDiWikiPage()); }
/** * Returns an array of SMWDataItem and simulates an alternating * existencance of return values ('_LIST') * * @see Store::getPropertyValues * * @return SMWDataItem[] */ public function mockStorePropertyValuesCallback($subject, DIProperty $property, $requestoptions = null) { return $property->getKey() === '_LIST' ? array() : $this->storeValues; }
/** * @since 2.5 * * @param DIProperty $property * * @return boolean */ public function isExemptedProperty(DIProperty $property) { $dataItemTypeId = DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID()); // Is neither therefore is exempted if ($dataItemTypeId !== DataItem::TYPE_BLOB && $dataItemTypeId !== DataItem::TYPE_URI) { return true; } return isset($this->propertyExemptionList[$property->getKey()]); }
private function doResolveDependenciesFromPrintRequest(&$subjects, array $printRequests) { foreach ($printRequests as $printRequest) { $data = $printRequest->getData(); if ($data instanceof \SMWPropertyValue) { $property = $data->getDataItem(); if ($property->isInverse()) { $property = new DIProperty($property->getKey()); } $subjects[] = $property->getDiWikiPage(); } // Category if ($data instanceof \Title) { $subjects[] = DIWikiPage::newFromTitle($data); } } }
/** * @since 2.3 * * @param DIProperty $property * * @return DIWikiPage[]|[] */ public function findSubpropertListFor(DIProperty $property) { return $this->findMatchesWith('_SUBP', $property->getKey(), $property->getDiWikiPage(), new RequestOptions()); }