jenkins-bot has submitted this change and it was merged.

Change subject: Narrow RdfBuilder interfaces as much as possible
......................................................................


Narrow RdfBuilder interfaces as much as possible

... and make as much stuff as possible private. Please note that
the code is not unused, see //$this->addStatements( ...

Change-Id: I88c0f62ab4b13e65aa79995236bfa344a76348e6
---
M repo/includes/rdf/RdfBuilder.php
M repo/tests/phpunit/includes/rdf/RdfBuilderTest.php
2 files changed, 63 insertions(+), 65 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  Thiemo Mättig (WMDE): Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/repo/includes/rdf/RdfBuilder.php b/repo/includes/rdf/RdfBuilder.php
index 8c30ab2..9787c7b 100644
--- a/repo/includes/rdf/RdfBuilder.php
+++ b/repo/includes/rdf/RdfBuilder.php
@@ -8,7 +8,6 @@
 use EasyRdf_Namespace;
 use EasyRdf_Resource;
 use SiteList;
-use Wikibase\DataModel\Claim\Claim;
 use Wikibase\DataModel\Entity\BasicEntityIdParser;
 use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\Entity\EntityDocument;
@@ -16,6 +15,7 @@
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\SiteLink;
 use Wikibase\DataModel\Snak\PropertyValueSnak;
+use Wikibase\DataModel\Statement\Statement;
 use Wikibase\DataModel\StatementListProvider;
 use Wikibase\Lib\Store\EntityLookup;
 
@@ -60,7 +60,7 @@
         *
         * @var array
         */
-       protected $namespaces = array();
+       private $namespaces = array();
 
        /**
         * A list of entities mentioned/touched to or by this builder.
@@ -70,7 +70,7 @@
         *
         * @var array
         */
-       protected $entitiesResolved = array();
+       private $entitiesResolved = array();
 
        /**
         * @param SiteList $sites
@@ -138,24 +138,24 @@
         * refer to the Wikibase RDF mapping spec.
         *
         * @param string   $prefix use a self::NS_XXX constant
-        * @param EntityId $id
+        * @param EntityId $entityId
         *
         * @return string
         */
