private function getSnakValue(PropertyValueSnak $snak) : DataValue
 {
     $value = $snak->getDataValue();
     if ($value instanceof EntityIdValue) {
         return new EntityIdentityValue($value->getEntityId(), $this->getEntityName($value->getEntityId()), $this->urlBuilder->getApiEntityUrl($value->getEntityId()));
     }
     return $value;
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     $value = $snak->getDataValue();
     $entityId = $value->getValue()->getEntityId();
     $entityLName = $this->vocabulary->getEntityLName($entityId);
     $writer->say($propertyValueNamespace, $propertyValueLName)->is(RdfVocabulary::NS_ENTITY, $entityLName);
     $this->mentionedEntityTracker->entityReferenceMentioned($entityId);
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     $valueType = $snak->getDataValue()->getType();
     $builder = $this->getValueBuilder($dataType, $valueType);
     if ($builder) {
         $builder->addValue($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $snak);
     }
 }
 private function handle(PropertyValueSnak $snak)
 {
     $value = $snak->getDataValue();
     if ($value instanceof EntityIdValue) {
         return new StringValue($this->getEntityName($value->getEntityId()));
     }
     return $value;
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     /** @var QuantityValue $value */
     $value = $snak->getDataValue();
     $writer->say($propertyValueNamespace, $propertyValueLName)->value($value->getAmount(), 'xsd', 'decimal');
     //FIXME: this is meaningless without a unit identifier!
     if ($this->complexValueHelper !== null) {
         $this->addValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value);
     }
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     /** @var GlobeCoordinateValue $value */
     $value = $snak->getDataValue();
     $point = "Point({$value->getLatitude()} {$value->getLongitude()})";
     $writer->say($propertyValueNamespace, $propertyValueLName)->value($point, RdfVocabulary::NS_GEO, "wktLiteral");
     if ($this->complexValueHelper !== null) {
         $this->addValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value);
     }
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     $writer->say($propertyValueNamespace, $propertyValueLName);
     /** @var TimeValue $value */
     $value = $snak->getDataValue();
     $this->sayDateLiteral($writer, $value);
     if ($this->complexValueHelper !== null) {
         $this->addValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value);
     }
 }
 private function assertSnakHasUnDeserializableValue(PropertyValueSnak $snak)
 {
     $this->assertEquals(new PropertyId('P42'), $snak->getPropertyId());
     $dataValue = $snak->getDataValue();
     /**
      * @var UnDeserializableValue $dataValue
      */
     $this->assertInstanceOf('DataValues\\UnDeserializableValue', $dataValue);
     $this->assertEquals($dataValue->getTargetType(), 'string');
     $this->assertEquals($dataValue->getValue(), 1337);
 }
 /**
  * @see SnakUrlExpander::expandUrl
  *
  * @param PropertyValueSnak $snak
  *
  * @return string|null A URL or URI derived from the Snak, or null if no such URL
  *         could be determined.
  */
 public function expandUrl(PropertyValueSnak $snak)
 {
     $propertyId = $snak->getPropertyId();
     $value = $snak->getDataValue();
     Assert::parameterType('DataValues\\StringValue', $value, '$snak->getDataValue()');
     $pattern = $this->infoProvider->getPropertyInfo($propertyId);
     if ($pattern === null) {
         return null;
     }
     $id = urlencode($value->getValue());
     $url = str_replace('$1', $id, $pattern);
     return $url;
 }
 /**
  * @param PropertyId|EntityId|int $propertyId
  * @param DataValue $dataValue
  * @param DataValue[] $derivedDataValues
  *
  * @throws InvalidArgumentException
  */
 public function __construct($propertyId, DataValue $dataValue, array $derivedDataValues)
 {
     parent::__construct($propertyId, $dataValue);
     foreach ($derivedDataValues as $key => $extensionDataValue) {
         if (!$extensionDataValue instanceof DataValue || !is_string($key)) {
             throw new InvalidArgumentException('$derivedDataValues must be an array of DataValue objects with string keys');
         }
     }
     $this->derivedDataValues = $derivedDataValues;
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     /** @var GlobeCoordinateValue $value */
     $value = $snak->getDataValue();
     $point = "Point({$value->getLatitude()} {$value->getLongitude()})";
     $globe = $value->getGlobe();
     if ($globe && $globe !== GlobeCoordinateValue::GLOBE_EARTH) {
         $globe = str_replace('>', '%3E', $globe);
         // Add coordinate system according to http://www.opengeospatial.org/standards/geosparql
         // Per https://portal.opengeospatial.org/files/?artifact_id=47664 sec 8.5.1
         //    All RDFS Literals of type geo:wktLiteral shall consist of an optional URI
         //    identifying the coordinate reference system followed by Simple Features Well Known
         //   Text (WKT) describing a geometric value.
         // Example: "<http://www.opengis.net/def/crs/EPSG/0/4326> Point(33.95 -83.38)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>
         $point = "<{$globe}> {$point}";
     }
     $writer->say($propertyValueNamespace, $propertyValueLName)->value($point, RdfVocabulary::NS_GEO, "wktLiteral");
     if ($this->complexValueHelper !== null) {
         $this->addValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value);
     }
 }
 public function testGetDataValue()
 {
     $snak = new PropertyValueSnak(new PropertyId('P1'), new StringValue('a'));
     $dataValue = $snak->getDataValue();
     $this->assertInstanceOf('DataValues\\DataValue', $dataValue);
     $this->assertTrue($dataValue->equals(new StringValue('a')));
 }
 public function invalidGuidProvider()
 {
     $qualifierSnak = new PropertyValueSnak(722, new StringValue('abc'));
     $hash = $qualifierSnak->getHash();
     return array(array('xyz', $hash), array('x$y$z', $hash));
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     $uri = $this->getValueUri($snak->getDataValue());
     $writer->say($propertyValueNamespace, $propertyValueLName)->is($uri);
 }
 /**
  * Adds the value of the given property to the RDF graph.
  *
  * @param RdfWriter $writer
  * @param PropertyValueSnak $snak
  * @param string $propertyNamespace The property namespace for this snak
  */
 private function addSnakValue(RdfWriter $writer, PropertyValueSnak $snak, $propertyNamespace)
 {
     $propertyId = $snak->getPropertyId();
     $propertyValueLName = $this->vocabulary->getEntityLName($propertyId);
     $propertyKey = $propertyId->getSerialization();
     // cache data type for all properties we encounter
     if (!isset($this->propertyTypes[$propertyKey])) {
         try {
             $this->propertyTypes[$propertyKey] = $this->propertyLookup->getDataTypeIdForProperty($propertyId);
         } catch (PropertyDataTypeLookupException $e) {
             $this->propertyTypes[$propertyKey] = "unknown";
         }
     }
     $dataType = $this->propertyTypes[$propertyKey];
     $this->valueBuilder->addValue($writer, $propertyNamespace, $propertyValueLName, $dataType, $snak);
 }
 /**
  * @dataProvider formatProvider
  */
 public function testFormatSnak_givenDifferentFormats($format, $expected)
 {
     $snak = new PropertyValueSnak(new PropertyId('P1'), new StringValue('string'));
     $formatter = $this->getFormatter($snak->getType(), $format);
     $this->assertEquals($expected, $formatter->formatSnak($snak));
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     $literalValue = $this->getLiteralValue($snak->getDataValue());
     $nsType = $this->typeBase ?: ($this->typeLocal === null ? null : 'xsd');
     $writer->say($propertyValueNamespace, $propertyValueLName)->value($literalValue, $nsType, $this->typeLocal);
 }
 /**
  * Adds specific value
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type
  * @param PropertyValueSnak $snak
  */
 public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak)
 {
     /** @var MonolingualTextValue $value */
     $value = $snak->getDataValue();
     $writer->say($propertyValueNamespace, $propertyValueLName)->text($value->getText(), $value->getLanguageCode());
 }
 public function validateProvider()
 {
     $p11 = new PropertyId('P11');
     $q17 = new ItemId('Q17');
     $item = new Item($q17);
     $claimGuid = $this->mockProvider->getGuidGenerator()->newGuid($q17);
     $oldSnak = new PropertyValueSnak($p11, new StringValue("old qualifier"));
     $snak = new PropertyNoValueSnak($p11);
     $qualifiers = new SnakList(array($oldSnak));
     $item->getStatements()->addNewStatement($snak, $qualifiers, null, $claimGuid);
     //NOTE: the mock validator will consider the string "INVALID" to be invalid.
     $badSnak = new PropertyValueSnak($p11, new StringValue('INVALID'));
     $brokenSnak = new PropertyValueSnak($p11, new NumberValue(23));
     $snakHash = $oldSnak->getHash();
     $cases = array();
     $cases['invalid snak value'] = array($item, $claimGuid, $badSnak, '');
     $cases['invalid snak value type'] = array($item, $claimGuid, $brokenSnak, $snakHash);
     return $cases;
 }
 public function testDerivedSnakDoesNoteEqualPropertyValueSnak()
 {
     $property = new PropertyId('P9001');
     $value = new StringValue('bc');
     $derivedValues = array('foo' => new StringValue('foo'), 'bar' => new StringValue('bar'));
     $propertySnak = new PropertyValueSnak($property, $value);
     $emptyDerivedSnak = new DerivedPropertyValueSnak($property, $value, array());
     $derivedSnak = new DerivedPropertyValueSnak($property, $value, $derivedValues);
     $this->assertFalse($propertySnak->equals($emptyDerivedSnak));
     $this->assertFalse($propertySnak->equals($derivedSnak));
 }