Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/365025 )

Change subject: Setup data for demo system
......................................................................

Setup data for demo system

All ID values were taken from http://wikidata-lexeme.wmflabs.org

Used Test builders to make code more readable. I don't see a problem
here as soon as this code is temporary.

Change-Id: Iaacf73a9b3135462dde212ecf773c90ba12ae55c
---
M src/Content/LexemeContent.php
A src/DemoData/DefaultPopulator.php
A src/DemoData/HardLexemePopulator.php
A src/DemoData/Id.php
4 files changed, 278 insertions(+), 92 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme 
refs/changes/25/365025/1

diff --git a/src/Content/LexemeContent.php b/src/Content/LexemeContent.php
index 8c97975..64d702b 100644
--- a/src/Content/LexemeContent.php
+++ b/src/Content/LexemeContent.php
@@ -5,23 +5,10 @@
 use InvalidArgumentException;
 use LogicException;
 use Wikibase\Content\EntityHolder;
-use Wikibase\DataModel\Term\Term;
-use Wikibase\DataModel\Term\TermList;
 use Wikibase\EntityContent;
 use Wikibase\Lexeme\DataModel\Lexeme;
-use Wikibase\Lexeme\DataModel\Sense;
-use Wikibase\Lexeme\DataModel\SenseId;
+use Wikibase\Lexeme\DemoData;
 use Wikimedia\Assert\Assert;
-
-use DataValues\StringValue;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel\Snak\PropertyNoValueSnak;
-use Wikibase\DataModel\Snak\PropertyValueSnak;
-use Wikibase\DataModel\Statement\Statement;
-use Wikibase\DataModel\Statement\StatementList;
-use Wikibase\Lexeme\DataModel\Form;
-use Wikibase\Lexeme\DataModel\FormId;
 
 /**
  * @license GPL-2.0+
@@ -67,84 +54,11 @@
                /** @var Lexeme $lexeme */
                $lexeme = $this->lexemeHolder->getEntity( Lexeme::class );
 
-               // TODO: This obviously is a dummy that must be removed
-               $grammaticalFeatures1 = [ new ItemId( 'Q2' ) ];
-               $grammaticalFeatures2 = [ new ItemId( 'Q2' ), new ItemId( 'Q3' 
) ];
-               $statements1 = new StatementList(
-                       [
-                               new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P2' ) ), null, null, 'guid1' )
-                       ]
-               );
-               $statements2 = new StatementList(
-                       [
-                               new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P2' ) ), null, null, 'guid2' ),
-                               new Statement(
-                                       new PropertyValueSnak(
-                                               new PropertyId( 'P3' ),
-                                               new StringValue( 'asd' )
-                                       ),
-                                       null,
-                                       null,
-                                       'guid3'
-                               ),
-                       ]
-               );
-
-               $forms = [
-                       new Form(
-                               new FormId( 'F1' ),
-                               new TermList( [ new Term( 'en', 'A' ) ] ),
-                               []
-                       ),
-                       new Form(
-                               new FormId( 'F2' ),
-                               new TermList( [ new Term( 'en', 'B' ) ] ),
-                               $grammaticalFeatures1,
-                               $statements1
-                       ),
-                       new Form(
-                               new FormId( 'F3' ),
-                               new TermList( [ new Term( 'en', 'C' ) ] ),
-                               $grammaticalFeatures2,
-                               $statements2
-                       ),
-               ];
-
-               $lexeme->setForms( $forms );
-
-               $senses = [
-                       new Sense(
-                               new SenseId( 'S1' ),
-                               new TermList( [
-                                       new Term(
-                                               'en',
-                                               'A mammal, Capra aegagrus 
hircus, and similar species of the genus Capra.'
-                                       ),
-                                       new Term(
-                                               'fr',
-                                               'Un mammale, Capra aegagruse 
hircuse, et similare species de un genuse Capra.'
-                                       ),
-                               ] ),
-                               new StatementList()
-                       ),
-                       new Sense(
-                               new SenseId( 'S2' ),
-                               new TermList( [ new Term( 'en', 'A scapegoat.' 
) ] ),
-                               new StatementList( [
-                                       new Statement(
-                                               new PropertyValueSnak(
-                                                       new PropertyId( 'P900' 
),
-                                                       new StringValue( 
'informal' )
-                                               ),
-                                               null,
-                                               null,
-                                               'guid900'
-                                       ),
-                               ] )
-                       )
-               ];
-
-               $lexeme->setSenses( $senses );
+               if ( $lexeme->getId()->getSerialization() === 
DemoData\Id::L_HARD ) {
+                       ( new DemoData\HardLexemePopulator() )->populate( 
$lexeme );
+               } else {
+                       ( new DemoData\DefaultPopulator() )->populate( $lexeme 
);
+               }
 
                return $lexeme;
        }
