php SMW-DataValueFactory类(方法)实例源码

下面列出了php SMW-DataValueFactory 类(方法)源码代码实例,从而了解它的用法。

作者:whysass    项目:kmwik   
/**
  * Get the serialization for the provided data item.
  *
  * @since 1.7
  *
  * @param SMWDataItem $dataItem
  *
  * @return mixed
  */
 public static function getSerialization(DataItem $dataItem, $printRequest = null)
 {
     $result = array();
     switch ($dataItem->getDIType()) {
         case DataItem::TYPE_WIKIPAGE:
             $title = $dataItem->getTitle();
             $result = array('fulltext' => $title->getFullText(), 'fullurl' => $title->getFullUrl(), 'namespace' => $title->getNamespace(), 'exists' => $title->isKnown());
             break;
         case DataItem::TYPE_NUMBER:
             // dataitems and datavalues
             // Quantity is a datavalue type that belongs to dataitem
             // type number which means in order to identify the correct
             // unit, we have re-factor the corresponding datavalue otherwise
             // we will not be able to determine the unit
             // (unit is part of the datavalue object)
             if ($printRequest !== null && $printRequest->getTypeID() === '_qty') {
                 $diProperty = $printRequest->getData()->getDataItem();
                 $dataValue = DataValueFactory::getInstance()->newDataItemValue($dataItem, $diProperty);
                 $result = array('value' => $dataValue->getNumber(), 'unit' => $dataValue->getUnit());
             } else {
                 $result = $dataItem->getNumber();
             }
             break;
         case DataItem::TYPE_GEO:
             $result = $dataItem->getCoordinateSet();
             break;
         case DataItem::TYPE_TIME:
             $result = $dataItem->getMwTimestamp();
             break;
         default:
             $result = $dataItem->getSerialization();
             break;
     }
     return $result;
 }

作者:WolfgangFah    项目:SemanticMediaWik   
protected function setUp()
 {
     parent::setUp();
     $this->dataValueFactory = DataValueFactory::getInstance();
     $this->queryResultValidator = UtilityFactory::getInstance()->newValidatorFactory()->newQueryResultValidator();
     $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();
 }

作者:jongfel    项目:SemanticMediaWik   
/**
  * @since  1.9
  *
  * @param ParserParameterProcessor $parameters
  *
  * @return string|null
  */
 public function parse(ParserParameterProcessor $parameters)
 {
     $count = 0;
     $template = '';
     $subject = $this->parserData->getSemanticData()->getSubject();
     $parametersToArray = $parameters->toArray();
     if (isset($parametersToArray['template'])) {
         $template = $parametersToArray['template'][0];
         unset($parametersToArray['template']);
     }
     foreach ($parametersToArray as $property => $values) {
         $last = count($values) - 1;
         // -1 because the key starts with 0
         foreach ($values as $key => $value) {
             $dataValue = DataValueFactory::getInstance()->newDataValueByText($property, $value, false, $subject);
             if ($this->parserData->canModifySemanticData()) {
                 $this->parserData->addDataValue($dataValue);
             }
             $this->messageFormatter->addFromArray($dataValue->getErrors());
             $this->addFieldsToTemplate($template, $dataValue, $property, $value, $last == $key, $count);
         }
     }
     $this->parserData->pushSemanticDataToParserOutput();
     $html = $this->templateRenderer->render() . $this->messageFormatter->addFromArray($parameters->getErrors())->getHtml();
     return array($html, 'noparse' => $template === '', 'isHTML' => false);
 }