-       public function getEntityQName( $prefix, EntityId $id ) {
-               return $prefix . ':' . ucfirst( $id->getSerialization() );
+       public function getEntityQName( $prefix, EntityId $entityId ) {
+               return $prefix . ':' . ucfirst( $entityId->getSerialization() );
        }
 
        /**
         * Returns a qname for the given statement using the given prefix.
         *
         * @param string $prefix use a self::NS_XXX constant, usually 
self::NS_STATEMENT
-        * @param Claim $claim
+        * @param Statement $statement
         *
         * @return string
         */
-       public function getStatementQName( $prefix, Claim $claim ) {
-               return $prefix . ':' . $claim->getGuid();
+       private function getStatementQName( $prefix, Statement $statement ) {
+               return $prefix . ':' . $statement->getGuid();
        }
 
        /**
@@ -166,7 +166,7 @@
         *
         * @return string
         */
-       public function getEntityTypeQName( $type ) {
+       private function getEntityTypeQName( $type ) {
                //TODO: the list of types is configurable, need to register 
URIs for extra types!
 
                return self::NS_ONTOLOGY . ':' . ucfirst( $type );
@@ -175,12 +175,12 @@
        /**
         * Gets a resource object representing the given entity
         *
-        * @param EntityId $id
+        * @param EntityId $entityId
         *
         * @return EasyRDF_Resource
         */
-       public function getEntityResource( EntityId $id ) {
-               $entityQName = $this->getEntityQName( self::NS_ENTITY, $id );
+       private function getEntityResource( EntityId $entityId ) {
+               $entityQName = $this->getEntityQName( self::NS_ENTITY, 
$entityId );
                $entityResource = $this->graph->resource( $entityQName );
                return $entityResource;
        }
@@ -188,14 +188,12 @@
        /**
         * Gets a URL of the rdf description of the given entity
         *
-        * @param EntityId $id
+        * @param EntityId $entityId
         *
         * @return string
         */
-       public function getDataURL( EntityId $id ) {
-               $base = $this->namespaces[ self::NS_DATA ];
-               $url = $base . ucfirst( $id->getSerialization() );
-               return $url;
+       public function getDataURL( EntityId $entityId ) {
+               return $this->namespaces[self::NS_DATA] . ucfirst( 
$entityId->getSerialization() );
        }
 
        /**
@@ -205,7 +203,7 @@
         *
         * @return bool
         */
-       protected function isLanguageIncluded( $lang ) {
+       private function isLanguageIncluded( $lang ) {
                return true; //todo: optional filter
        }
 
@@ -213,10 +211,10 @@
         * Registers an entity as mentioned. Will be recorded as unresolved
         * if it wasn't already marked as resolved.
         *
-        * @param EntityId $id
+        * @param EntityId $entityId
         */
-       protected function entityMentioned( EntityId $id ) {
-               $prefixedId = $id->getSerialization();
+       private function entityMentioned( EntityId $entityId ) {
+               $prefixedId = $entityId->getSerialization();
 
                if ( !isset( $this->entitiesResolved[$prefixedId] ) ) {
                        $this->entitiesResolved[$prefixedId] = false;
@@ -226,10 +224,10 @@
        /**
         * Registers an entity as resolved.
         *
-        * @param EntityId $id
+        * @param EntityId $entityId
         */
-       protected function entityResolved( EntityId $id ) {
-               $prefixedId = $id->getSerialization();
+       private function entityResolved( EntityId $entityId ) {
+               $prefixedId = $entityId->getSerialization();
                $this->entitiesResolved[$prefixedId] = true;
        }
 
@@ -261,7 +259,7 @@
         *
         * @param Entity         $entity
         */
-       public function addEntityMetaData( Entity $entity ) {
+       private function addEntityMetaData( Entity $entity ) {
                $entityResource = $this->getEntityResource( $entity->getId() );
                $entityResource->addResource( 'rdf:type', 
$this->getEntityTypeQName( $entity->getType() ) );
                $dataURL = $this->getDataURL( $entity->getId() );
@@ -282,7 +280,7 @@
         *
         * @param Entity $entity
         */
-       public function addLabels( Entity $entity ) {
+       private function addLabels( Entity $entity ) {
                $entityResource = $this->getEntityResource( $entity->getId() );
 
                foreach ( $entity->getLabels() as $languageCode => $labelText ) 
{
@@ -301,7 +299,7 @@
         *
         * @param Entity $entity
         */
-       public function addDescriptions( Entity $entity ) {
+       private function addDescriptions( Entity $entity ) {
                $entityResource = $this->getEntityResource( $entity->getId() );
 
                foreach ( $entity->getDescriptions() as $languageCode => 
$description ) {
@@ -318,7 +316,7 @@
         *
         * @param Entity $entity
         */
-       public function addAliases( Entity $entity ) {
+       private function addAliases( Entity $entity ) {
                $entityResource = $this->getEntityResource( $entity->getId() );
 
                foreach ( $entity->getAllAliases() as $languageCode => $aliases 
) {
@@ -337,12 +335,10 @@
         *
         * @param Item $item
         */
-       public function addSiteLinks( Item $item ) {
+       private function addSiteLinks( Item $item ) {
                $entityResource = $this->getEntityResource( $item->getId() );
 
-               /**
-                * @var SiteLink $siteLink
-                */
+               /** @var SiteLink $siteLink */
                foreach ( $item->getSiteLinkList() as $siteLink ) {
                        $site = $this->sites->getSite( $siteLink->getSiteId() );
 
@@ -364,44 +360,44 @@
        }
 
        /**
-        * Adds all Claims/Statements from the given entity to the RDF graph.
+        * Adds all Statements from the given entity to the RDF graph.
         *
         * @param EntityDocument $entity
         */
-       public function addClaims( EntityDocument $entity ) {
-               $id = $entity->getId();
+       private function addStatements( EntityDocument $entity ) {
+               $entityId = $entity->getId();
 
                if ( $entity instanceof StatementListProvider ) {
                        foreach ( $entity->getStatements() as $statement ) {
-                               $this->addClaim( $id, $statement );
+                               $this->addStatement( $entityId, $statement );
                        }
                }
        }
 
        /**
-        * Adds the given Claim from the given Entity to the RDF graph.
+        * Adds the given Statement from the given Entity to the RDF graph.
         *
         * @param EntityId $entityId
-        * @param Claim $claim
+        * @param Statement $statement
         */
-       private function addClaim( EntityId $entityId, Claim $claim ) {
-               $this->addMainSnak( $entityId, $claim );
+       private function addStatement( EntityId $entityId, Statement $statement 
) {
+               $this->addMainSnak( $entityId, $statement );
 
                //TODO: add qualifiers
                //TODO: add references
        }
 
        /**
-        * Adds the given Claim's main Snak to the RDF graph.
+        * Adds the given Statement's main Snak to the RDF graph.
         *
         * @param EntityId $entityId
-        * @param Claim $claim
+        * @param Statement $statement
         */
-       private function addMainSnak( EntityId $entityId, Claim $claim ) {
-               $snak = $claim->getMainSnak();
+       private function addMainSnak( EntityId $entityId, Statement $statement 
) {
+               $snak = $statement->getMainSnak();
 
                if ( $snak instanceof PropertyValueSnak ) {
-                       $this->addPropertyValueSnak( $entityId, $claim, $snak );
+                       $this->addPropertyValueSnak( $entityId, $statement, 
$snak );
                } else {
                        //TODO: NoValueSnak, SomeValueSnak
                        wfDebug( __METHOD__ . ": Unsupported snak type: " . 
get_class( $snak ) );
@@ -409,14 +405,14 @@
        }
 
        /**
-        * Returns a resource representing the given claim.
+        * Returns a resource representing the given Statement.
         *
-        * @param Claim $claim
+        * @param Statement $statement
         *
         * @return EasyRDF_Resource
         */
-       public function getStatementResource( Claim $claim ) {
-               $statementQName = $this->getStatementQName( self::NS_STATEMENT, 
$claim );
+       private function getStatementResource( Statement $statement ) {
+               $statementQName = $this->getStatementQName( self::NS_STATEMENT, 
$statement );
                $statementResource = $this->graph->resource( $statementQName, 
array( self::WIKIBASE_STATEMENT_QNAME ) );
                return $statementResource;
        }
@@ -426,32 +422,32 @@
         *
         * @param EntityId $entityId
         * @param PropertyValueSnak $snak
-        * @param Claim $claim
+        * @param Statement $statement
         */
-       private function addPropertyValueSnak( EntityId $entityId, Claim 
$claim, PropertyValueSnak $snak ) {
+       private function addPropertyValueSnak( EntityId $entityId, Statement 
$statement, PropertyValueSnak $snak ) {
                $entityResource = $this->getEntityResource( $entityId );
 
-               $propertyId = $claim->getMainSnak()->getPropertyId();
+               $propertyId = $statement->getMainSnak()->getPropertyId();
                $propertyQName = $this->getEntityQName( self::NS_ENTITY, 
$propertyId );
 
-               $statementResource = $this->getStatementResource( $claim );
+               $statementResource = $this->getStatementResource( $statement );
                $entityResource->addResource( $propertyQName, 
$statementResource );
 
                $value = $snak->getDataValue();
 
                $this->entityMentioned( $propertyId );
-               $this->addClaimValue( $claim, $propertyId, $value );
+               $this->addStatementValue( $statement, $propertyId, $value );
        }
 
        /**
         * Adds the value of the given property to the RDF graph.
         *
-        * @param Claim     $claim
+        * @param Statement $statement
         * @param EntityId  $propertyId
         * @param DataValue $value
         */
-       public function addClaimValue( Claim $claim, EntityId $propertyId, 
DataValue $value ) {
-               $statementResource = $this->getStatementResource( $claim );
+       private function addStatementValue( Statement $statement, EntityId 
$propertyId, DataValue $value ) {
+               $statementResource = $this->getStatementResource( $statement );
                $propertyValueQName = $this->getEntityQName( self::NS_VALUE, 
$propertyId );
 
                $typeId = $value->getType();
@@ -483,10 +479,10 @@
                // @todo inject a DispatchingEntityIdParser
                $idParser = new BasicEntityIdParser();
 
-               foreach ( $this->entitiesResolved as $id => $resolved ) {
+               foreach ( $this->entitiesResolved as $entityId => $resolved ) {
                        if ( !$resolved ) {
-                               $id = $idParser->parse( $id );
-                               $entity = $entityLookup->getEntity( $id );
+                               $entityId = $idParser->parse( $entityId );
+                               $entity = $entityLookup->getEntity( $entityId );
 
                                $this->addEntityStub( $entity );
                        }
@@ -509,7 +505,9 @@
                        $this->addSiteLinks( $entity );
                }
 
-               //$this->addClaims( $entity ); //TODO: finish this.
+               if ( $entity instanceof EntityDocument ) {
+                       //$this->addStatements( $entity ); //TODO: finish this.
+               }
        }
 
        /**
@@ -518,7 +516,7 @@
         *
         * @param Entity $entity
         */
-       public function addEntityStub( Entity $entity ) {
+       private function addEntityStub( Entity $entity ) {
                $this->addEntityMetaData( $entity );
                $this->addLabels( $entity );
                $this->addDescriptions( $entity );
diff --git a/repo/tests/phpunit/includes/rdf/RdfBuilderTest.php 
b/repo/tests/phpunit/includes/rdf/RdfBuilderTest.php
index 5978d49..eb4c82a 100644
--- a/repo/tests/phpunit/includes/rdf/RdfBuilderTest.php
+++ b/repo/tests/phpunit/includes/rdf/RdfBuilderTest.php
@@ -144,7 +144,7 @@
                $graphs['empty'] = self::makeEntityGraph(
                        $entities['empty']->getId(),
                        array(
-                               'rdf:type' => $builder->getEntityTypeQName( 
Item::ENTITY_TYPE ),
+                               'rdf:type' => RdfBuilder::NS_ONTOLOGY . ':Item',
                        ),
                        array(
                                'rdf:type' => RdfBuilder::NS_SCHEMA_ORG . 
':Dataset',
@@ -157,7 +157,7 @@
                $graphs['terms'] = self::makeEntityGraph(
                        $entities['terms']->getId(),
                        array(
-                               'rdf:type' => $builder->getEntityTypeQName( 
Item::ENTITY_TYPE ),
+                               'rdf:type' => RdfBuilder::NS_ONTOLOGY . ':Item',
                                'rdfs:label' => array(
                                        new EasyRdf_Literal( 'Berlin', 'en' ),
                                        new EasyRdf_Literal( 'Берлин', 'ru' )

-- 
To view, visit https://gerrit.wikimedia.org/r/176725
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I88c0f62ab4b13e65aa79995236bfa344a76348e6
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: JanZerebecki <jan.wikime...@zerebecki.de>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to