diff --git a/src/DemoData/DefaultPopulator.php 
b/src/DemoData/DefaultPopulator.php
new file mode 100644
index 0000000..faf2d96
--- /dev/null
+++ b/src/DemoData/DefaultPopulator.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace Wikibase\Lexeme\DemoData;
+
+use Wikibase\Lexeme\DataModel\Lexeme;
+use Wikibase\DataModel\Term\Term;
+use Wikibase\DataModel\Term\TermList;
+use Wikibase\Lexeme\DataModel\Sense;
+use Wikibase\Lexeme\DataModel\SenseId;
+
+use DataValues\StringValue;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Snak\PropertyNoValueSnak;
+use Wikibase\DataModel\Snak\PropertyValueSnak;
+use Wikibase\DataModel\Statement\Statement;
+use Wikibase\DataModel\Statement\StatementList;
+use Wikibase\Lexeme\DataModel\Form;
+use Wikibase\Lexeme\DataModel\FormId;
+
+class DefaultPopulator {
+
+       public function populate( Lexeme $lexeme ) {
+               // TODO: This obviously is a dummy that must be removed
+               $grammaticalFeatures1 = [ new ItemId( 'Q2' ) ];
+               $grammaticalFeatures2 = [ new ItemId( 'Q2' ), new ItemId( 'Q3' 
) ];
+               $statements1 = new StatementList(
+                       [
+                               new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P2' ) ), null, null, 'guid1' )
+                       ]
+               );
+               $statements2 = new StatementList(
+                       [
+                               new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P2' ) ), null, null, 'guid2' ),
+                               new Statement(
+                                       new PropertyValueSnak(
+                                               new PropertyId( 'P3' ),
+                                               new StringValue( 'asd' )
+                                       ),
+                                       null,
+                                       null,
+                                       'guid3'
+                               ),
+                       ]
+               );
+
+               $forms = [
+                       new Form(
+                               new FormId( 'F1' ),
+                               new TermList( [ new Term( 'en', 'A' ) ] ),
+                               []
+                       ),
+                       new Form(
+                               new FormId( 'F2' ),
+                               new TermList( [ new Term( 'en', 'B' ) ] ),
+                               $grammaticalFeatures1,
+                               $statements1
+                       ),
+                       new Form(
+                               new FormId( 'F3' ),
+                               new TermList( [ new Term( 'en', 'C' ) ] ),
+                               $grammaticalFeatures2,
+                               $statements2
+                       ),
+               ];
+
+               $lexeme->setForms( $forms );
+
+               $senses = [
+                       new Sense(
+                               new SenseId( 'S1' ),
+                               new TermList( [
+                                                                 new Term(
+                                                                         'en',
+                                                                         'A 
mammal, Capra aegagrus hircus, and similar species of the genus Capra.'
+                                                                 ),
+                                                                 new Term(
+                                                                         'fr',
+                                                                         'Un 
mammale, Capra aegagruse hircuse, et similare species de un genuse Capra.'
+                                                                 ),
+                                                         ] ),
+                               new StatementList()
+                       ),
+                       new Sense(
+                               new SenseId( 'S2' ),
+                               new TermList( [ new Term( 'en', 'A scapegoat.' 
) ] ),
+                               new StatementList( [
+                                                                          new 
Statement(
+                                                                               
   new PropertyValueSnak(
+                                                                               
           new PropertyId( 'P900' ),
+                                                                               
           new StringValue( 'informal' )
+                                                                               
   ),
+                                                                               
   null,
+                                                                               
   null,
+                                                                               
   'guid900'
+                                                                          ),
+                                                                  ] )
+                       )
+               ];
+
+               $lexeme->setSenses( $senses );
+       }
+
+}
diff --git a/src/DemoData/HardLexemePopulator.php 
b/src/DemoData/HardLexemePopulator.php
new file mode 100644
index 0000000..c294c11
--- /dev/null
+++ b/src/DemoData/HardLexemePopulator.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace Wikibase\Lexeme\DemoData;
+
+use Wikibase\Lexeme\DataModel\Lexeme;
+use Wikibase\Lexeme\Tests\DataModel\NewForm;
+use Wikibase\Lexeme\Tests\DataModel\NewSense;
+use Wikibase\Repo\Tests\NewStatement;
+
+class HardLexemePopulator {
+
+       public function populate( Lexeme $lexeme ) {
+               $hardForm = $this->buildHardForm();
+               $harderForm = $this->buildHarderForm();
+
+               $presentingDifficultySense = 
$this->buildPresentingDifficultySense();
+               $resistingDeformationSense = 
$this->buildResistingDeformationSense();
+
+               $lexeme->setForms( [ $hardForm, $harderForm ] );
+               $lexeme->setSenses( [ $presentingDifficultySense, 
$resistingDeformationSense ] );
+       }
+
+       /**
+        * @return \Wikibase\Lexeme\DataModel\Form
+        */
+       private function buildHardForm() {
+               return NewForm::havingId( 'F1' )
+                       ->andRepresentation( 'en', 'hard' )
+                       ->andGrammaticalFeature( Id::Q_NORMATIVE )
+                       ->andStatement(
+                               NewStatement::forProperty( 
Id::P_IPA_PRONUNCIATION )
+                                       ->withValue( '/hɑːd/' )
+                       )->andStatement(
+                               NewStatement::forProperty( 
Id::P_IPA_PRONUNCIATION )
+                                       ->withValue( '/hɑɹd/' )
+                       )->andStatement(
+                               NewStatement::forProperty( 
Id::P_PRONUNCIATION_AUDIO )
+                                       ->withValue( 'hard.ogg' )
+                       )->build();
+       }
+
+       /**
+        * @return \Wikibase\Lexeme\DataModel\Form
+        */
+       private function buildHarderForm() {
+               return NewForm::havingId( 'F2' )
+                       ->andRepresentation( 'en', 'harder' )
+                       ->andGrammaticalFeature( Id::Q_COMPARATIVE )
+                       ->build();
+       }
+
+       /**
+        * @return \Wikibase\Lexeme\DataModel\Sense
+        */
+       private function buildPresentingDifficultySense() {
+               return NewSense::havingId( 'S1' )
+                       ->withGloss( 'en', 'presenting difficulty' )
+                       ->withGloss( 'de', 'Schwierig oder kompliziert' )
+//                     ->withStatement(
+//                             NewStatement::forProperty(Id::P_SYNONYM_OF)
+//                             ->withValue(Id::___difficult)
+//                     )
+                       ->withStatement(
+                               NewStatement::forProperty( Id::P_REGISTER )
+                                       ->withValue( Id::Q_COLLOQUIALISM )
+                       )
+//                     ->withStatement(
+//                             NewStatement::forProperty(Id::P_Translation)
+//                             ->withValue(Id::S_schwierig)
+//                     )
+                       ->build();
+       }
+
+       /**
+        * @return \Wikibase\Lexeme\DataModel\Sense
+        */
+       private function buildResistingDeformationSense() {
+               return NewSense::havingId( 'S2' )
+                       ->withGloss( 'en', 'resisting deformation' )
+                       ->withGloss( 'de', 'schwer verformbar' )
+//                     ->withStatement(
+//                             NewStatement::forProperty(Id::P_SYNONYM_OF)
+//                             ->withValue(Id::___difficult)
+//                     )
+                       ->withStatement(
+                               NewStatement::forProperty( 
Id::P_RELATED_CONCEPT )
+                                       ->withValue( Id::Q_ELASTICITY )
+                       )
+                       ->withStatement(
+                               NewStatement::forProperty( 
Id::P_RELATED_CONCEPT )
+                                       ->withValue( Id::Q_DUCTILITY )
+                       )
+                       ->withStatement(
+                               NewStatement::forProperty( 
Id::P_RELATED_CONCEPT )
+                                       ->withValue( Id::Q_HARDNESS )
+                       )
+//                     ->withStatement(
+//                             NewStatement::forProperty(Id::P_Translation)
+//                             ->withValue(Id::S_schwierig)
+//                     )
+                       ->build();
+       }
+
+}
diff --git a/src/DemoData/Id.php b/src/DemoData/Id.php
new file mode 100644
index 0000000..3c90d50
--- /dev/null
+++ b/src/DemoData/Id.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace Wikibase\Lexeme\DemoData;
+
+class Id {
+
+       const L_HARD = 'L13';
+       const L_HEARD = 'L14';
+       const L_LEITER = 'L15';
+       const L_LEITERIN = 'L16';
+       const L_ASK_1 = 'L17';
+       const L_ASK_2 = 'L18';
+       const L_ASK_OUT = 'L19';
+
+       const P_LANGUAGE_CODE = 'P2';
+       const P_INSTANCE_OF = 'P3';
+       const P_LEXEME_PROPERTY = 'P4';
+       const P_RHYMES_WITH = 'P5';
+       const P_HOMOPHONE = 'P6';
+       const P_TRANSLATES_TO = 'P7';
+       const P_SYNONYM_OF = 'P8';
+       const P_DERIVED_FROM = 'P9';
+       const P_IPA_PRONUNCIATION = 'P10';
+       const P_REGION = 'P11';
+       const P_PRONUNCIATION_AUDIO = 'P12';
+       const P_REGISTER = 'P13';
+       const P_RELATED_CONCEPT = 'P14';
+       const P_MORPHOLOGY = 'P15';
+       const P_GRAMMATICAL_GENDER = 'P16';
+       const P_GENDERED_FORM = 'P17';
+       const P_SYLLABIFICATION = 'P18';
+       const P_GRAMMATICAL_FRAME = 'P19';
+
+       const Q_VERBAL_PHRASE = 'Q31';
+       const Q_FEMALE = 'Q30';
+       const Q_GENITIVE = 'Q29';
+       const Q_SINGULAR = 'Q28';
+       const Q_NOMINATIVE = 'Q27';
+       const Q_MALE = 'Q26';
+       const Q_GERMAN_DECLINATION_W1 = 'Q25';
+       const Q_NORMATIVE = 'Q24';
+       const Q_HARDNESS = 'Q22';
+       const Q_DUCTILITY = 'Q21';
+       const Q_ELASTICITY = 'Q20';
+       const Q_COLLOQUIALISM = 'Q19';
+       const Q_COMPARATIVE = 'Q18';
+       const Q_UNITED_STATES_OF_AMERICA = 'Q17';
+       const Q_SCOTLAND = 'Q16';
+       const Q_OLDENGLISH = 'Q15';
+       const Q_ADJECTIVE = 'Q14';
+       const Q_SYNONYM_SENSE = 'Q13';
+       const Q_TRANSLATES_TO_SENSE = 'Q12';
+       const Q_HOMOPHONE_FORM = 'Q11';
+       const Q_RHYMES_WITH_FORM = 'Q10';
+       const Q_FORM_ITEM = 'Q9';
+       const Q_NOUN = 'Q8';
+       const Q_GERMAN = 'Q7';
+       const Q_LEXICAL_CATEGORY = 'Q6';
+       const Q_LANGUAGE = 'Q5';
+       const Q_ENGLISH_LANGUAGE = 'Q4';
+       const Q_ENGLISH = 'Q3';
+       const Q_VERB = 'Q2';
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaacf73a9b3135462dde212ecf773c90ba12ae55c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de>

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

Reply via email to