作者:jongfel    项目:SemanticMediaWik   
protected function setUp()
 {
     parent::setUp();
     $validatorFactory = $this->testEnvironment->getUtilityFactory()->newValidatorFactory();
     $stringValidator = $validatorFactory->newStringValidator();
     $semanticDataValidator = $validatorFactory->newSemanticDataValidator();
     $queryResultValidator = $validatorFactory->newQueryResultValidator();
     $this->queryTestCaseProcessor = new QueryTestCaseProcessor($this->getStore(), $queryResultValidator, $stringValidator);
     $this->rdfTestCaseProcessor = new RdfTestCaseProcessor($this->getStore(), $stringValidator);
     $this->parserTestCaseProcessor = new ParserTestCaseProcessor($this->getStore(), $semanticDataValidator, $stringValidator);
     $this->specialPageTestCaseProcessor = new SpecialPageTestCaseProcessor($this->getStore(), $stringValidator);
     $this->eventDispatcher = EventHandler::getInstance()->getEventDispatcher();
     // This ensures that if content is created in the NS_MEDIAWIKI namespace
     // and an object relies on the MediaWikiNsContentReader then it uses the DB
     ApplicationFactory::getInstance()->getMediaWikiNsContentReader()->skipMessageCache();
     DataValueFactory::getInstance()->clear();
     // Reset the Title/TitleParser otherwise a singleton instance holds an outdated
     // content language reference
     $this->testEnvironment->resetMediaWikiService('_MediaWikiTitleCodec');
     $this->testEnvironment->resetMediaWikiService('TitleParser');
     $this->testEnvironment->resetPoolCacheFor(PropertySpecificationLookup::POOLCACHE_ID);
     // Make sure LocalSettings don't interfere with the default settings
     $GLOBALS['smwgDVFeatures'] = $GLOBALS['smwgDVFeatures'] & ~SMW_DV_NUMV_USPACE;
     $this->testEnvironment->addConfiguration('smwgQueryResultCacheType', false);
 }

作者:jongfel    项目:SemanticMediaWik   
protected function setUp()
 {
     parent::setUp();
     $this->testEnvironment = new TestEnvironment();
     $this->semanticDataValidator = $this->testEnvironment->getUtilityFactory()->newValidatorFactory()->newSemanticDataValidator();
     $this->dataValueFactory = DataValueFactory::getInstance();
 }

作者:brandonphuon    项目:mediawik   
protected function getTypeProperties($typeLabel)
 {
     global $wgRequest, $smwgTypePagingLimit;
     if ($smwgTypePagingLimit <= 0) {
         return '';
         // not too useful, but we comply to this request
     }
     $from = $wgRequest->getVal('from');
     $until = $wgRequest->getVal('until');
     $typeValue = DataValueFactory::getInstance()->newTypeIDValue('__typ', $typeLabel);
     if (!$typeValue->isValid()) {
         return $this->msg('smw-special-types-no-such-type')->escaped();
     }
     $store = \SMW\StoreFactory::getStore();
     $options = SMWPageLister::getRequestOptions($smwgTypePagingLimit, $from, $until);
     $diWikiPages = $store->getPropertySubjects(new SMWDIProperty('_TYPE'), $typeValue->getDataItem(), $options);
     if (!$options->ascending) {
         $diWikiPages = array_reverse($diWikiPages);
     }
     $result = '';
     if (count($diWikiPages) > 0) {
         $pageLister = new SMWPageLister($diWikiPages, null, $smwgTypePagingLimit, $from, $until);
         $title = $this->getTitleFor('Types', $typeLabel);
         $title->setFragment('#SMWResults');
         // Make navigation point to the result list.
         $navigation = $pageLister->getNavigationLinks($title);
         $resultNumber = min($smwgTypePagingLimit, count($diWikiPages));
         $typeName = $typeValue->getLongWikiText();
         $result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . '<h2>' . wfMessage('smw_type_header', $typeName)->text() . "</h2>\n<p>" . wfMessage('smw_typearticlecount')->numParams($resultNumber)->text() . "</p>\n" . $navigation . $pageLister->formatList() . $navigation . "\n</div>";
     }
     return $result;
 }

作者:jongfel    项目:SemanticMediaWik   
/**
  * @since 2.4
  *
  * @param string $value
  *
  * @return Description
  * @throws InvalidArgumentException
  */
 public function deserialize($value)
 {
     if (!is_string($value)) {
         throw new InvalidArgumentException('Value needs to be a string');
     }
     if ($value === '') {
         $this->addError(wfMessage('smw_novalues')->text());
         return new ThingDescription();
     }
     $subdescriptions = array();
     list($text, $languageCode) = $this->dataValue->getValuesFromString($value);
     foreach ($this->dataValue->getPropertyDataItems() as $property) {
         // If the DVFeature doesn't require a language code to be present then
         // allow to skip it as conjunctive condition when it is empty
         if ($languageCode === '' && $property->getKey() === '_LCODE' && !$this->dataValue->isEnabledFeature(SMW_DV_MLTV_LCODE)) {
             continue;
         }
         $value = $property->getKey() === '_LCODE' ? $languageCode : $text;
         $comparator = SMW_CMP_EQ;
         $this->prepareValue($value, $comparator);
         // Directly use the DI instead of going through the DVFactory to
         // avoid having ~zh-* being validated when building a DV
         // If one of the values is empty use, ? so queries can be arbitrary
         // in respect of the query condition
         $dataValue = DataValueFactory::getInstance()->newDataValueByItem(new DIBlob($value === '' ? '?' : $value), $property, false, $this->dataValue->getContextPage());
         if (!$dataValue->isValid()) {
             $this->addError($dataValue->getErrors());
             continue;
         }
         $subdescriptions[] = $this->newSubdescription($dataValue, $comparator);
     }
     return $this->getFinalDescriptionFor($subdescriptions);
 }

作者:ReachingOu    项目:SemanticMediaWik   
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;
 }

作者:jongfel    项目:SemanticMediaWik   
private function doFormatFinalOutputFor($type, $linker)
 {
     $text = '';
     $languagecode = '';
     foreach ($this->dataValue->getPropertyDataItems() as $property) {
         // If we wanted to omit the language code display for some outputs then
         // this is the point to make it happen
         if (($type == self::HTML_LONG || $type == self::WIKI_SHORT) && $property->getKey() === '_LCODE') {
             //continue;
         }
         $dataItems = $this->dataValue->getDataItem()->getSemanticData()->getPropertyValues($property);
         // Should not happen but just in case
         if (!$dataItems === array()) {
             $this->dataValue->addErrorMsg('smw-datavalue-monolingual-dataitem-missing');
             continue;
         }
         $dataItem = reset($dataItems);
         if ($dataItem === false) {
             continue;
         }
         $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property);
         $result = $this->findValueOutputFor($type, $dataValue, $linker);
         if ($property->getKey() === '_LCODE' && $type !== self::VALUE) {
             $languagecode = ' ' . Message::get(array('smw-datavalue-monolingual-lcode-parenthesis', $result));
         } elseif ($property->getKey() === '_LCODE' && $type === self::VALUE) {
             $languagecode = '@' . $result;
         } else {
             $text = $result;
         }
     }
     return $text . $languagecode;
 }

作者:jongfel    项目:SemanticMediaWik   
protected function setUp()
 {
     parent::setUp();
     $this->dataItemFactory = new DataItemFactory();
     $this->dataValueFactory = DataValueFactory::getInstance();
     $this->testEnvironment = new TestEnvironment();
     $this->testEnvironment->resetPoolCacheFor(\SMWExporter::POOLCACHE_ID);
 }

作者:jongfel    项目:SemanticMediaWik   
protected function setUp()
 {
     $this->testEnvironment = new TestEnvironment();
     $this->dataItemFactory = new DataItemFactory();
     $this->dataValueFactory = DataValueFactory::getInstance();
     $this->cachedPropertyValuesPrefetcher = $this->getMockBuilder('\\SMW\\CachedPropertyValuesPrefetcher')->disableOriginalConstructor()->getMock();
     $this->testEnvironment->registerObject('CachedPropertyValuesPrefetcher', $this->cachedPropertyValuesPrefetcher);
 }

作者:jongfel    项目:SemanticMediaWik   
protected function setUp()
 {
     parent::setUp();
     $this->dataValueFactory = DataValueFactory::getInstance();
     $this->queryResultValidator = UtilityFactory::getInstance()->newValidatorFactory()->newQueryResultValidator();
     $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();
     $this->testEnvironment->addConfiguration('smwgQueryResultCacheType', false);
 }

