/**
  * @param int $produce One of the RdfProducer::PRODUCE_... constants.
  * @param DedupeBag|null $dedup
  *
  * @return RdfBuilder
  */
 private function newRdfBuilder($produce, DedupeBag $dedup = null)
 {
     if ($dedup === null) {
         $dedup = new HashDedupeBag();
     }
     // Note: using the actual factory here makes this an integration test!
     $valueBuilderFactory = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory();
     $emitter = new NTriplesRdfWriter();
     $builder = new RdfBuilder($this->getTestData()->getSiteList(), $this->getTestData()->getVocabulary(), $valueBuilderFactory, $this->getTestData()->getMockRepository(), $produce, $emitter, $dedup);
     $builder->startDocument();
     return $builder;
 }
 /**
  * Produces RDF dump of the entity
  *
  * @param EntityId $entityId
  *
  * @throws EntityLookupException
  * @throws StorageException
  * @return string|null RDF
  */
 protected function generateDumpForEntityId(EntityId $entityId)
 {
     try {
         $entityRevision = $this->entityRevisionLookup->getEntityRevision($entityId);
         if (!$entityRevision) {
             throw new EntityLookupException($entityId, 'Entity not found: ' . $entityId->getSerialization());
         }
         $this->rdfBuilder->addEntityRevisionInfo($entityRevision->getEntity()->getId(), $entityRevision->getRevisionId(), $entityRevision->getTimestamp());
         $this->rdfBuilder->addEntity($entityRevision->getEntity());
     } catch (MWContentSerializationException $ex) {
         throw new StorageException('Deserialization error for ' . $entityId->getSerialization());
     } catch (RevisionedUnresolvedRedirectException $e) {
         if ($e->getRevisionId() > 0) {
             $this->rdfBuilder->addEntityRevisionInfo($entityId, $e->getRevisionId(), $e->getRevisionTimestamp());
         }
         $this->rdfBuilder->addEntityRedirect($entityId, $e->getRedirectTargetId());
     }
     $rdf = $this->rdfBuilder->getRDF();
     return $rdf;
 }
Esempio n. 3
0
 /**
  * Extract text test data from RDF builder
  * @param RdfBuilder $builder
  * @return string[] ntriples lines
  */
 private function getDataFromBuilder(RdfBuilder $builder)
 {
     $data = $builder->getRDF();
     $dataSplit = explode("\n", trim($data));
     sort($dataSplit);
     $dataSplit = array_map('trim', $dataSplit);
     return $dataSplit;
 }
 /**
  * @param EntityId $targetId
  * @param EntityRedirect|null $followedRedirect The followed redirect, will be omitted from the
  * output.
  * @param EntityId[] $incomingRedirects
  * @param RdfBuilder $rdfBuilder
  */
 private function addIncomingRedirects(EntityId $targetId, EntityRedirect $followedRedirect = null, array $incomingRedirects, RdfBuilder $rdfBuilder)
 {
     foreach ($incomingRedirects as $rId) {
         // don't add the followed redirect again
         if (!$followedRedirect || !$followedRedirect->getEntityId()->equals($rId)) {
             $rdfBuilder->addEntityRedirect($rId, $targetId);
         }
     }
 }