/** * @param Snak $snak */ private function processSnak(Snak $snak) { $propertyId = $snak->getPropertyId(); $this->entityIds[$propertyId->getSerialization()] = $propertyId; if ($snak instanceof PropertyValueSnak) { $this->processDataValue($snak->getDataValue()); } }
private function getSerialized(Snak $snak) { $serialization = array('snaktype' => $snak->getType(), 'property' => $snak->getPropertyId()->getSerialization()); if ($this->serializeWithHash) { $serialization['hash'] = $snak->getHash(); } if ($snak instanceof PropertyValueSnak) { $serialization['datavalue'] = $this->dataValueSerializer->serialize($snak->getDataValue()); } return $serialization; }
/** * @param Snak $snak */ private function processSnak(Snak $snak) { if ($snak instanceof PropertyValueSnak) { $id = $snak->getPropertyId(); $value = $snak->getDataValue(); if ($value instanceof StringValue && $this->propertyDataTypeMatcher->isMatchingDataType($id, 'commonsMedia')) { $fileName = str_replace(' ', '_', $value->getValue()); if ($fileName !== '') { $this->fileNames[$fileName] = null; } } } }
/** * @param Snak $snak */ private function processSnak(Snak $snak) { if ($snak instanceof PropertyValueSnak) { $id = $snak->getPropertyId(); $value = $snak->getDataValue(); if ($value instanceof StringValue && $this->propertyDataTypeMatcher->isMatchingDataType($id, 'url')) { $url = $value->getValue(); if ($url !== '') { $this->urls[$url] = null; } } } }
/** * @since 0.2 * * @param Snak $mainSnak * @param EntityId|Item|Property|string $target * @param EditInfo|null $editInfo * * @return string the GUID of the claim * @throws UnexpectedValueException */ public function create(Snak $mainSnak, $target, EditInfo $editInfo = null) { if (is_string($target)) { $entityId = $target; } elseif ($target instanceof EntityId) { $entityId = $target->getSerialization(); } elseif ($target instanceof Item || $target instanceof Property) { $entityId = $target->getId()->getSerialization(); } else { throw new UnexpectedValueException('$target needs to be an EntityId, Entity or string'); } $params = array('entity' => $entityId, 'snaktype' => $mainSnak->getType(), 'property' => $mainSnak->getPropertyId()->getSerialization()); if ($mainSnak instanceof PropertyValueSnak) { $serializedDataValue = $this->dataValueSerializer->serialize($mainSnak->getDataValue()); $params['value'] = json_encode($serializedDataValue['value']); } $result = $this->api->postRequest('wbcreateclaim', $params, $editInfo); return $result['claims']['id']; }
private function copySnak(Snak $mainSnak) { $newPropertyId = $this->entityMappingStore->getLocalId($mainSnak->getPropertyId()->getSerialization()); switch ($mainSnak->getType()) { case 'somevalue': return new PropertySomeValueSnak(new PropertyId($newPropertyId)); case 'novalue': return new PropertyNoValueSnak(new PropertyId($newPropertyId)); default: $value = $mainSnak->getDataValue(); if ($value instanceof EntityIdValue) { $localId = $this->entityMappingStore->getLocalId($value->getEntityId()->getSerialization()); if (!$localId) { $this->logger->error("Entity not found for {$localId}."); } $value = new EntityIdValue($this->idParser->parse($localId)); } return new PropertyValueSnak(new PropertyId($newPropertyId), $value); } }
/** * Adds the given Statement's main Snak to the RDF graph. * * @param RdfWriter $writer * @param Snak $snak * @param string $propertyNamespace * * @throws InvalidArgumentException */ public function addSnak(RdfWriter $writer, Snak $snak, $propertyNamespace) { $propertyId = $snak->getPropertyId(); switch ($snak->getType()) { case 'value': /** @var PropertyValueSnak $snak */ $this->addSnakValue($writer, $snak, $propertyNamespace); break; case 'somevalue': $propertyValueLName = $this->vocabulary->getEntityLName($propertyId); $writer->say($propertyNamespace, $propertyValueLName)->is('_', $writer->blank()); break; case 'novalue': $propertyValueLName = $this->vocabulary->getEntityLName($propertyId); $writer->say('a')->is(RdfVocabulary::NSP_NOVALUE, $propertyValueLName); break; default: throw new InvalidArgumentException('Unknown snak type: ' . $snak->getType()); } $this->mentionedEntityTracker->propertyMentioned($snak->getPropertyId()); }
/** * @since 0.4 * * @param Snak $snak * @return array */ protected function getSnakSummaryArgs(Snak $snak) { $propertyId = $snak->getPropertyId(); return array(array($propertyId->getSerialization() => $snak)); }
/** * @dataProvider provideAddSnakValue */ public function testAddSnakValue(Snak $snak, $dataType) { $writer = $this->getTestData()->getNTriplesWriter(); $writer->about(RdfVocabulary::NS_ENTITY, 'Q11'); $propertyId = $snak->getPropertyId(); $builder = $this->newBuilder(RdfVocabulary::NSP_DIRECT_CLAIM, $propertyId->getSerialization(), $dataType, $snak); // assertions are done by the mocks $builder->addSnak($writer, $snak, RdfVocabulary::NSP_DIRECT_CLAIM); }
/** * @param Snak $snak * * @return string */ private function makePropertyLink(Snak $snak) { $propertyId = $snak->getPropertyId(); $propertyLink = $this->propertyIdFormatter->formatEntityId($propertyId); return $propertyLink; }
private function isSnakMorePrecise(Snak $a, Snak $b) { if ($a instanceof PropertyValueSnak && $b instanceof PropertyValueSnak) { return $a->getPropertyId()->equals($b->getPropertyId()) && $this->isDataValueMorePrecise($a->getDataValue(), $b->getDataValue()); } return $a->equals($b); }
/** * @param Snak $mainSnak * * @return array */ private function getSummaryArgs(Snak $mainSnak) { $propertyId = $mainSnak->getPropertyId(); return array(array($propertyId->getSerialization() => $mainSnak)); }
/** * Validates a Snak. * For a PropertyValueSnak, this is done using the validators from the DataType * that is associated with the Snak's property. * Other Snak types are currently not validated. * * @see ValueValidator::validate() * * @param Snak $snak The value to validate * * @throws InvalidArgumentException * @return Result */ public function validate($snak) { if (!$snak instanceof Snak) { throw new InvalidArgumentException('Snak expected'); } // XXX: instead of an instanceof check, we could have multiple validators // with a canValidate() method, to determine which validator to use // for a given snak. $propertyId = $snak->getPropertyId(); try { $typeId = $this->propertyDataTypeLookup->getDataTypeIdForProperty($propertyId); if ($snak instanceof PropertyValueSnak) { $dataValue = $snak->getDataValue(); $result = $this->validateDataValue($dataValue, $typeId); } else { $result = Result::newSuccess(); } } catch (PropertyDataTypeLookupException $ex) { $result = Result::newError(array(Error::newError("Property {$propertyId} not found!", null, 'no-such-property', array($propertyId)))); } return $result; }
/** * Get a detailed formatted snak, including the snak's property label and value. * * @param Snak $snak * * @return string HTML */ public function getPropertyAndDetailedValue(Snak $snak) { return $this->getColonSeparatedHtml($this->formatPropertyId($snak->getPropertyId()), $this->getDetailedValue($snak)); }
/** * @dataProvider snakProvider * @param Snak $snak */ public function testGetPropertyId(Snak $snak) { $this->assertInstanceOf('Wikibase\\DataModel\\Entity\\EntityId', $snak->getPropertyId()); }
protected function makeSetQualifierRequest($statementGuid, $snakhash, Snak $qualifier, EntityId $entityId) { $params = array('action' => 'wbsetqualifier', 'claim' => $statementGuid, 'snakhash' => $snakhash, 'snaktype' => $qualifier->getType(), 'property' => $qualifier->getPropertyId()->getSerialization()); if ($qualifier instanceof PropertyValueSnak) { $dataValue = $qualifier->getDataValue(); $params['value'] = FormatJson::encode($dataValue->getArrayValue()); } $this->makeValidRequest($params); /** @var StatementListProvider $entity */ $entity = WikibaseRepo::getDefaultInstance()->getEntityLookup()->getEntity($entityId); $statements = $entity->getStatements(); $statement = $statements->getFirstStatementWithGuid($params['claim']); $this->assertNotNull($statement); $this->assertTrue($statement->getQualifiers()->hasSnak($qualifier), 'The qualifier should exist in the qualifier list after making the request'); }
/** * @param Snak $snak * * @throws PropertyDataTypeLookupException * @return string The Snak's data type */ private function getSnakDataType(Snak $snak) { return $this->dataTypeLookup->getDataTypeIdForProperty($snak->getPropertyId()); // @todo: wrap the PropertyDataTypeLookupException, but make sure ErrorHandlingSnakFormatter still handles it. }