作者:jongfel    项目:SemanticMediaWik   
protected function setUp()
 {
     parent::setUp();
     $this->dataValueFactory = DataValueFactory::getInstance();
     $this->semanticDataFactory = new SemanticDataFactory();
     $this->exportDataValidator = new ExportDataValidator();
     $this->fixturesProvider = new FixturesProvider();
 }

作者:hangy    项目:SemanticMediaWik   
protected function setUp()
 {
     parent::setUp();
     $this->apiFactory = new MwApiFactory();
     $this->dataValueFactory = DataValueFactory::getInstance();
     $this->serializerFactory = new SerializerFactory();
     $this->semanticDataFactory = new SemanticDataFactory();
 }

作者:hangy    项目:SemanticMap   
/**
  * @see SMWDescription::getQueryString
  * 
  * @since 0.6
  * 
  * @param boolean $asValue
  * @return string
  */
 public function getQueryString($asValue = false)
 {
     if ($this->getDataItem() !== null) {
         $queryString = DataValueFactory::newDataItemValue($this->getDataItem(), $this->getPropertyCompat())->getWikiValue();
         return $asValue ? $queryString : "[[{$queryString}]]";
     } else {
         return $asValue ? '+' : '';
     }
 }

作者:jongfel    项目:SemanticMediaWik   
public function getQueryString($asValue = false)
 {
     $pageValue = DataValueFactory::getInstance()->newDataValueByItem($this->concept, null);
     $result = '[[' . $pageValue->getPrefixedText() . ']]';
     if ($asValue) {
         return ' <q>' . $result . '</q> ';
     }
     return $result;
 }

作者:jongfel    项目:SemanticMediaWik   
/**
  * Instead of representing an external identifier as "owl:sameAs", the weaker
  * declarative axiom "skos:exactMatch" has been choosen to avoid potential
  * issues with undesirable entailments.
  *
  * "skos:exactMatch" has been defined as "... indicating a high degree of
  * confidence that the concepts can be used interchangeably across a wide
  * range of information retrieval applications ..."
  *
  * @since 2.5
  *
  * {@inheritDoc}
  */
 public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem)
 {
     parent::addResourceValue($expData, $property, $dataItem);
     $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property);
     $formattedUriDataItem = $dataValue->getWithFormattedUri();
     if ($formattedUriDataItem instanceof DIUri) {
         $expData->addPropertyObjectValue($this->exporter->getSpecialNsResource('skos', 'exactMatch'), $this->exporter->getDataItemExpElement($formattedUriDataItem));
     }
 }

作者:whysass    项目:kmwik   
protected function setUp()
 {
     parent::setUp();
     $this->dataValueFactory = DataValueFactory::getInstance();
     $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();
     $this->queryResultValidator = UtilityFactory::getInstance()->newValidatorFactory()->newQueryResultValidator();
     $this->fixturesProvider = UtilityFactory::getInstance()->newFixturesFactory()->newFixturesProvider();
     $this->fixturesProvider->setupDependencies($this->getStore());
 }

作者:jongfel    项目:SemanticMediaWik   
/**
  * @since 2.1
  *
  * @return SemanticData
  */
 public function getDependencies()
 {
     $semanticData = parent::getDependencies();
     $dataValueFactory = DataValueFactory::getInstance();
     foreach ($this->conversionValues as $conversionValue) {
         $semanticData->addDataValue($dataValueFactory->newDataValueByProperty(new DIProperty('_CONV'), $conversionValue));
     }
     return $semanticData;
 }

作者:WolfgangFah    项目:SemanticMediaWik   
protected function setUp()
 {
     parent::setUp();
     $this->mwHooksHandler = UtilityFactory::getInstance()->newMwHooksHandler();
     $this->mwHooksHandler->deregisterListedHooks()->invokeHooksFromRegistry();
     $this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator();
     $this->pageCreator = UtilityFactory::getInstance()->newPageCreator();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $this->dataValueFactory = DataValueFactory::getInstance();
 }


问题


面经


文章

微信
公众号

扫码关注公众号