[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: First pass on LexicalCategory
jenkins-bot has submitted this change and it was merged. Change subject: First pass on LexicalCategory .. First pass on LexicalCategory - Add provider interface - Add to entity as an attribute and add getter and setter - Consider in equals() method - Consider in __clone() method - Consider in isEmpty() method Bug: T149495 Change-Id: Ide61b04304721122aa0dd732a2b7aac08c73ee7b --- M src/DataModel/Lexeme.php A src/DataModel/Providers/LexicalCategoryProvider.php M src/DataModel/Serialization/LexemeDeserializer.php M tests/phpunit/composer/DataModel/LexemeTest.php M tests/phpunit/mediawiki/View/LexemeViewTest.php 5 files changed, 92 insertions(+), 7 deletions(-) Approvals: Thiemo Mättig (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 773dd85..00fd413 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -5,6 +5,8 @@ use InvalidArgumentException; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; +use Wikibase\DataModel\Entity\Item; +use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Statement\StatementList; use Wikibase\DataModel\Statement\StatementListProvider; use Wikibase\DataModel\Term\DescriptionsProvider; @@ -13,12 +15,13 @@ use Wikibase\DataModel\Term\LabelsProvider; use Wikibase\DataModel\Term\TermList; use Wikibase\Lexeme\DataModel\Providers\LemmasProvider; +use Wikibase\Lexeme\DataModel\Providers\LexicalCategoryProvider; /** * @license GPL-2.0+ */ class Lexeme implements EntityDocument, StatementListProvider, FingerprintProvider, - LabelsProvider, DescriptionsProvider, LemmasProvider { + LabelsProvider, DescriptionsProvider, LemmasProvider, LexicalCategoryProvider { const ENTITY_TYPE = 'lexeme'; @@ -43,18 +46,26 @@ private $lemmas; /** +* @var ItemId|null +*/ + private $lexicalCategory; + + /** * @param LexemeId|null $id * @param TermList|null $lemmas +* @param ItemId|null $lexicalCategory * @param StatementList|null $statements */ public function __construct( LexemeId $id = null, TermList $lemmas = null, + ItemId $lexicalCategory = null, StatementList $statements = null ) { - // TODO: add lemma, language and lexical category + // TODO: add language $this->id = $id; $this->lemmas = $lemmas; + $this->lexicalCategory = $lexicalCategory; $this->statements = $statements ?: new StatementList(); // TODO: Remove this once Wikibase can work without fingerprint $this->fingerprint = new Fingerprint(); @@ -137,6 +148,7 @@ // TODO: should also check other attributes once implemented return ( is_null( $this->lemmas ) || $this->lemmas->isEmpty() ) + && is_null( $this->lexicalCategory ) && $this->statements->isEmpty(); } @@ -161,7 +173,14 @@ $this->lemmas !== null && $this->lemmas->equals( $target->getLemmas() ) ) ); + + $sameLexicalCategory = ( $this->lexicalCategory === $target->getLexicalCategory() || ( + $this->lexicalCategory !== null + && $this->lexicalCategory->equals( $target->getLexicalCategory() ) ) + ); + return $sameLemmas + && $sameLexicalCategory && $this->statements->equals( $target->statements ); } @@ -196,4 +215,18 @@ $this->lemmas = $lemmas; } + /** +* @return ItemId|null +*/ + public function getLexicalCategory() { + return $this->lexicalCategory; + } + + /** +* @param ItemId $lexicalCategory +*/ + public function setLexicalCategory( ItemId $lexicalCategory ) { + $this->lexicalCategory = $lexicalCategory; + } + } diff --git a/src/DataModel/Providers/LexicalCategoryProvider.php b/src/DataModel/Providers/LexicalCategoryProvider.php new file mode 100644 index 000..eaa8c88 --- /dev/null +++ b/src/DataModel/Providers/LexicalCategoryProvider.php @@ -0,0 +1,23 @@ + + */ +interface LexicalCategoryProvider { + + /** +* This is guaranteed to return the original, mutable object by reference. +* +* @return ItemId +*/ + public function getLexicalCategory(); + +} diff --git a/src/DataModel/Serialization/LexemeDeserializer.php b/src/DataModel/Serialization/LexemeDeserializer.php index 82bd2ef..03f6e1a 100644 --- a/src/DataModel/Serialization/Le
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: First pass on LexicalCategory
Ladsgroup has uploaded a new change for review. https://gerrit.wikimedia.org/r/325450 Change subject: First pass on LexicalCategory .. First pass on LexicalCategory - Add provider interface - Add to entity as an attribute and add getter and setter - Consider in equals() method - Consider in __clone() method - Consider in isEmpty() method Bug: T149495 Change-Id: Ide61b04304721122aa0dd732a2b7aac08c73ee7b --- M src/DataModel/Lexeme.php A src/DataModel/Providers/LexicalCategoryProvider.php M src/DataModel/Serialization/LexemeDeserializer.php M tests/phpunit/composer/DataModel/LexemeTest.php 4 files changed, 93 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/50/325450/1 diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 773dd85..dcdfc69 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -5,6 +5,7 @@ use InvalidArgumentException; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; +use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Statement\StatementList; use Wikibase\DataModel\Statement\StatementListProvider; use Wikibase\DataModel\Term\DescriptionsProvider; @@ -13,12 +14,13 @@ use Wikibase\DataModel\Term\LabelsProvider; use Wikibase\DataModel\Term\TermList; use Wikibase\Lexeme\DataModel\Providers\LemmasProvider; +use Wikibase\Lexeme\DataModel\Providers\LexicalCategoryProvider; /** * @license GPL-2.0+ */ class Lexeme implements EntityDocument, StatementListProvider, FingerprintProvider, - LabelsProvider, DescriptionsProvider, LemmasProvider { + LabelsProvider, DescriptionsProvider, LemmasProvider, LexicalCategoryProvider { const ENTITY_TYPE = 'lexeme'; @@ -43,18 +45,26 @@ private $lemmas; /** +* @var Item|null +*/ + private $lexicalCategory; + + /** * @param LexemeId|null $id * @param TermList|null $lemmas +* @param Item|null $lexicalCategory * @param StatementList|null $statements */ public function __construct( LexemeId $id = null, TermList $lemmas = null, + Item $lexicalCategory = null, StatementList $statements = null ) { - // TODO: add lemma, language and lexical category + // TODO: add language $this->id = $id; $this->lemmas = $lemmas; + $this->lexicalCategory = $lexicalCategory; $this->statements = $statements ?: new StatementList(); // TODO: Remove this once Wikibase can work without fingerprint $this->fingerprint = new Fingerprint(); @@ -137,6 +147,7 @@ // TODO: should also check other attributes once implemented return ( is_null( $this->lemmas ) || $this->lemmas->isEmpty() ) + && is_null( $this->lexicalCategory ) && $this->statements->isEmpty(); } @@ -161,7 +172,18 @@ $this->lemmas !== null && $this->lemmas->equals( $target->getLemmas() ) ) ); + + $sameLexicalCategory = ( $this->lexicalCategory === $target->getLexicalCategory() || ( + $this->lexicalCategory !== null + && $this->lexicalCategory->equals( $target->getLexicalCategory() ) + && $this->lexicalCategory->getId() !== null + && $this->lexicalCategory->getId()->equals( + $target->getLexicalCategory()->getId() + ) ) + ); + return $sameLemmas + && $sameLexicalCategory && $this->statements->equals( $target->statements ); } @@ -196,4 +218,18 @@ $this->lemmas = $lemmas; } + /** +* @return Item +*/ + public function getLexicalCategory() { + return $this->lexicalCategory; + } + + /** +* @param Item $lexicalCategory +*/ + public function setLexicalCategory( Item $lexicalCategory ) { + $this->lexicalCategory = $lexicalCategory; + } + } diff --git a/src/DataModel/Providers/LexicalCategoryProvider.php b/src/DataModel/Providers/LexicalCategoryProvider.php new file mode 100644 index 000..d684494 --- /dev/null +++ b/src/DataModel/Providers/LexicalCategoryProvider.php @@ -0,0 +1,23 @@ + + */ +interface LexicalCategoryProvider { + + /** +* This is guaranteed to return the original. +* +* @return Item +*/ + public function getLexicalCategory(); + +} diff --