/**
  * @param PropertyId $propertyId
  *
  * @throws PropertyDataTypeLookupException
  */
 private function verifyDataTypeIsSet(PropertyId $propertyId)
 {
     $numericId = $propertyId->getSerialization();
     if (!array_key_exists($numericId, $this->dataTypeIds)) {
         throw new PropertyDataTypeLookupException($propertyId, "The DataType for property '{$numericId}' is not set");
     }
 }
 /**
  * @param PropertyId $propertyId
  *
  * @return string
  * @throws PropertyDataTypeLookupException
  */
 public function getDataTypeIdForProperty(PropertyId $propertyId)
 {
     $serializedId = $propertyId->getSerialization();
     if (!array_key_exists($serializedId, $this->propertyIds)) {
         $this->propertyIds[$serializedId] = $this->lookup->getDataTypeIdFOrProperty($propertyId);
     }
     return $this->propertyIds[$serializedId];
 }
 public function getPropertyEntityIdValueMatches(PropertyId $propertyId, EntityId $valueId)
 {
     $propertyText = $propertyId->getSerialization();
     $valueText = $valueId->getSerialization();
     $queryBuilder = new QueryBuilder($this->config->get('WikidataQueryPrefixes'));
     $queryBuilder->select('?id')->where("?id", "wdt:{$propertyText}", "wd:{$valueText}");
     $queryExecuter = new QueryExecuter($this->config->get('WikidataQueryUrl'));
     $results = $queryExecuter->execute($queryBuilder->getSPARQL());
     return $this->parseResults($results);
 }
Exemple #4
0
 /**
  * Support for passing in an EntityId instance that is not a PropertyId instance has
  * been deprecated since 0.5.
  *
  * @since 0.1
  *
  * @param PropertyId|EntityId|int $propertyId
  *
  * @throws InvalidArgumentException
  */
 public function __construct($propertyId)
 {
     if (is_int($propertyId)) {
         $propertyId = PropertyId::newFromNumber($propertyId);
     }
     if (!$propertyId instanceof EntityId) {
         throw new InvalidArgumentException('$propertyId must be an instance of EntityId');
     }
     if ($propertyId->getEntityType() !== Property::ENTITY_TYPE) {
         throw new InvalidArgumentException('$propertyId must have an entityType of ' . Property::ENTITY_TYPE);
     }
     if (!$propertyId instanceof PropertyId) {
         $propertyId = new PropertyId($propertyId->getSerialization());
     }
     $this->propertyId = $propertyId;
 }
 /**
  * @param Snak $snak
  * @param PropertyId $propertyId
  * @param int $rank
  */
 private function processSnak(Snak $snak, PropertyId $propertyId, $rank = Statement::RANK_NORMAL)
 {
     $id = $propertyId->getSerialization();
     $fileName = str_replace(' ', '_', $this->getString($snak));
     if ($fileName === null || $fileName === '') {
         return;
     }
     if (!$this->isAcceptableRank($rank)) {
         return;
     }
     if (!$this->isAcceptablePriority($id)) {
         return;
     }
     if ($this->isSamePriority($id) && !$this->isBetterRank($rank)) {
         return;
     }
     $this->bestProperty = $id;
     $this->bestRank = $rank;
     $this->bestFileName = $fileName;
 }
 /**
  * Checks if there are PropertyIdProvider instances for the given PropertyId.
  *
  * @since 1.0
  *
  * @param PropertyId $propertyId
  *
  * @return bool
  */
 public function hasPropertyId(PropertyId $propertyId)
 {
     return isset($this->byPropertyId[$propertyId->getSerialization()]);
 }
 private function buildTimeValueForSearch(PropertyId $propertyId, TimeValue $timeValue)
 {
     $significantTimePart = preg_replace('/(-00)*T00:00:00Z$/', '', $timeValue->getTime());
     return new MongoRegex('/^' . preg_quote($propertyId->getSerialization() . '-' . $significantTimePart, '/') . '/');
 }
 public function getApiPropertyUrl(PropertyId $id) : string
 {
     return $this->apiUrl . '/properties/' . $id->getSerialization();
 }
 public function testAddSnakValue_mention()
 {
     $propertyId = new PropertyId('P2');
     $value = new EntityIdValue(new ItemId('Q42'));
     $snak = new PropertyValueSnak($propertyId, $value);
     $writer = $this->getTestData()->getNTriplesWriter();
     $writer->about(RdfVocabulary::NS_ENTITY, 'Q11');
     $mentioned = array();
     $builder = $this->newBuilder(RdfVocabulary::NSP_DIRECT_CLAIM, $propertyId->getSerialization(), 'wikibase-item', $snak, $mentioned);
     $builder->addSnak($writer, $snak, RdfVocabulary::NSP_DIRECT_CLAIM);
     $this->assertEquals(array('P2'), array_keys($mentioned));
 }
 /**
  * Checks if there are constraints registered for the given property id.
  *
  * @param PropertyId $propertyId
  * @return boolean
  */
 public function hasConstraints(PropertyId $propertyId)
 {
     return isset($this->constraintsPerProperty[$propertyId->getSerialization()]);
 }
 private function getSerialization(EntityDocument $entity, PropertyId $propertyId)
 {
     return array('id' => $entity->getId()->getSerialization(), 'type' => $entity->getType(), 'labels' => array('de' => array('language' => 'de', 'value' => 'Kuchen'), 'en' => array('language' => 'en', 'value' => 'Cake')), 'claims' => array($propertyId->getSerialization() => array(array('id' => $this->makeGuid($entity->getId()), 'mainsnak' => array('snaktype' => 'value', 'property' => $propertyId->getSerialization(), 'datavalue' => array('value' => 'kittens!', 'type' => 'string')), 'type' => 'statement', 'rank' => 'normal'))));
 }
 /**
  * @dataProvider serializationProvider
  */
 public function testUnserialize($json, $expected)
 {
     $id = new PropertyId('P1');
     $id->unserialize($json);
     $this->assertSame($expected, $id->getSerialization());
 }
 /**
  * Returns the absolute numeric indices of objects featuring the same property id.
  *
  * @param PropertyId $propertyId
  *
  * @throws RuntimeException
  * @return int[]
  */
 private function getFlatArrayIndices(PropertyId $propertyId)
 {
     $this->assertIndexIsBuild();
     $propertyIndices = array();
     $i = 0;
     foreach ($this->byId as $serializedPropertyId => $objects) {
         if ($serializedPropertyId === $propertyId->getSerialization()) {
             $propertyIndices = range($i, $i + count($objects) - 1);
             break;
         } else {
             $i += count($objects);
         }
     }
     return $propertyIndices;
 }