public function provideApplyConstraints() { $cases = array(); $statements = new StatementList(); $cases[] = array($statements, array()); $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(11)); $cases[] = array($statements, array()); $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(42)); $statements->addNewStatement(new PropertyNoValueSnak(10)); $statements->addNewStatement(new PropertyNoValueSnak(11)); $cases[] = array($statements, array()); $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(42)); $statements->addNewStatement(new PropertyNoValueSnak(11)); $statements->addNewStatement(new PropertyNoValueSnak(12)); $cases[] = array($statements, array('P12' => array('c6'))); $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(42)); $statements->addNewStatement(new PropertyNoValueSnak(32)); $statements->addNewStatement(new PropertyNoValueSnak(11)); $cases[] = array($statements, array('P32' => array('c2', 'c4'))); $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(42)); $statements->addNewStatement(new PropertyNoValueSnak(32)); $statements->addNewStatement(new PropertyNoValueSnak(12)); $cases[] = array($statements, array('P32' => array('c2', 'c4'), 'P12' => array('c6'))); return $cases; }
public function statementListsProvider() { $empty = new StatementList(); $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(1)); return array(array(array(), ''), array(array('statements' => $empty), '<HEADING id="claims" class="wikibase-statements">' . '(wikibase-statementsection-statements)</HEADING><LIST>'), array(array('statements' => $empty, 'identifiers' => $empty), '<HEADING id="claims" class="wikibase-statements">' . '(wikibase-statementsection-statements)</HEADING><LIST>'), array(array('statements' => $empty, 'P1' => $statements), '<HEADING id="claims" class="wikibase-statements">' . '(wikibase-statementsection-statements)</HEADING><LIST>' . '<HEADING id="P1" class="wikibase-statements' . ' wikibase-statements-P1">' . '(wikibase-statementsection-p1)</HEADING><LIST>')); }
public function testValidateStatements_returnsFalse() { $conflictConstraint = new ConflictConstraint(new PropertyNoValueSnak(42)); $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(42)); $this->assertFalse($conflictConstraint->validateStatements($statements)); }
public function testValidateStatements_returnsFalse() { $diffRangeConstraint = new DiffRangeConstraint(new NumberValue(5)); $statements = new StatementList(); $statements->addNewStatement(new PropertyValueSnak(42, new NumberValue(2))); $statements->addNewStatement(new PropertyValueSnak(42, new NumberValue(9))); $this->assertFalse($diffRangeConstraint->validateStatements($statements)); }
public function testUsesFirstStatementsGuid() { $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(1), null, null, 'Q1$'); $statements->addNewStatement(new PropertyNoValueSnak(1), null, null, 'P1$'); $grouper = new DispatchingEntityTypeStatementGrouper(array('item' => $this->newGrouper(1), 'property' => $this->newGrouper(0))); $grouper->groupStatements($statements); }
public function testGroupStatements() { $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(1)); $expected = array('statements' => $statements); $grouper = new NullStatementGrouper(); $this->assertSame($expected, $grouper->groupStatements($statements)); }
public function testValidateStatements_returnsFalse() { $dataValueConstraint = new DataValueConstraint(new FormatChecker('/foo/')); $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(42)); $statements->addNewStatement(new PropertyValueSnak(42, new NumberValue(123))); $statements->addNewStatement(new PropertyValueSnak(42, new StringValue('bar'))); $this->assertFalse($dataValueConstraint->validateStatements($statements)); }
/** * Adds Statements to the RDF graph. * * @param EntityId $entityId * @param StatementList $statementList */ public function addStatements(EntityId $entityId, StatementList $statementList) { // FIXME: getBestStatementPerProperty() uis expensive, share the result with FullStatementRdfBuilder! foreach ($statementList->getPropertyIds() as $propertyId) { foreach ($statementList->getByPropertyId($propertyId)->getBestStatements() as $statement) { $this->addMainSnak($entityId, $statement); } } }
public function entitiesProvider() { $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(1)); $q1 = new Item(null, null, null, $statements); $siteLinks = new SiteLinkList(); $siteLinks->addNewSiteLink('enwiki', 'Title'); $q2 = new Item(null, null, $siteLinks); return array(array(array(), 0, 0), array(array($q1), 1, 0), array(array($q2), 0, 1), array(array($q1, $q2), 1, 1)); }
public function testCanRepurposeDefaultGroup() { $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(1)); $grouper = new FilteringStatementGrouper(array('statements' => $this->newStatementFilter())); $groups = $grouper->groupStatements($statements); $this->assertCount(1, $groups); $this->assertArrayHasKey('statements', $groups); $this->assertCount(1, $groups['statements']); }
/** * @param StatementList $statements * * @return DataValue[] */ private function getStatementMainValues(StatementList $statements) { $statementValues = []; foreach ($statements->getMainSnaks() as $snak) { if ($snak instanceof PropertyValueSnak) { $statementValues[] = $this->getSnakValue($snak); } } return $statementValues; }
/** * @param StatementList $statements * * @return StatementGrouper */ private function guessStatementGrouper(StatementList $statements) { foreach ($statements->toArray() as $statement) { $entityType = $this->getEntityType($statement); if (array_key_exists($entityType, $this->statementGroupers)) { return $this->statementGroupers[$entityType]; } // FIXME: Check all statements and fail if they don't share the same entity type? } return new NullStatementGrouper(); }
public function testApplyConstraints() { $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(42)); $constraintList = new ConstraintList(array(new SingleValueConstraint())); $this->assertEmpty($constraintList->applyConstraints($statements)); $statements->addNewStatement(new PropertyNoValueSnak(42)); $this->assertEquals(array('singlevalue'), $constraintList->applyConstraints($statements)); $statements = new StatementList(); $constraintList->addConstraint(new MultiValueConstraint()); $this->assertEquals(array('singlevalue', 'multivalue'), $constraintList->applyConstraints($statements)); }
public function testArrayObjectNotConstructedFromObject() { $statement1 = $this->makeStatement(new PropertyNoValueSnak(1)); $statement2 = $this->makeStatement(new PropertyNoValueSnak(2)); $statementList = new StatementList(); $statementList->addStatement($statement1); $claims = new Claims($statementList); // According to the documentation append() "cannot be called when the ArrayObject was // constructed from an object." This test makes sure it was not constructed from an object. $claims->append($statement2); $this->assertSame(2, $claims->count()); }
/** * @param StatementList $statements * @param PropertyId $propertyId * @return DataValue[] */ public function getBestValues(StatementList $statements, PropertyId $propertyId) { $values = array(); $bestStatements = $statements->getByPropertyId($propertyId)->getBestStatements(); foreach ($bestStatements->toArray() as $statement) { $mainSnak = $statement->getMainSnak(); if ($mainSnak instanceof PropertyValueSnak) { $values[] = $mainSnak->getDataValue(); } } return $values; }
/** * @param StatementList $statements * * @return StatementList[] An associative array, mapping property id serializations to * StatementList objects. */ public function groupStatements(StatementList $statements) { /** @var StatementList[] $groups */ $groups = array(); foreach ($statements->toArray() as $statement) { $id = $statement->getPropertyId()->getSerialization(); if (!isset($groups[$id])) { $groups[$id] = new StatementList(); } $groups[$id]->addStatement($statement); } return $groups; }
/** * @param StatementList $statements * @param PropertyId $propertyId * * @return DataValue[] */ private function getStatementValuesWithPropertyId(StatementList $statements, PropertyId $propertyId) { $statementValues = []; /** * @var Statement $statement */ foreach ($statements->getByPropertyId($propertyId)->getBestStatements() as $statement) { $snak = $statement->getMainSnak(); if ($snak instanceof PropertyValueSnak) { $statementValues[] = $this->handle($snak); } } return $statementValues; }
/** * @param array[] $serialization * * @return StatementList */ private function getDeserialized(array $serialization) { $statementList = new StatementList(); foreach ($serialization as $key => $statementArray) { if (is_string($key)) { foreach ($statementArray as $statementSerialization) { $statementList->addStatement($this->statementDeserializer->deserialize($statementSerialization)); } } else { $statementList->addStatement($this->statementDeserializer->deserialize($statementArray)); } } return $statementList; }
/** * @param StatementList $statements * @param Diff $patch * * @throws InvalidArgumentException * @return StatementList */ public function getPatchedStatementList(StatementList $statements, Diff $patch) { $statementsByGuid = array(); /** * @var Statement $statement */ foreach ($statements as $statement) { $statementsByGuid[$statement->getGuid()] = $statement; } $patchedList = new StatementList(); foreach ($this->patcher->patch($statementsByGuid, $patch) as $statement) { $patchedList->addStatement($statement); } return $patchedList; }
private function getSerialized(StatementList $statementList) { $serialization = array(); foreach ($statementList->toArray() as $statement) { $idSerialization = $statement->getPropertyId()->getSerialization(); if (!array_key_exists($idSerialization, $serialization)) { $serialization[$idSerialization] = array(); } $serialization[$idSerialization][] = $this->statementSerializer->serialize($statement); } if ($this->useObjectsForMaps) { $serialization = (object) $serialization; } return $serialization; }
/** * @see EntityDocument::equals * * @param mixed $target * * @return bool */ public function equals($target) { if ($this === $target) { return true; } return $target instanceof self && $this->labels->equals($target->labels) && $this->descriptions->equals($target->descriptions) && $this->statements->equals($target->statements); }
/** * @see Comparable::equals * * Two items are considered equal if they are of the same * type and have the same value. The value does not include * the id, so entities with the same value but different id * are considered equal. * * @since 0.1 * * @param mixed $target * * @return bool */ public function equals($target) { if ($this === $target) { return true; } return $target instanceof self && $this->fingerprint->equals($target->fingerprint) && $this->siteLinks->equals($target->siteLinks) && $this->statements->equals($target->statements); }
/** * @param StatementList $statements * * @return StatementList[] An associative array, mapping statement group identifiers to * StatementList objects. All identifiers given in the constructor are guaranteed to be in the * result. */ public function groupStatements(StatementList $statements) { $groups = $this->getEmptyGroups(); foreach ($statements->toArray() as $statement) { $key = $this->getKey($statement); $groups[$key]->addStatement($statement); } return $groups; }
public function testFoo() { $statement0 = new Statement(new PropertyNoValueSnak(42)); $statement0->setGuid('s0'); $statement1 = new Statement(new PropertySomeValueSnak(42)); $statement1->setGuid('s1'); $statement2 = new Statement(new PropertyValueSnak(42, new StringValue('ohi'))); $statement2->setGuid('s2'); $statement3 = new Statement(new PropertyNoValueSnak(1)); $statement3->setGuid('s3'); $patch = new Diff(array('s0' => new DiffOpRemove($statement0), 's2' => new DiffOpAdd($statement2), 's3' => new DiffOpAdd($statement3))); $source = new StatementList(); $source->addStatement($statement0); $source->addStatement($statement1); $expected = new StatementList(); $expected->addStatement($statement1); $expected->addStatement($statement2); $expected->addStatement($statement3); $this->assertListResultsFromPatch($expected, $source, $patch); }
/** * @param StatementList $statements * * @return string|null The string value of the main snak of the first best * "formatterUrlProperty" statements, if such exists. Null otherwise. */ private function getFormatterUrl(StatementList $statements) { if ($this->formatterUrlProperty === null) { return null; } $bestStatements = $statements->getByPropertyId($this->formatterUrlProperty)->getBestStatements(); if ($bestStatements->isEmpty()) { return null; } $statementArray = $bestStatements->toArray(); $mainSnak = $statementArray[0]->getMainSnak(); if (!$mainSnak instanceof PropertyValueSnak) { return null; } $dataValue = $mainSnak->getDataValue(); if (!$dataValue instanceof StringValue) { return null; } return $dataValue->getValue(); }
/** * @param StatementList $statements * @param int $propertyId * @param string $string * @param int $rank */ private function addStatement(StatementList $statements, $propertyId, $string, $rank = Statement::RANK_NORMAL) { $statement = new Statement(new PropertyValueSnak($propertyId, new StringValue($string))); $statement->setRank($rank); $statements->addStatement($statement); }
private function newNonEmptyStatementList() { $statementList = new StatementList(); $statementList->addNewStatement(new PropertyNoValueSnak(42)); $statementList->addNewStatement(new PropertyNoValueSnak(1337)); return $statementList; }
/** * @return StatementList */ private function newStatementList() { $statements = new StatementList(); $statements->addNewStatement(new PropertyNoValueSnak(1), null, null, 'Q1$'); return $statements; }
/** * @param StatementList $statements * @param string $string * @param int $propertyId */ private function addStatement(StatementList $statements, $string, $propertyId = 1) { $statements->addNewStatement(new PropertyValueSnak($propertyId, new StringValue($string))); }
/** * @see Constraint::validateStatements * * @param StatementList $statements * @return boolean */ public function validateStatements(StatementList $statements) { return $statements->count() === 1; }