/** * Adds the given Statement's main Snak to the RDF graph. * * @todo share more of this code with FullStatementRdfBuilder * * @param EntityId $entityId * @param Statement $statement * * @throws InvalidArgumentException */ private function addMainSnak(EntityId $entityId, Statement $statement) { $snak = $statement->getMainSnak(); $entityLName = $this->vocabulary->getEntityLName($entityId); $this->writer->about(RdfVocabulary::NS_ENTITY, $entityLName); $this->snakBuilder->addSnak($this->writer, $snak, RdfVocabulary::NSP_DIRECT_CLAIM); }
/** * @param Statement|null $oldStatement * @param Statement|null $newStatement * * @return DiffOpChange|null */ private function diffMainSnaks(Statement $oldStatement = null, Statement $newStatement = null) { $oldSnak = $oldStatement === null ? null : $oldStatement->getMainSnak(); $newSnak = $newStatement === null ? null : $newStatement->getMainSnak(); if ($oldSnak !== null && $oldSnak->equals($newSnak)) { return null; } return new DiffOpChange($oldSnak, $newSnak); }
/** * @param Statement $statement * * @return Statement */ public function copy(Statement $statement) { $mainSnak = $this->copySnak($statement->getMainSnak()); $qualifiers = $this->copyQualifiers($statement->getQualifiers()); $references = $this->copyReferences($statement->getReferences()); $newStatement = new Statement($mainSnak, $qualifiers, $references); $newStatement->setRank($statement->getRank()); return $newStatement; }
private function getSerialized(Statement $statement) { $serialization = array('mainsnak' => $this->mainSnakSerializer->serialize($statement->getMainSnak()), 'type' => 'statement'); $this->addQualifiersToSerialization($statement, $serialization); $this->addGuidToSerialization($statement, $serialization); $this->addRankToSerialization($statement, $serialization); $this->addReferencesToSerialization($statement, $serialization); return $serialization; }
private function checkDiff(Statement $lhs, Statement $rhs) { $lhsSnak = $lhs->getMainSnak(); $rhsSnak = $rhs->getMainSnak(); if (!$lhsSnak instanceof PropertyValueSnak || !$rhsSnak instanceof PropertyValueSnak) { return true; } $diff = abs($lhsSnak->getDataValue()->getSortKey() - $rhsSnak->getDataValue()->getSortKey()); return $diff <= $this->diff->getSortKey(); }
/** * Builds and returns the HTML representing a single WikibaseEntity's statement. * * @since 0.4 * * @param Statement $statement * @param null|string $editSectionHtml has the html for the edit section * * @return string HTML */ public function getHtmlForClaim(Statement $statement, $editSectionHtml = null) { $mainSnakHtml = $this->snakHtmlGenerator->getSnakHtml($statement->getMainSnak(), false); $statementRankSerializer = new StatementRankSerializer(); $serializedRank = $statementRankSerializer->serialize($statement->getRank()); // Messages: wikibase-statementview-rank-preferred, wikibase-statementview-rank-normal, // wikibase-statementview-rank-deprecated $rankHtml = $this->templateFactory->render('wikibase-rankselector', 'ui-state-disabled', 'wikibase-rankselector-' . $serializedRank, $this->getStatementRankText($serializedRank)); $referencesHeading = $this->getReferencesHeading($statement); $references = $statement->getReferences(); $referencesHtml = $this->getHtmlForReferences($references); return $this->templateFactory->render('wikibase-statementview', $statement->getGuid(), $rankHtml, $mainSnakHtml, $this->getHtmlForQualifiers($statement->getQualifiers()), $editSectionHtml, $referencesHeading, $referencesHtml, count($references) ? 'wikibase-initially-collapsed' : ''); }
/** * Applies validation to the given Claim. * This is done by validating all snaks contained in the claim, notably: * the main snak, the qualifiers, and all snaks of all references, * in case the claim is a Statement. * * @param Statement $statement The value to validate * * @return Result */ public function validateClaimSnaks(Statement $statement) { $snak = $statement->getMainSnak(); $result = $this->validate($snak); if (!$result->isValid()) { return $result; } foreach ($statement->getQualifiers() as $snak) { $result = $this->validate($snak); if (!$result->isValid()) { return $result; } } $result = $this->validateReferences($statement->getReferences()); if (!$result->isValid()) { return $result; } return Result::newSuccess(); }
/** * Generates HTML of a statement change. * * @since 0.4 * * @param ClaimDifference $claimDifference * @param Statement $baseStatement The new statement, if it exists. Otherwise the old statement. * * @return string HTML */ public function visualizeClaimChange(ClaimDifference $claimDifference, Statement $baseStatement) { $newestMainSnak = $baseStatement->getMainSnak(); $oldestMainSnak = $newestMainSnak; $html = ''; $mainSnakChange = $claimDifference->getMainSnakChange(); if ($mainSnakChange !== null) { $oldestMainSnak = $mainSnakChange->getOldValue() ?: $newestMainSnak; $html .= $this->visualizeMainSnakChange($mainSnakChange, $oldestMainSnak, $newestMainSnak); } $rankChange = $claimDifference->getRankChange(); if ($rankChange !== null) { $html .= $this->visualizeRankChange($rankChange, $oldestMainSnak, $newestMainSnak); } $qualifierChanges = $claimDifference->getQualifierChanges(); if ($qualifierChanges !== null) { $html .= $this->visualizeQualifierChanges($qualifierChanges, $oldestMainSnak, $newestMainSnak); } $referenceChanges = $claimDifference->getReferenceChanges(); if ($referenceChanges !== null) { $html .= $this->visualizeReferenceChanges($referenceChanges, $oldestMainSnak, $newestMainSnak); } return $html; }
/** * Adds the given Statement's main Snak to the RDF graph. * * @param EntityId $entityId * @param string $statementLName * @param Statement $statement * @param bool $isBest Is this best ranked statement? */ private function addMainSnak(EntityId $entityId, $statementLName, Statement $statement, $isBest) { $snak = $statement->getMainSnak(); $entityLName = $this->vocabulary->getEntityLName($entityId); $propertyLName = $this->vocabulary->getEntityLName($snak->getPropertyId()); $this->statementWriter->about(RdfVocabulary::NS_ENTITY, $entityLName)->say(RdfVocabulary::NSP_CLAIM, $propertyLName)->is(RdfVocabulary::NS_STATEMENT, $statementLName); $this->statementWriter->about(RdfVocabulary::NS_STATEMENT, $statementLName)->a(RdfVocabulary::NS_ONTOLOGY, 'Statement'); $rank = $statement->getRank(); if (isset(RdfVocabulary::$rankMap[$rank])) { if ($isBest) { $this->statementWriter->a(RdfVocabulary::NS_ONTOLOGY, RdfVocabulary::WIKIBASE_RANK_BEST); } $this->statementWriter->about(RdfVocabulary::NS_STATEMENT, $statementLName)->say(RdfVocabulary::NS_ONTOLOGY, 'rank')->is(RdfVocabulary::NS_ONTOLOGY, RdfVocabulary::$rankMap[$rank]); } else { wfLogWarning("Unknown rank {$rank} encountered for {$entityId}:{$statement->getGuid()}"); } $this->snakBuilder->addSnak($this->statementWriter, $snak, RdfVocabulary::NSP_CLAIM_STATEMENT); }
/** * @param Statement $statement * * @return Coord|null */ private function extractMainSnakCoord(Statement $statement) { $snak = $statement->getMainSnak(); if (!$snak instanceof PropertyValueSnak) { return null; } $dataValue = $snak->getDataValue(); if (!$dataValue instanceof GlobeCoordinateValue) { // Property data type - value mismatch return null; } $globeUri = $dataValue->getGlobe(); if (!isset($this->globeUris[$globeUri])) { // Unknown globe return null; } return new Coord($dataValue->getLatitude(), $dataValue->getLongitude(), $this->globeUris[$globeUri]); }
/** * @see StatementDataUpdater::processStatement * * @param Statement $statement */ public function processStatement(Statement $statement) { $this->processSnak($statement->getMainSnak(), $statement->getPropertyId(), $statement->getRank()); }
private function findSubStatement(StatementList $statementList, Statement $statement) { foreach ($statementList as $statementToMatch) { if ($this->isSnakMorePrecise($statement->getMainSnak(), $statementToMatch->getMainSnak()) && $this->isSubSnakList($statement->getQualifiers(), $statementToMatch->getQualifiers())) { return $statementToMatch; } } throw new OutOfBoundsException(); }
/** * @param Statement $statement * * @return string combined hash of the Mainsnak and Qualifiers */ private function getStatementHash(Statement $statement) { return $statement->getMainSnak()->getHash() . $statement->getQualifiers()->getHash(); }
private function getExpectedSummary(Statement $oldStatement, DataValue $value = null) { $oldSnak = $oldStatement->getMainSnak(); $property = $this->getEntityIdFormatter()->formatEntityId($oldSnak->getPropertyId()); //NOTE: new snak is always a PropertyValueSnak if ($value === null) { $value = $oldSnak->getDataValue(); } $value = $this->getPropertyValueFormatter()->format($value); return '/* wbsetclaimvalue:1| */ ' . $property . ': ' . $value; }
private function getExpectedSummary(Statement $oldStatement, StringValue $value) { $oldSnak = $oldStatement->getMainSnak(); $property = $this->getEntityIdFormatter()->formatEntityId($oldSnak->getPropertyId()); $value = $this->getPropertyValueFormatter()->format($value); return '/* wbsetclaimvalue:1| */ ' . $property . ': ' . $value; }
/** * Checks that the update of the main snak is permissible. * * This checks that the main snaks of the old and the new claim * refer to the same property. * * @param Statement $oldStatement * * @throws ChangeOpException If the main snak update is illegal. */ private function checkMainSnakUpdate(Statement $oldStatement) { $newMainSnak = $this->statement->getMainSnak(); $oldPropertyId = $oldStatement->getMainSnak()->getPropertyId(); if (!$oldPropertyId->equals($newMainSnak->getPropertyId())) { $guid = $this->statement->getGuid(); throw new ChangeOpException("Claim with GUID {$guid} uses property " . $oldPropertyId . ", can't change to " . $newMainSnak->getPropertyId()); } }
/** * @dataProvider instanceProvider */ public function testGetPropertyId(Statement $statement) { $this->assertEquals($statement->getMainSnak()->getPropertyId(), $statement->getPropertyId()); }
/** * Builds an associative array that can be used as summary arguments. It uses property IDs as * array keys and builds arrays of the main Snaks of all statements given by the GUIDs. * * @param Statement $newStatement * @param string $guid * * @return array[] Associative array that contains property ID => array of main Snaks */ private function buildSummaryArgs(Statement $newStatement, $guid) { $pairs = array(); if ($newStatement->getGuid() === $guid) { $snak = $newStatement->getMainSnak(); $key = $snak->getPropertyId()->getSerialization(); if (!array_key_exists($key, $pairs)) { $pairs[$key] = array(); } $pairs[$key][] = $snak; } return array($pairs); }