/** * 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); } } }
/** * @param StatementList $statements * * @return array */ public function buildFromStatements(StatementList $statements) { $simpleStatements = []; foreach ($statements->getPropertyIds() as $propertyId) { $simpleStatement = new SimpleStatement(); $statementValues = $this->getStatementValuesWithPropertyId($statements, $propertyId); if (!empty($statementValues)) { $simpleStatement->values = $statementValues; $simpleStatement->valueType = $statementValues[0]->getType(); $simpleStatement->propertyName = $this->getEntityName($propertyId); $simpleStatement->propertyId = $propertyId; $simpleStatements[] = $simpleStatement; } } return $simpleStatements; }
/** * @param StatementList $statements * * @return array */ public function buildFromStatements(StatementList $statements) : array { $simpleStatements = []; foreach ($statements->getPropertyIds() as $propertyId) { $statementValues = $this->getStatementMainValues($statements->getByPropertyId($propertyId)->getBestStatements()); if (!empty($statementValues)) { $simpleStatement = new SimpleStatement(); $simpleStatement->values = $statementValues; $simpleStatement->valueType = $statementValues[0]->getType(); $simpleStatement->propertyName = $this->getEntityName($propertyId); $simpleStatement->propertyId = $propertyId; $simpleStatement->propertyUrl = $this->urlBuilder->getApiPropertyUrl($propertyId); $simpleStatements[] = $simpleStatement; } } return $simpleStatements; }
public function testGivenStatements_getPropertyIdsReturnsArrayWithoutDuplicates() { $list = new StatementList($this->getStatement(1, 'kittens'), $this->getStatement(3, 'foo'), $this->getStatement(2, 'bar'), $this->getStatement(2, 'baz'), $this->getStatement(1, 'bah')); $this->assertEquals(array('P1' => new PropertyId('P1'), 'P3' => new PropertyId('P3'), 'P2' => new PropertyId('P2')), $list->getPropertyIds()); }
/** * Adds Statements to the RDF graph. * * @param EntityId $entityId * @param StatementList $statementList */ public function addStatements(EntityId $entityId, StatementList $statementList) { $bestList = array(); // FIXME: This is expensive, share the result with TruthyStatementRdfBuilder! foreach ($statementList->getPropertyIds() as $propertyId) { $bestStatements = $statementList->getByPropertyId($propertyId)->getBestStatements(); foreach ($bestStatements->toArray() as $statement) { $bestList[$statement->getGuid()] = true; } } foreach ($statementList->toArray() as $statement) { $this->addStatement($entityId, $statement, isset($bestList[$statement->getGuid()])); } }