Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/199622
Change subject: Clean up RDF and Dumpers related code
......................................................................
Clean up RDF and Dumpers related code
Nothing here should change semantics. This is a pure clean up patch.
* Fix some wrong type hints
* More specific type hints
* Drop some none-descriptive method descriptions
* Optimize imports
* Split long lines
* Code formatting according to style guide
Change-Id: If782b9e1e17973f31c5b25f73cb07f59109b042b
---
M repo/includes/Dumpers/DumpGenerator.php
M repo/includes/Dumpers/JsonDumpGenerator.php
M repo/includes/Dumpers/RdfDumpGenerator.php
M repo/includes/rdf/BNodeLabeler.php
M repo/includes/rdf/N3RdfWriterBase.php
M repo/includes/rdf/NTriplesRdfWriter.php
M repo/includes/rdf/RdfBuilder.php
M repo/includes/rdf/RdfProducer.php
M repo/includes/rdf/RdfSerializer.php
M repo/includes/rdf/RdfWriterBase.php
M repo/includes/rdf/TurtleRdfWriter.php
M repo/includes/rdf/UnicodeEscaper.php
M repo/includes/rdf/XmlRdfWriter.php
M repo/maintenance/dumpRdf.php
M repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
15 files changed, 273 insertions(+), 221 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/22/199622/1
diff --git a/repo/includes/Dumpers/DumpGenerator.php
b/repo/includes/Dumpers/DumpGenerator.php
index 7b75da1..771f58b 100644
--- a/repo/includes/Dumpers/DumpGenerator.php
+++ b/repo/includes/Dumpers/DumpGenerator.php
@@ -3,8 +3,6 @@
namespace Wikibase\Dumpers;
use InvalidArgumentException;
-use MWContentSerializationException;
-use MWException;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\Lib\Reporting\ExceptionHandler;
use Wikibase\Lib\Reporting\MessageReporter;
@@ -61,6 +59,7 @@
/**
* Entity count limit - dump will generate this many
+ *
* @var int
*/
protected $limit = 0;
@@ -83,6 +82,7 @@
/**
* Set maximum number of entities produced
+ *
* @param int $limit
*/
public function setLimit( $limit ) {
@@ -174,14 +174,17 @@
* Set the entity type to be included in the output.
*
* @param string|null $type The desired type (use null for any type).
+ *
* @throws InvalidArgumentException
*/
public function setEntityTypeFilter( $type ) {
$this->entityType = $type;
}
+
private function idMatchesFilters( EntityId $entityId ) {
return $this->idMatchesShard( $entityId ) &&
$this->idMatchesType( $entityId );
}
+
private function idMatchesShard( EntityId $entityId ) {
// Shorten out
if ( $this->shardingFactor === 1 ) {
@@ -258,7 +261,7 @@
$this->progressReporter->reportMessage( 'Processed ' .
$dumpCount . ' entities.' );
- if( $this->limit && $dumpCount >= $this->limit ) {
+ if ( $this->limit && $dumpCount >= $this->limit ) {
break;
}
}
@@ -268,6 +271,7 @@
/**
* Dump list of entities
+ *
* @param EntityId[] $entityIds
* @param int &$dumpCount The number of entities already dumped (will
be updated).
*/
@@ -288,7 +292,7 @@
$this->postEntityDump( $dumpCount );
$dumpCount ++;
- if( $this->limit && $dumpCount >= $this->limit
) {
+ if ( $this->limit && $dumpCount >= $this->limit
) {
break;
}
} catch ( StorageException $ex ) {
@@ -303,8 +307,8 @@
* @param EntityId $entityId
*
* @throws StorageException
- *
* @return string|null
*/
abstract protected function generateDumpForEntityId( EntityId $entityId
);
+
}
diff --git a/repo/includes/Dumpers/JsonDumpGenerator.php
b/repo/includes/Dumpers/JsonDumpGenerator.php
index dd8a3c5..2a35aa7 100644
--- a/repo/includes/Dumpers/JsonDumpGenerator.php
+++ b/repo/includes/Dumpers/JsonDumpGenerator.php
@@ -157,4 +157,5 @@
public function getJsonFlags() {
return $this->jsonFlags;
}
+
}
diff --git a/repo/includes/Dumpers/RdfDumpGenerator.php
b/repo/includes/Dumpers/RdfDumpGenerator.php
index 212a362..28976ca 100644
--- a/repo/includes/Dumpers/RdfDumpGenerator.php
+++ b/repo/includes/Dumpers/RdfDumpGenerator.php
@@ -2,20 +2,20 @@
namespace Wikibase\Dumpers;
+use HashBagOStuff;
use InvalidArgumentException;
use MWContentSerializationException;
use MWException;
use SiteList;
use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\Lib\Serializers\Serializer;
+use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
use Wikibase\Lib\Store\EntityLookup;
+use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Lib\Store\RedirectResolvingEntityLookup;
use Wikibase\Lib\Store\StorageException;
use Wikibase\Lib\Store\UnresolvedRedirectException;
-use Wikibase\Lib\Store\EntityRevisionLookup;
-use Wikibase\RdfSerializer;
use Wikibase\RdfProducer;
-use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
+use Wikibase\RdfSerializer;
/**
* RdfDumpGenerator generates an RDF dump of a given set of entities, excluding
@@ -30,34 +30,29 @@
class RdfDumpGenerator extends DumpGenerator {
/**
- *
* @var RdfSerializer
*/
private $entitySerializer;
/**
- *
* @var EntityRevisionLookup
*/
private $entityRevisionLookup;
/**
- * List of the prefixes we've seen in the dump
- * @var array
+ * @var bool[] List of the prefixes we've seen in the dump.
*/
private $prefixes;
/**
- * Fixed timestamp for tests
- * @var int
+ * @var int Fixed timestamp for tests.
*/
private $timestamp;
/**
- *
* @param resource $out
- * @param EntityLookup $lookup Must not resolve redirects
- * @param Serializer $entitySerializer
+ * @param EntityRevisionLookup $lookup Must not resolve redirects
+ * @param RdfSerializer $entitySerializer
*
* @throws InvalidArgumentException
*/
@@ -75,6 +70,7 @@
* Cleanup prefixes in the dump to avoid repetitions
*
* @param string $data
+ *
* @return string
*/
protected function cleanupPrefixes( $data ) {
@@ -99,10 +95,10 @@
/**
* Produces RDF dump of the entity
+ *
* @param EntityId $entityId
*
* @throws StorageException
- *
* @return string|null
*/
protected function generateDumpForEntityId( EntityId $entityId ) {
@@ -122,21 +118,24 @@
return $this->cleanupPrefixes( $data );
}
- public function setTimestamp( $ts ) {
- $this->timestamp = (int)$ts;
+ /**
+ * @param int $timestamp
+ */
+ public function setTimestamp( $timestamp ) {
+ $this->timestamp = (int)$timestamp;
}
/**
- * Create dump generator
* @param string $format
- * @param string $output
+ * @param resource $output
* @param string $baseUri
* @param string $dataUri
* @param SiteList $sites
* @param EntityLookup $entityLookup
* @param EntityRevisionLookup $entityRevisionLookup
- * @param PropertyInfoDataTypeLookup $propertyLookup
- * @throws \MWException
+ * @param PropertyDataTypeLookup $propertyLookup
+ *
+ * @throws MWException
* @return RdfDumpGenerator
*/
public static function createDumpGenerator(
@@ -150,8 +149,8 @@
PropertyDataTypeLookup $propertyLookup
) {
$rdfFormat = RdfSerializer::getFormat( $format );
- if( !$rdfFormat ) {
- throw new \MWException( "Unknown format: $format" );
+ if ( !$rdfFormat ) {
+ throw new MWException( "Unknown format: $format" );
}
$entitySerializer = new RdfSerializer( $rdfFormat,
$baseUri,
@@ -162,8 +161,9 @@
RdfProducer::PRODUCE_ALL_STATEMENTS |
RdfProducer::PRODUCE_TRUTHY_STATEMENTS |
RdfProducer::PRODUCE_QUALIFIERS |
RdfProducer::PRODUCE_REFERENCES |
RdfProducer::PRODUCE_SITELINKS |
RdfProducer::PRODUCE_FULL_VALUES,
- new \HashBagOStuff()
+ new HashBagOStuff()
);
return new RdfDumpGenerator( $output, $entityRevisionLookup,
$entitySerializer );
}
+
}
diff --git a/repo/includes/rdf/BNodeLabeler.php
b/repo/includes/rdf/BNodeLabeler.php
index ed94c34..dfdee00 100644
--- a/repo/includes/rdf/BNodeLabeler.php
+++ b/repo/includes/rdf/BNodeLabeler.php
@@ -28,6 +28,8 @@
/**
* @param string $prefix
* @param int $start
+ *
+ * @throws InvalidArgumentException
*/
public function __construct( $prefix = 'genid', $start = 1 ) {
if ( !is_string( $prefix ) ) {
diff --git a/repo/includes/rdf/N3RdfWriterBase.php
b/repo/includes/rdf/N3RdfWriterBase.php
index 25059f7..a6fb496 100644
--- a/repo/includes/rdf/N3RdfWriterBase.php
+++ b/repo/includes/rdf/N3RdfWriterBase.php
@@ -28,14 +28,14 @@
}
/**
- * @return boolean
+ * @return bool
*/
public function getTrustIRIs() {
return $this->trustIRIs;
}
/**
- * @param boolean $trustIRIs
+ * @param bool $trustIRIs
*/
public function setTrustIRIs( $trustIRIs ) {
$this->trustIRIs = $trustIRIs;
@@ -43,7 +43,7 @@
protected function writeRef( $base, $local = null ) {
if ( $local === null ) {
- if( $this->isShorthand( $base) ) {
+ if ( $this->isShorthand( $base ) ) {
$this->writeShorthand( $base );
} else {
$this->writeIRI( $base );
@@ -99,7 +99,7 @@
}
}
- protected function writeValue( $value, $typeBase = null, $typeLocal =
null ) {
+ protected function writeValue( $value, $typeBase = null, $typeLocal =
null ) {
$value = $this->quoter->escapeLiteral( $value );
$this->write( '"', $value, '"' );
diff --git a/repo/includes/rdf/NTriplesRdfWriter.php
b/repo/includes/rdf/NTriplesRdfWriter.php
index 7449546..d0263a5 100644
--- a/repo/includes/rdf/NTriplesRdfWriter.php
+++ b/repo/includes/rdf/NTriplesRdfWriter.php
@@ -69,7 +69,7 @@
parent::writeText( $text, $language );
}
- protected function writeValue( $value, $typeBase = null, $typeLocal =
null ) {
+ protected function writeValue( $value, $typeBase = null, $typeLocal =
null ) {
$this->writeSubjectAndObject();
$this->write( ' ' );
diff --git a/repo/includes/rdf/RdfBuilder.php b/repo/includes/rdf/RdfBuilder.php
index bdd80de..8d8280f 100644
--- a/repo/includes/rdf/RdfBuilder.php
+++ b/repo/includes/rdf/RdfBuilder.php
@@ -2,31 +2,35 @@
namespace Wikibase;
+use BagOStuff;
use DataValues\DataValue;
+use DataValues\DecimalValue;
+use DataValues\GlobeCoordinateValue;
+use DataValues\MonolingualTextValue;
+use DataValues\QuantityValue;
+use DataValues\StringValue;
+use DataValues\TimeValue;
use EasyRdf_Graph;
use EasyRdf_Literal;
+use EasyRdf_Literal_DateTime;
use EasyRdf_Namespace;
use EasyRdf_Resource;
use SiteList;
-use BagOStuff;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
use Wikibase\DataModel\Entity\Entity;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\EntityIdValue;
use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
+use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Reference;
+use Wikibase\DataModel\SiteLink;
+use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Snak\Snak;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\StatementListProvider;
use Wikibase\Lib\Store\EntityLookup;
-use Wikibase\DataModel\Entity\EntityIdValue;
-use DataValues\TimeValue;
-use DataValues\QuantityValue;
-use DataValues\StringValue;
-use DataValues\MonolingualTextValue;
-use DataValues\GlobeCoordinateValue;
-use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
-use DataValues\DecimalValue;
/**
* RDF mapping for wikibase data model.
@@ -40,6 +44,7 @@
* @author Stas Malyshev
*/
class RdfBuilder {
+
// Change this when changing data format!
const FORMAT_VERSION = '0.0.1';
@@ -92,7 +97,6 @@
);
/**
- *
* @var SiteList
*/
private $sites;
@@ -115,7 +119,6 @@
private $entitiesResolved = array ();
/**
- *
* @var PropertyDataTypeLookup
*/
private $propertyLookup;
@@ -133,7 +136,6 @@
private $dedupBag;
/**
- *
* @param SiteList $sites
* @param string $baseUri
* @param string $dataUri
@@ -249,11 +251,12 @@
/**
* Should we produce this aspect?
*
- * @param integer $what
- * @return boolean
+ * @param int $what
+ *
+ * @return bool
*/
private function shouldProduce( $what ) {
- return ( $this->produceWhat & $what ) != 0;
+ return ( $this->produceWhat & $what ) !== 0;
}
/**
@@ -339,19 +342,19 @@
* Adds meta-information about an entity (such as the ID and type) to
the RDF graph.
*
* @param Entity $entity
- * @param boolean $produceData Should we also produce Dataset node?
+ * @param bool $produceData Should we also produce Dataset node?
*/
private function addEntityMetaData( Entity $entity, $produceData = true
) {
$entityResource = $this->getEntityResource( $entity->getId() );
$entityResource->addResource( 'rdf:type',
$this->getEntityTypeQName( $entity->getType() ) );
$dataURL = $this->getDataURL( $entity->getId() );
- if( $produceData ) {
+ if ( $produceData ) {
$dataResource = $this->graph->resource( $dataURL );
$dataResource->addResource( 'rdf:type',
self::NS_SCHEMA_ORG . ":Dataset" );
$dataResource->addResource( self::NS_SCHEMA_ORG .
':about', $entityResource );
- if( $this->shouldProduce(
RdfProducer::PRODUCE_VERSION_INFO ) ) {
+ if ( $this->shouldProduce(
RdfProducer::PRODUCE_VERSION_INFO ) ) {
// Dumps don't need version/license info for
each entity, since it is included in the dump header
$dataResource->addResource( self::NS_CC .
':license', self::LICENSE );
$dataResource->addLiteral( self::NS_SCHEMA_ORG
. ':softwareVersion', self::FORMAT_VERSION );
@@ -426,6 +429,7 @@
private function addSiteLinks( Item $item ) {
$entityResource = $this->getEntityResource( $item->getId() );
+ /** @var SiteLink $siteLink */
foreach ( $item->getSiteLinkList() as $siteLink ) {
$site = $this->sites->getSite( $siteLink->getSiteId() );
@@ -465,7 +469,7 @@
$produceTruthy = $this->shouldProduce(
RdfProducer::PRODUCE_TRUTHY_STATEMENTS ) ;
foreach ( $statementList->getBestStatementPerProperty()
as $statement ) {
$bestList[$statement->getGuid()] = true;
- if( $produceTruthy ) {
+ if ( $produceTruthy ) {
$this->addMainSnak( $entityId,
$statement, true );
}
}
@@ -480,16 +484,18 @@
/**
* Did we already see this value? If yes, we may need to skip it
+ *
* @param string $hash hash value to check
* @param string $namespace
- * @return boolean
+ *
+ * @return bool
*/
private function alreadySeen( $hash, $namespace ) {
- if( !$this->dedupBag ) {
+ if ( !$this->dedupBag ) {
return false;
}
$key = $namespace . substr($hash, 0, 5);
- if( $this->dedupBag->get( $key ) !== $hash ) {
+ if ( $this->dedupBag->get( $key ) !== $hash ) {
$this->dedupBag->set( $key, $hash );
return false;
}
@@ -501,7 +507,7 @@
*
* @param EntityId $entityId
* @param Statement $statement
- * @param boolean $isBest Is this best ranked statement?
+ * @param bool $isBest Is this best ranked statement?
*/
private function addStatement( EntityId $entityId, Statement
$statement, $isBest = false ) {
$this->addMainSnak( $entityId, $statement, false, $isBest );
@@ -516,15 +522,16 @@
if ( $this->shouldProduce( RdfProducer::PRODUCE_REFERENCES ) ) {
$statementResource = $this->getStatementResource(
$statement );
- foreach ( $statement->getReferences() as $ref ) {
//FIXME: split body into separate method
- $hash = $ref->getHash();
+ /** @var Reference $reference */
+ foreach ( $statement->getReferences() as $reference ) {
//FIXME: split body into separate method
+ $hash = $reference->getHash();
$refQName = self::NS_REFERENCE . ':' . $hash;
$statementResource->addResource(
self::PROV_QNAME, $refQName );
- if( $this->alreadySeen( $hash, 'R' ) ) {
+ if ( $this->alreadySeen( $hash, 'R' ) ) {
continue;
}
$refResource = $this->graph->resource(
$refQName, array ( self::WIKIBASE_REFERENCE_QNAME ) );
- foreach ( $ref->getSnaks() as $refSnak ) {
+ foreach ( $reference->getSnaks() as $refSnak ) {
$this->addSnak( $refResource, $refSnak,
self::NS_VALUE );
}
}
@@ -536,8 +543,8 @@
*
* @param EntityId $entityId
* @param Statement $statement
- * @param boolean $truthy Is this producing "truthy" or full-form
statement?
- * @param boolean $isBest Is this best ranked statement?
+ * @param bool $truthy Is this producing "truthy" or full-form
statement?
+ * @param bool $isBest Is this best ranked statement?
*/
private function addMainSnak( EntityId $entityId, Statement $statement,
$truthy, $isBest = false ) {
$snak = $statement->getMainSnak();
@@ -552,17 +559,17 @@
$entityResource->addResource( $propertyQName,
$statementResource );
$this->addSnak( $statementResource, $snak,
self::NS_VALUE );
- if( $this->shouldProduce(
RdfProducer::PRODUCE_PROPERTIES) ) {
+ if ( $this->shouldProduce(
RdfProducer::PRODUCE_PROPERTIES) ) {
$this->entityMentioned( $snak->getPropertyId()
);
}
$rank = $statement->getRank();
- if( isset( self::$rankMap[$rank] ) ) {
+ if ( isset( self::$rankMap[$rank] ) ) {
$statementResource->addResource(
self::WIKIBASE_RANK_QNAME, self::$rankMap[$rank] );
} else {
wfLogWarning( "Unknown rank $rank encountered
for $entityId:{$statement->getGuid()}" );
}
- if( $isBest ) {
+ if ( $isBest ) {
$statementResource->addResource(
self::WIKIBASE_RANK_QNAME, self::WIKIBASE_RANK_BEST );
}
@@ -594,14 +601,15 @@
private function addSnak( EasyRdf_Resource $target, Snak $snak,
$propertyNamespace, $simpleValue = false ) {
$propertyId = $snak->getPropertyId();
switch ( $snak->getType() ) {
- case 'value' :
+ case 'value':
+ /** @var PropertyValueSnak $snak */
$this->addStatementValue( $target, $propertyId,
$snak->getDataValue(), $propertyNamespace, $simpleValue );
break;
- case 'somevalue' :
+ case 'somevalue':
$propertyValueQName = $this->getEntityQName(
$propertyNamespace, $propertyId );
$target->addResource( $propertyValueQName,
self::WIKIBASE_SOMEVALUE_QNAME );
break;
- case 'novalue' :
+ case 'novalue':
$propertyValueQName = $this->getEntityQName(
$propertyNamespace, $propertyId );
$target->addResource( $propertyValueQName,
self::WIKIBASE_NOVALUE_QNAME );
break;
@@ -610,23 +618,29 @@
/**
* Created full data value
+ *
* @param EasyRdf_Resource $target Place to attach the value
* @param string $propertyValueQName Relationship name
* @param DataValue $value
* @param array $props List of properties
*/
- private function addExpandedValue( EasyRdf_Resource $target,
$propertyValueQName, DataValue $value, array $props) {
+ private function addExpandedValue(
+ EasyRdf_Resource $target,
+ $propertyValueQName,
+ DataValue $value,
+ array $props
+ ) {
$hash = $value->getHash();
- $vname = self::NS_VALUE . ":" . $hash;
- $target->addResource( $propertyValueQName."-value", $vname );
- if( $this->alreadySeen( $hash, 'V' ) ) {
+ $vname = self::NS_VALUE . ':' . $hash;
+ $target->addResource( $propertyValueQName . '-value', $vname );
+ if ( $this->alreadySeen( $hash, 'V' ) ) {
return;
}
$node = $this->graph->resource( $vname,
self::WIKIBASE_VALUE_QNAME );
- foreach( $props as $prop => $type ) {
- $getter = "get" . ucfirst( $prop );
+ foreach ( $props as $prop => $type ) {
+ $getter = 'get' . ucfirst( $prop );
$data = $value->$getter();
- if( !is_null( $data ) ) {
+ if ( !is_null( $data ) ) {
$this->addValueToNode( $node,
$this->getEntityTypeQName( $prop ), $type, $data );
}
}
@@ -636,17 +650,22 @@
* Adds the value of the given property to the RDF graph.
*
* @param EasyRdf_Resource $target
- * @param EntityId $propertyId
+ * @param PropertyId $propertyId
* @param DataValue $value
* @param string $propertyNamespace The property namespace for this snak
* @param bool $simpleValue
*/
- private function addStatementValue( EasyRdf_Resource $target, EntityId
$propertyId,
- DataValue $value, $propertyNamespace, $simpleValue =
false ) {
+ private function addStatementValue(
+ EasyRdf_Resource $target,
+ PropertyId $propertyId,
+ DataValue $value,
+ $propertyNamespace,
+ $simpleValue = false
+ ) {
$propertyValueQName = $this->getEntityQName(
$propertyNamespace, $propertyId );
$typeId = $value->getType();
- if( $typeId == 'string' ) {
+ if ( $typeId === 'string' ) {
// Only strings have different types now, so we can
save time but not asking
// for any other types
$dataType =
$this->propertyLookup->getDataTypeIdForProperty( $propertyId );
@@ -655,9 +674,9 @@
}
//FIXME: use a proper registry / dispatching builder
- $typeFunc = "addStatementFor".preg_replace( '/[^\w]/', '',
ucwords( $typeId ) );
+ $typeFunc = 'addStatementFor' . preg_replace( '/[^\w]/', '',
ucwords( $typeId ) );
- if( !is_callable( array( $this, $typeFunc ) ) ) {
+ if ( !is_callable( array( $this, $typeFunc ) ) ) {
wfLogWarning( __METHOD__ . ": Unsupported data type:
$typeId" );
} else {
$this->$typeFunc( $target, $propertyValueQName,
$dataType, $value, $simpleValue );
@@ -667,39 +686,45 @@
}
/**
- * Adds specific value
- *
* @param EasyRdf_Resource $target
* @param string $propertyValueQName Property name
* @param string $dataType Property data type
* @param EntityIdValue $value
* @param bool $simpleValue
*/
- private function addStatementForWikibaseEntityid( EasyRdf_Resource
$target, $propertyValueQName, $dataType,
- EntityIdValue $value, $simpleValue = false ) {
+ private function addStatementForWikibaseEntityid(
+ EasyRdf_Resource $target,
+ $propertyValueQName,
+ $dataType,
+ EntityIdValue $value,
+ $simpleValue = false
+ ) {
$entityId = $value->getValue()->getEntityId();
$entityQName = $this->getEntityQName( self::NS_ENTITY,
$entityId );
$entityResource = $this->graph->resource( $entityQName );
$target->addResource( $propertyValueQName, $entityResource );
- if( $this->shouldProduce(
RdfProducer::PRODUCE_RESOLVED_ENTITIES ) ) {
+ if ( $this->shouldProduce(
RdfProducer::PRODUCE_RESOLVED_ENTITIES ) ) {
$this->entityMentioned( $entityId );
}
}
/**
- * Adds specific value
- *
* @param EasyRdf_Resource $target
* @param string $propertyValueQName Property name
* @param string $dataType Property data type
* @param StringValue $value
* @param bool $simpleValue
*/
- private function addStatementForString( EasyRdf_Resource $target,
$propertyValueQName, $dataType,
- StringValue $value, $simpleValue = false ) {
- if ( $dataType == 'commonsMedia' ) {
+ private function addStatementForString(
+ EasyRdf_Resource $target,
+ $propertyValueQName,
+ $dataType,
+ StringValue $value,
+ $simpleValue = false
+ ) {
+ if ( $dataType === 'commonsMedia' ) {
$this->addValueToNode( $target, $propertyValueQName,
'url', $this->getCommonsURI( $value->getValue() ) );
- } elseif ( $dataType == 'url' ) {
+ } elseif ( $dataType === 'url' ) {
$this->addValueToNode( $target, $propertyValueQName,
'url', $value->getValue() );
} else {
$target->addLiteral( $propertyValueQName, new
EasyRdf_Literal( $value->getValue() ) );
@@ -716,19 +741,19 @@
* @param string $value
*/
private function addValueToNode( EasyRdf_Resource $target,
$propertyName, $type, $value ) {
- if( $type == 'url' ) {
+ if ( $type === 'url' ) {
$target->addResource( $propertyName, $value );
- } elseif( $type == 'xsd:dateTime' ) {
+ } elseif ( $type === 'xsd:dateTime' ) {
$target->addLiteral( $propertyName,
new \EasyRdf_Literal_DateTime(
$this->cleanupDateValue( $value ) ) );
- } elseif( $type == 'xsd:decimal' ) {
+ } elseif ( $type === 'xsd:decimal' ) {
// TODO: handle precision here?
- if( $value instanceof DecimalValue ) {
+ if ( $value instanceof DecimalValue ) {
$value = $value->getValue();
}
$target->addLiteral( $propertyName, new
\EasyRdf_Literal_Decimal( $value ) );
} else {
- if( !is_scalar( $value ) ) {
+ if ( !is_scalar( $value ) ) {
// somehow we got a weird value, better not
risk it and bail
$vtype = gettype( $value );
wfLogWarning( "Bad value passed to
addValueToNode for {$target->getUri()}:$propertyName: $vtype" );
@@ -738,18 +763,20 @@
}
}
-
/**
- * Adds specific value
- *
* @param EasyRdf_Resource $target
* @param string $propertyValueQName Property name
* @param string $dataType Property data type
* @param MonolingualTextValue $value
* @param bool $simpleValue
*/
- private function addStatementForMonolingualtext( EasyRdf_Resource
$target, $propertyValueQName, $dataType,
- MonolingualTextValue $value, $simpleValue = false ) {
+ private function addStatementForMonolingualtext(
+ EasyRdf_Resource $target,
+ $propertyValueQName,
+ $dataType,
+ MonolingualTextValue $value,
+ $simpleValue = false
+ ) {
$target->addLiteral( $propertyValueQName, $value->getText(),
$value->getLanguageCode() );
}
@@ -757,16 +784,18 @@
* Clean up Wikidata date value in Gregorian calendar
* - remove + from the start - not all data stores like that
* - validate month and date value
+ *
* @param string $dateValue
+ *
* @return string Value compatible with xsd:dateTime type
*/
private function cleanupDateValue( $dateValue ) {
- list($date, $time) = explode( "T", $dateValue, 2 );
- if( $date[0] == "-" ) {
- list($y, $m, $d) = explode( "-", substr( $date, 1 ), 3
);
+ list( $date, $time ) = explode( 'T', $dateValue, 2 );
+ if ( $date[0] === '-' ) {
+ list( $y, $m, $d ) = explode( '-', substr( $date, 1 ),
3 );
$y = -(int)$y;
} else {
- list($y, $m, $d) = explode( "-", $date, 3 );
+ list( $y, $m, $d ) = explode( '-', $date, 3 );
$y = (int)$y;
}
@@ -775,25 +804,25 @@
// PHP source docs say PHP gregorian calendar can work down to
4714 BC
// for smaller dates, we ignore month/day
- if( $y <= -4714 ) {
+ if ( $y <= -4714 ) {
$d = $m = 1;
}
- if( $m <= 0 ) {
+ if ( $m <= 0 ) {
$m = 1;
}
- if( $m >= 12 ) {
+ if ( $m >= 12 ) {
// Why anybody would do something like that? Anyway,
better to check.
$m = 12;
}
- if( $d <= 0 ) {
+ if ( $d <= 0 ) {
$d = 1;
}
// check if the date "looks safe". If not, we do deeper check
- if( !( $d <= 28 || ( $m != 2 && $d <= 30 ) ) ) {
+ if ( !( $d <= 28 || ( $m != 2 && $d <= 30 ) ) ) {
$max = cal_days_in_month( CAL_GREGORIAN, $m, $y );
// We just put it as the last day in month, won't
bother further
- if( $d > $max ) {
+ if ( $d > $max ) {
$d = $max;
}
}
@@ -801,7 +830,7 @@
// and leading 0 is not allowed for 5 digits
// But sprintf counts - as digit
// See: http://www.w3.org/TR/xmlschema-2/#dateTime
- return sprintf( "%s%04d-%02d-%02dT%s", ($y < 0)? "-":"", abs(
$y ), $m, $d, $time );
+ return sprintf( "%s%04d-%02d-%02dT%s", $y < 0 ? '-' : '', abs(
$y ), $m, $d, $time );
}
/**
@@ -813,16 +842,14 @@
*/
private function getDateLiteral( TimeValue $value ) {
$calendar = $value->getCalendarModel();
- if( $calendar == self::GREGORIAN_CALENDAR ) {
- return new \EasyRdf_Literal_DateTime(
$this->cleanupDateValue( $value->getTime() ) );
+ if ( $calendar === self::GREGORIAN_CALENDAR ) {
+ return new EasyRdf_Literal_DateTime(
$this->cleanupDateValue( $value->getTime() ) );
}
// TODO: add handling for Julian values
return new EasyRdf_Literal( $value->getTime() );
}
/**
- * Adds specific value
- *
* @param EasyRdf_Resource $target
* @param string $propertyValueQName Property name
* @param string $dataType Property data type
@@ -850,8 +877,6 @@
}
/**
- * Adds specific value
- *
* @param EasyRdf_Resource $target
* @param string $propertyValueQName Property name
* @param string $dataType Property data type
@@ -873,8 +898,6 @@
}
/**
- * Adds specific value
- *
* @param EasyRdf_Resource $target
* @param string $propertyValueQName Property name
* @param string $dataType Property data type
@@ -957,15 +980,17 @@
/**
* Create header structure for the dump
- * @param int $ts Timestamp (for testing)
+ *
+ * @param int $timestamp Timestamp (for testing)
*/
- public function addDumpHeader( $ts = 0 ) {
+ public function addDumpHeader( $timestamp = 0 ) {
// TODO: this should point to "this document"
$dataResource = $this->graph->resource(
$this->getEntityTypeQName( 'Dump' ) );
$dataResource->addResource( 'rdf:type', self::NS_SCHEMA_ORG .
":Dataset" );
$dataResource->addResource( self::NS_CC . ':license',
self::LICENSE );
$dataResource->addLiteral( self::NS_SCHEMA_ORG .
':softwareVersion', self::FORMAT_VERSION );
$dataResource->addLiteral( self::NS_SCHEMA_ORG .
':dateModified',
- new EasyRdf_Literal( wfTimestamp( TS_ISO_8601,
$ts ), null, 'xsd:dateTime' ) );
+ new EasyRdf_Literal( wfTimestamp( TS_ISO_8601,
$timestamp ), null, 'xsd:dateTime' ) );
}
+
}
diff --git a/repo/includes/rdf/RdfProducer.php
b/repo/includes/rdf/RdfProducer.php
index 24f722d..571427a 100644
--- a/repo/includes/rdf/RdfProducer.php
+++ b/repo/includes/rdf/RdfProducer.php
@@ -42,7 +42,6 @@
/**
* Produce full expanded values as nodes.
* Should be used together with PRODUCE_ALL_STATEMENTS.
- * @var unknown
*/
const PRODUCE_FULL_VALUES = 64;
@@ -60,4 +59,4 @@
* All options turned on.
*/
const PRODUCE_ALL = 0xFFFF;
-}
\ No newline at end of file
+}
diff --git a/repo/includes/rdf/RdfSerializer.php
b/repo/includes/rdf/RdfSerializer.php
index 85b7cee..b6da65f 100644
--- a/repo/includes/rdf/RdfSerializer.php
+++ b/repo/includes/rdf/RdfSerializer.php
@@ -2,12 +2,13 @@
namespace Wikibase;
+use BagOStuff;
use EasyRdf_Exception;
use EasyRdf_Format;
use EasyRdf_Graph;
use SiteList;
-use Wikibase\Lib\Store\EntityLookup;
use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
+use Wikibase\Lib\Store\EntityLookup;
/**
* RDF serialization for wikibase data model.
@@ -69,7 +70,8 @@
* @param SiteList $sites;
* @param EntityLookup $entityLookup
* @param PropertyDataTypeLookup $propertyLookup
- * @param integer flavor
+ * @param int $flavor
+ * @param BagOStuff|null $dedupBag
*/
public function __construct(
EasyRdf_Format $format,
@@ -79,7 +81,7 @@
PropertyDataTypeLookup $propertyLookup,
EntityLookup $entityLookup,
$flavor,
- \BagOStuff $dedupBag = null
+ BagOStuff $dedupBag = null
) {
$this->baseUri = $baseUri;
$this->dataUri = $dataUri;
diff --git a/repo/includes/rdf/RdfWriterBase.php
b/repo/includes/rdf/RdfWriterBase.php
index a42e610..50f63da 100644
--- a/repo/includes/rdf/RdfWriterBase.php
+++ b/repo/includes/rdf/RdfWriterBase.php
@@ -2,6 +2,7 @@
namespace Wikibase\RDF;
+use Closure;
use InvalidArgumentException;
use LogicException;
@@ -43,7 +44,7 @@
private $shorthands = array();
/**
- * @var array[] a map of prefixes to base IRIs
+ * @var string[] a map of prefixes to base IRIs
*/
private $prefixes = array();
@@ -87,6 +88,8 @@
/**
* @param string $role The writer's role, use the XXX_ROLE constants.
* @param BNodeLabeler $labeler
+ *
+ * @throws InvalidArgumentException
*/
function __construct( $role, BNodeLabeler $labeler = null ) {
if ( !is_string( $role ) ) {
@@ -137,6 +140,7 @@
* Determines whether $shorthand can be used as a shorthand.
*
* @param string $shorthand
+ *
* @return bool
*/
protected function isShorthand( $shorthand ) {
@@ -147,6 +151,7 @@
* Determines whether $shorthand can legally be used as a prefix.
*
* @param string $prefix
+ *
* @return bool
*/
protected function isPrefix( $prefix ) {
@@ -156,7 +161,7 @@
/**
* Returns the prefix map.
*
- * @return array An associative array mapping prefixes to base IRIs.
+ * @return string[] An associative array mapping prefixes to base IRIs.
*/
public function getPrefixes() {
return $this->prefixes;
@@ -195,7 +200,7 @@
/**
* Appends any parameters to the output buffer.
*
- * @param string $s...
+ * @param string [$text,...]
*/
final protected function write() {
foreach ( func_get_args() as $arg ) {
@@ -226,6 +231,8 @@
*
* @param string &$base
* @param string|null &$local
+ *
+ * @throws LogicException
*/
protected function expandQName( &$base, &$local ) {
if ( $local !== null && $base !== '_' ) {
@@ -296,7 +303,7 @@
*/
private function flattenBuffer() {
foreach ( $this->buffer as &$b ) {
- if ( $b instanceof \Closure ) {
+ if ( $b instanceof Closure ) {
$b = $b();
}
if ( $b instanceof RdfWriter ) {
@@ -464,6 +471,8 @@
* parser.
*
* @param $newState
+ *
+ * @throws InvalidArgumentException
*/
final protected function state( $newState ) {
switch ( $newState ) {
@@ -488,7 +497,7 @@
break;
default:
- throw new \InvalidArgumentException( 'invalid
$newState: ' . $newState );
+ throw new InvalidArgumentException( 'invalid
$newState: ' . $newState );
}
$this->state = $newState;
@@ -510,7 +519,7 @@
break;
default:
- throw new LogicException( 'Bad transition: ' .
$this->state. ' -> ' . self::STATE_DOCUMENT );
+ throw new LogicException( 'Bad transition: ' .
$this->state. ' -> ' . self::STATE_DOCUMENT );
}
}
diff --git a/repo/includes/rdf/TurtleRdfWriter.php
b/repo/includes/rdf/TurtleRdfWriter.php
index d6824c6..a2a87a9 100644
--- a/repo/includes/rdf/TurtleRdfWriter.php
+++ b/repo/includes/rdf/TurtleRdfWriter.php
@@ -31,7 +31,7 @@
$this->writeRef( $base, $local );
}
- protected function writeValue( $value, $typeBase = null, $typeLocal =
null ) {
+ protected function writeValue( $value, $typeBase = null, $typeLocal =
null ) {
//TODO: shorthand form for xsd:integer|decimal|double|boolean
parent::writeValue( $value, $typeBase, $typeLocal );
}
@@ -86,4 +86,5 @@
public function getMimeType() {
return 'text/turtle; charset=UTF-8';
}
+
}
diff --git a/repo/includes/rdf/UnicodeEscaper.php
b/repo/includes/rdf/UnicodeEscaper.php
index 572bdbe..6c6f90d 100644
--- a/repo/includes/rdf/UnicodeEscaper.php
+++ b/repo/includes/rdf/UnicodeEscaper.php
@@ -45,13 +45,12 @@
/**
* @ignore
*/
- public function escapeString($str)
- {
+ public function escapeString( $str ) {
$result = '';
- $strLen = mb_strlen($str, "UTF-8");
- for ($i = 0; $i < $strLen; $i++) {
- $c = mb_substr($str, $i, 1, "UTF-8");
- if (!isset($this->escChars[$c])) {
+ $strLen = mb_strlen( $str, 'UTF-8' );
+ for ( $i = 0; $i < $strLen; $i++ ) {
+ $c = mb_substr( $str, $i, 1, 'UTF-8' );
+ if ( !isset( $this->escChars[$c] ) ) {
$this->escChars[$c] = $this->escapedChar($c);
}
$result .= $this->escChars[$c];
@@ -62,28 +61,27 @@
/**
* @ignore
*/
- protected function unicodeCharNo($cUtf)
- {
- $bl = strlen($cUtf); /* binary length */
+ protected function unicodeCharNo( $cUtf ) {
+ $bl = strlen( $cUtf ); /* binary length */
$r = 0;
- switch ($bl) {
+ switch ( $bl ) {
case 1: /* 0####### (0-127) */
- $r = ord($cUtf);
+ $r = ord( $cUtf );
break;
case 2: /* 110##### 10###### = 192+x 128+x */
- $r = ((ord($cUtf[0]) - 192) * 64) +
- (ord($cUtf[1]) - 128);
+ $r = ( ( ord( $cUtf[0] ) - 192 ) * 64 ) +
+ ( ord( $cUtf[1] ) - 128 );
break;
case 3: /* 1110#### 10###### 10###### = 224+x 128+x
128+x */
- $r = ((ord($cUtf[0]) - 224) * 4096) +
- ((ord($cUtf[1]) - 128) * 64) +
- (ord($cUtf[2]) - 128);
+ $r = ( ( ord( $cUtf[0] ) - 224 ) * 4096 ) +
+ ( ( ord( $cUtf[1] ) - 128 ) * 64 ) +
+ ( ord( $cUtf[2] ) - 128 );
break;
case 4: /* 1111#### 10###### 10###### 10###### = 240+x
128+x 128+x 128+x */
- $r = ((ord($cUtf[0]) - 240) * 262144) +
- ((ord($cUtf[1]) - 128) * 4096) +
- ((ord($cUtf[2]) - 128) * 64) +
- (ord($cUtf[3]) - 128);
+ $r = ( ( ord( $cUtf[0] ) - 240 ) * 262144 ) +
+ ( ( ord( $cUtf[1] ) - 128 ) * 4096 ) +
+ ( ( ord( $cUtf[2] ) - 128 ) * 64 ) +
+ ( ord( $cUtf[3] ) - 128 );
break;
}
return $r;
@@ -92,38 +90,38 @@
/**
* @ignore
*/
- protected function escapedChar($c)
- {
- $no = $this->unicodeCharNo($c);
+ protected function escapedChar( $c ) {
+ $no = $this->unicodeCharNo( $c );
/* see http://www.w3.org/TR/rdf-testcases/#ntrip_strings */
- if ($no < 9) {
- return "\\u" . sprintf('%04X', $no); /* #x0-#x8 (0-8) */
- } elseif ($no == 9) {
+ if ( $no < 9 ) {
+ return "\\u" . sprintf( '%04X', $no ); /* #x0-#x8 (0-8)
*/
+ } elseif ( $no == 9 ) {
return '\t'; /* #x9 (9) */
- } elseif ($no == 10) {
+ } elseif ( $no == 10 ) {
return '\n'; /* #xA (10) */
- } elseif ($no < 13) {
- return "\\u" . sprintf('%04X', $no); /* #xB-#xC (11-12)
*/
- } elseif ($no == 13) {
+ } elseif ( $no < 13 ) {
+ return "\\u" . sprintf( '%04X', $no ); /* #xB-#xC
(11-12) */
+ } elseif ( $no == 13 ) {
return '\r'; /* #xD (13) */
- } elseif ($no < 32) {
- return "\\u" . sprintf('%04X', $no); /* #xE-#x1F
(14-31) */
- } elseif ($no < 34) {
+ } elseif ( $no < 32 ) {
+ return "\\u" . sprintf( '%04X', $no ); /* #xE-#x1F
(14-31) */
+ } elseif ( $no < 34 ) {
return $c; /* #x20-#x21 (32-33) */
- } elseif ($no == 34) {
+ } elseif ( $no == 34 ) {
return '\"'; /* #x22 (34) */
- } elseif ($no < 92) {
+ } elseif ( $no < 92 ) {
return $c; /* #x23-#x5B (35-91) */
- } elseif ($no == 92) {
+ } elseif ( $no == 92 ) {
return '\\'; /* #x5C (92) */
- } elseif ($no < 127) {
+ } elseif ( $no < 127 ) {
return $c; /* #x5D-#x7E (93-126) */
- } elseif ($no < 65536) {
- return "\\u" . sprintf('%04X', $no); /* #x7F-#xFFFF
(128-65535) */
- } elseif ($no < 1114112) {
- return "\\U" . sprintf('%08X', $no); /*
#x10000-#x10FFFF (65536-1114111) */
+ } elseif ( $no < 65536 ) {
+ return "\\u" . sprintf( '%04X', $no ); /* #x7F-#xFFFF
(128-65535) */
+ } elseif ( $no < 1114112 ) {
+ return "\\U" . sprintf( '%08X', $no ); /*
#x10000-#x10FFFF (65536-1114111) */
} else {
return ''; /* not defined => ignore */
}
}
+
}
diff --git a/repo/includes/rdf/XmlRdfWriter.php
b/repo/includes/rdf/XmlRdfWriter.php
index d7f7378..2017252 100644
--- a/repo/includes/rdf/XmlRdfWriter.php
+++ b/repo/includes/rdf/XmlRdfWriter.php
@@ -73,9 +73,10 @@
* prefix().
*
* @param string $name the attribute name (without the 'rdf:' prefix)
- * @param string $base
- * @param string $local
+ * @param string|null $base
+ * @param string|null $local
*
+ * @throws InvalidArgumentException
* @return string[]
*/
private function getTargetAttributes( $name, $base, $local ) {
diff --git a/repo/maintenance/dumpRdf.php b/repo/maintenance/dumpRdf.php
index 9593295..6dde8d2 100644
--- a/repo/maintenance/dumpRdf.php
+++ b/repo/maintenance/dumpRdf.php
@@ -1,5 +1,8 @@
<?php
+
namespace Wikibase;
+
+use Wikibase\Dumpers\DumpGenerator;
use Wikibase\Dumpers\RdfDumpGenerator;
require_once __DIR__ . '/dumpEntities.php';
@@ -13,18 +16,20 @@
/**
* Create concrete dumper instance
+ *
* @param resource $output
+ *
* @return DumpGenerator
*/
protected function createDumper( $output ) {
return RdfDumpGenerator::createDumpGenerator(
- $this->getOption( 'format', 'ttl' ),
- $output,
- $GLOBALS['wgCanonicalServer']."/entity/",
-
$GLOBALS['wgCanonicalServer']."/Special:EntityData/",
- $this->wikibaseRepo->getSiteStore()->getSites(),
- $this->entityLookup, $this->revisionLookup,
-
$this->wikibaseRepo->getPropertyDataTypeLookup());
+ $this->getOption( 'format', 'ttl' ),
+ $output,
+ $GLOBALS['wgCanonicalServer']."/entity/",
+ $GLOBALS['wgCanonicalServer']."/Special:EntityData/",
+ $this->wikibaseRepo->getSiteStore()->getSites(),
+ $this->entityLookup, $this->revisionLookup,
+ $this->wikibaseRepo->getPropertyDataTypeLookup() );
}
}
diff --git a/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
b/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
index 3532c79..a6d575b 100644
--- a/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
+++ b/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
@@ -1,12 +1,15 @@
<?php
+
namespace Wikibase\Test\Dumpers;
+
+use PHPUnit_Framework_TestCase;
+use Site;
+use SiteList;
+use Wikibase\DataModel\Entity\Entity;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\Dumpers\RdfDumpGenerator;
-use Wikibase\RdfSerializer;
-use Wikibase\RdfProducer;
-use Wikibase\Lib\Store\UnresolvedRedirectException;
use Wikibase\EntityRevision;
use Wikibase\Test\RdfBuilderTest;
@@ -19,31 +22,30 @@
*
* @license GPL 2+
*/
-class RdfDumpGeneratorTest extends \PHPUnit_Framework_TestCase {
+class RdfDumpGeneratorTest extends PHPUnit_Framework_TestCase {
const URI_BASE = 'http://acme.test/';
const URI_DATA = 'http://data.acme.test/';
/**
- * Get site list
- * @return \SiteList
+ * @return SiteList
*/
public function getSiteList() {
- $list = new \SiteList();
+ $list = new SiteList();
- $wiki = new \Site();
+ $wiki = new Site();
$wiki->setGlobalId( 'enwiki' );
$wiki->setLanguageCode( 'en' );
$wiki->setLinkPath( 'http://enwiki.acme.test/$1' );
$list['enwiki'] = $wiki;
- $wiki = new \Site();
+ $wiki = new Site();
$wiki->setGlobalId( 'ruwiki' );
$wiki->setLanguageCode( 'ru' );
$wiki->setLinkPath( 'http://ruwiki.acme.test/$1' );
$list['ruwiki'] = $wiki;
- $wiki = new \Site();
+ $wiki = new Site();
$wiki->setGlobalId( 'test' );
$wiki->setLanguageCode( 'test' );
$wiki->setLinkPath( 'http://test.acme.test/$1' );
@@ -55,7 +57,7 @@
/**
* @param Entity[] $entities
*
- * @return JsonDumpGenerator
+ * @return RdfDumpGenerator
*/
protected function newDumpGenerator( array $entities = array() ) {
$out = fopen( 'php://output', 'w' );
@@ -65,31 +67,32 @@
$propertyLookup = $this->getMock(
'Wikibase\DataModel\Entity\PropertyDataTypeLookup' );
$entityLookup->expects( $this->any() )
- ->method( 'getEntity' )
- ->will( $this->returnCallback( function( EntityId $id ) use (
$entities ) {
- $key = $id->getSerialization();
- return $entities[$key];
- } ) );
+ ->method( 'getEntity' )
+ ->will( $this->returnCallback( function( EntityId $id )
use ( $entities ) {
+ $key = $id->getSerialization();
+ return $entities[$key];
+ } ) );
$entityRevisionLookup->expects( $this->any() )
->method ( 'getEntityRevision' )
->will( $this->returnCallback( function( EntityId $id )
use( $entityLookup ) {
$e = $entityLookup->getEntity( $id );
- if( !$e ) {
+ if ( !$e ) {
return null;
}
- return new EntityRevision($e, 12, wfTimestamp(
TS_MW, 1000000 ) );
+ return new EntityRevision( $e, 12, wfTimestamp(
TS_MW, 1000000 ) );
}
));
return RdfDumpGenerator::createDumpGenerator('ntriples',
- $out,
- self::URI_BASE,
- self::URI_DATA,
- $this->getSiteList(),
- $entityLookup,
- $entityRevisionLookup,
- $propertyLookup);
+ $out,
+ self::URI_BASE,
+ self::URI_DATA,
+ $this->getSiteList(),
+ $entityLookup,
+ $entityRevisionLookup,
+ $propertyLookup
+ );
}
public function idProvider() {
@@ -97,15 +100,17 @@
$q30 = new ItemId( 'Q30' );
return array(
- 'empty' => array( array(), 'empty' ),
- 'some entities' => array( array( $p10, $q30 ),
'entities' ),
+ 'empty' => array( array(), 'empty' ),
+ 'some entities' => array( array( $p10, $q30 ),
'entities' ),
);
}
/**
* Brings data to normalized form - sorted array of lines
+ *
* @param string $data
- * @return array
+ *
+ * @return string[]
*/
public function normalizeData($data) {
$dataSplit = explode( "\n", $data );
@@ -115,15 +120,16 @@
/**
* Load serialized ntriples
+ *
* @param string $testName
- * @return array
+ *
+ * @return string[]
*/
public function getSerializedData( $testName )
{
$filename = __DIR__ . "/../../data/rdf/dump_$testName.nt";
- if ( !file_exists( $filename ) )
- {
- return array ();
+ if ( !file_exists( $filename ) ) {
+ return array();
}
return $this->normalizeData( file_get_contents( $filename ) );
}
@@ -144,12 +150,11 @@
$dump = ob_get_clean();
$dump = $this->normalizeData($dump);
$this->assertEquals($this->getSerializedData($dumpname), $dump);
-
}
public function loadDataProvider() {
return array(
- 'references' => array( array( new ItemId( 'Q7'
), new ItemId( 'Q9' ) ), 'refs' ),
+ 'references' => array( array( new ItemId( 'Q7' ), new
ItemId( 'Q9' ) ), 'refs' ),
);
}
@@ -174,4 +179,4 @@
$this->assertEquals($this->getSerializedData($dumpname), $dump);
}
-}
\ No newline at end of file
+}
--
To view, visit https://gerrit.wikimedia.org/r/199622
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If782b9e1e17973f31c5b25f73cb07f59109b042b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits