From eea1cb994e8c59ca46af8fb6dffc541196906f61 Mon Sep 17 00:00:00 2001 From: Noud de Brouwer Date: Sun, 6 Sep 2020 13:28:36 +0200 Subject: [PATCH] dutch --- docs/en/index.rst | 1 + lib/Doctrine/Inflector/InflectorFactory.php | 4 + lib/Doctrine/Inflector/Language.php | 1 + .../Inflector/Rules/Dutch/Inflectible.php | 164 ++++++++++++++++++ .../Rules/Dutch/InflectorFactory.php | 21 +++ lib/Doctrine/Inflector/Rules/Dutch/Rules.php | 31 ++++ .../Inflector/Rules/Dutch/Uninflected.php | 66 +++++++ .../Tests/Inflector/InflectorFactoryTest.php | 2 + .../Rules/Dutch/DutchFunctionalTest.php | 57 ++++++ 9 files changed, 347 insertions(+) create mode 100644 lib/Doctrine/Inflector/Rules/Dutch/Inflectible.php create mode 100644 lib/Doctrine/Inflector/Rules/Dutch/InflectorFactory.php create mode 100644 lib/Doctrine/Inflector/Rules/Dutch/Rules.php create mode 100644 lib/Doctrine/Inflector/Rules/Dutch/Uninflected.php create mode 100644 tests/Doctrine/Tests/Inflector/Rules/Dutch/DutchFunctionalTest.php diff --git a/docs/en/index.rst b/docs/en/index.rst index 29866f4d..8cd76827 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -38,6 +38,7 @@ you want to create an inflector for to the ``createForLanguage()`` method: The supported languages are as follows: +- ``Language::DUTCH`` - ``Language::ENGLISH`` - ``Language::FRENCH`` - ``Language::NORWEGIAN_BOKMAL`` diff --git a/lib/Doctrine/Inflector/InflectorFactory.php b/lib/Doctrine/Inflector/InflectorFactory.php index a0740a74..d4053ed3 100644 --- a/lib/Doctrine/Inflector/InflectorFactory.php +++ b/lib/Doctrine/Inflector/InflectorFactory.php @@ -4,6 +4,7 @@ namespace Doctrine\Inflector; +use Doctrine\Inflector\Rules\Dutch; use Doctrine\Inflector\Rules\English; use Doctrine\Inflector\Rules\French; use Doctrine\Inflector\Rules\NorwegianBokmal; @@ -24,6 +25,9 @@ public static function create(): LanguageInflectorFactory public static function createForLanguage(string $language): LanguageInflectorFactory { switch ($language) { + case Language::DUTCH: + return new Dutch\InflectorFactory(); + case Language::ENGLISH: return new English\InflectorFactory(); diff --git a/lib/Doctrine/Inflector/Language.php b/lib/Doctrine/Inflector/Language.php index 78c3cc75..7ab66f78 100644 --- a/lib/Doctrine/Inflector/Language.php +++ b/lib/Doctrine/Inflector/Language.php @@ -6,6 +6,7 @@ final class Language { + public const DUTCH = 'dutch'; public const ENGLISH = 'english'; public const FRENCH = 'french'; public const NORWEGIAN_BOKMAL = 'norwegian-bokmal'; diff --git a/lib/Doctrine/Inflector/Rules/Dutch/Inflectible.php b/lib/Doctrine/Inflector/Rules/Dutch/Inflectible.php new file mode 100644 index 00000000..3f6ebf87 --- /dev/null +++ b/lib/Doctrine/Inflector/Rules/Dutch/Inflectible.php @@ -0,0 +1,164 @@ +medeklinker = '(' . $this->missingFromWiki . '|' . $this->plofKlank . '|' . $this->wrijfKlank . '|' . $this->neusKlank . '|' . $this->vloeiKlank . '|' . $this->glijKlank . '|' . $this->affricate . ')'; + * $this->medeklinker = '((c|h|p|q|x|y|z)|(p|t|k|b|d)|(f|s|ch|sj|v|z|g|j)|(m|n|ng)|(l|r)|(j|w)|(ts|zz|tsj|g))'; + * } + */ +class Inflectible +{ + /** + * @return Transformation[] + */ + public static function getSingular(): iterable + { + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Klinkerverandering + yield new Transformation(new Pattern('()heden$'), '\1heid'); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Beroepen_eindigend_op_-man + yield new Transformation(new Pattern('()mannen$'), '\1man'); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Latijnse_meervoudsvormen + yield new Transformation(new Pattern('()ices$'), '\1ex'); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Stapelmeervoud + yield new Transformation(new Pattern('^(ei|gemoed|goed|hoen|kind|lied|rad|rund)eren$'), '\1'); + + // http://nl.wikipedia.org/wiki/Nederlandse_grammatica + yield new Transformation(new Pattern('()ijen$'), '\1ij'); + + yield new Transformation(new Pattern('()ieen$'), '\1ie'); // ën + + yield new Transformation(new Pattern('()((a|e|i|o|u|ij))s$'), '\1\2'); + + yield new Transformation(new Pattern('()((s)s)en$'), '\1s'); + + yield new Transformation(new Pattern('()((c|h|p|q|x|y|z)|(p|t|k|b|d)|(f|s|ch|sj|v|z|g|j)|(m|n|ng)|(l|r)|(j|w)|(ts|zz|tsj|g))en$'), '\1\2'); + } + + /** + * @return Transformation[] + */ + public static function getPlural(): iterable + { + // @todo already in plural (?) + // @todo refine + yield new Transformation(new Pattern('()(e)(s)$'), '\1\2\3\3en'); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Klinkerverandering + yield new Transformation(new Pattern('()heid$'), '\1heden'); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Beroepen_eindigend_op_-man + yield new Transformation(new Pattern('()man$'), '\1mannen'); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Latijnse_meervoudsvormen + yield new Transformation(new Pattern('()ix$'), '\1ices'); + + yield new Transformation(new Pattern('()ex$'), '\1ices'); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Stapelmeervoud + yield new Transformation(new Pattern('^(ei|gemoed|goed|hoen|kind|lied|rad|rund)$'), '\1eren'); + + // http://nl.wikipedia.org/wiki/Nederlandse_grammatica + yield new Transformation(new Pattern('()ij$'), '\1ijen'); + + yield new Transformation(new Pattern('()orie$'), '\1orieen'); // ën klemtoon + + yield new Transformation(new Pattern('()io$'), '\1io\'s'); + + yield new Transformation(new Pattern('()(a|e|i|o|u|ij)$'), '\1\2s'); + + yield new Transformation(new Pattern('()(((c|h|p|q|x|y|z)|(p|t|k|b|d)|(f|s|ch|sj|v|z|g|j)|(m|n|ng)|(l|r)|(j|w)|(ts|zz|tsj|g))e((c|h|p|q|x|y|z)|(p|t|k|b|d)|(f|s|ch|sj|v|z|g|j)|(m|n|ng)|(l|r)|(j|w)|(ts|zz|tsj|g)))$'), '\1\2s'); + + yield new Transformation(new Pattern('()(((c|h|p|q|x|y|z)|(p|t|k|b|d)|(f|s|ch|sj|v|z|g|j)|(m|n|ng)|(l|r)|(j|w)|(ts|zz|tsj|g))(u|i|e|a|o)s)$'), '\1\2sen'); + + yield new Transformation(new Pattern('()(((c|h|p|q|x|y|z)|(p|t|k|b|d)|(f|s|ch|sj|v|z|g|j)|(m|n|ng)|(l|r)|(j|w)|(ts|zz|tsj|g))s)$'), '\1\2en'); + + yield new Transformation(new Pattern('()s$'), '\1zen'); + + yield new Transformation(new Pattern('()((c|h|p|q|x|y|z)|(p|t|k|b|d)|(f|s|ch|sj|v|z|g|j)|(m|n|ng)|(l|r)|(j|w)|(ts|zz|tsj|g))$'), '\1\2en'); + } + + /** + * @return Substitution[] + */ + public static function getIrregular(): iterable + { + // http://nl.wikipedia.org/wiki/Klemtoon + yield new Substitution(new Word('olie'), new Word('oliën')); + + yield new Substitution(new Word('industrie'), new Word('industrieën')); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Klinkerverandering + yield new Substitution(new Word('lid'), new Word('leden')); + + yield new Substitution(new Word('smid'), new Word('smeden')); + + yield new Substitution(new Word('schip'), new Word('schepen')); + + yield new Substitution(new Word('stad'), new Word('steden')); + + yield new Substitution(new Word('gelid'), new Word('gelederen')); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Stapelmeervoud + yield new Substitution(new Word('gelid'), new Word('gelederen')); + + yield new Substitution(new Word('kalf'), new Word('kalveren')); + + yield new Substitution(new Word('lam'), new Word('lammeren')); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Onregelmatige_meervoudsvorming + yield new Substitution(new Word('koe'), new Word('koeien')); + + yield new Substitution(new Word('vlo'), new Word('vlooien')); + + yield new Substitution(new Word('leerrede'), new Word('leerredenen')); + + yield new Substitution(new Word('lende'), new Word('lendenen')); + + yield new Substitution(new Word('epos'), new Word('epen')); + + yield new Substitution(new Word('genius'), new Word('geniën')); + + yield new Substitution(new Word('aanbod'), new Word('aanbiedingen')); + + yield new Substitution(new Word('beleg'), new Word('belegeringen')); + + yield new Substitution(new Word('dank'), new Word('dankbetuigingen')); + + yield new Substitution(new Word('gedrag'), new Word('gedragingen')); + + yield new Substitution(new Word('genot'), new Word('genietingen')); + + yield new Substitution(new Word('lof'), new Word('lofbetuigingen')); + + // http://nl.wikipedia.org/wiki/Meervoud_(Nederlands)#Latijnse_meervoudsvormen + yield new Substitution(new Word('qaestrices'), new Word('quaestrix')); + + yield new Substitution(new Word('matrices'), new Word('matrix')); + } +} diff --git a/lib/Doctrine/Inflector/Rules/Dutch/InflectorFactory.php b/lib/Doctrine/Inflector/Rules/Dutch/InflectorFactory.php new file mode 100644 index 00000000..742233bc --- /dev/null +++ b/lib/Doctrine/Inflector/Rules/Dutch/InflectorFactory.php @@ -0,0 +1,21 @@ +getFlippedSubstitutions() + ); + } + + public static function getPluralRuleset(): Ruleset + { + return new Ruleset( + new Transformations(...Inflectible::getPlural()), + new Patterns(...Uninflected::getPlural()), + new Substitutions(...Inflectible::getIrregular()) + ); + } +} diff --git a/lib/Doctrine/Inflector/Rules/Dutch/Uninflected.php b/lib/Doctrine/Inflector/Rules/Dutch/Uninflected.php new file mode 100644 index 00000000..55ab60b6 --- /dev/null +++ b/lib/Doctrine/Inflector/Rules/Dutch/Uninflected.php @@ -0,0 +1,66 @@ + [DutchInflectorFactory::class, Language::DUTCH]; yield 'English' => [EnglishInflectorFactory::class, Language::ENGLISH]; yield 'French' => [FrenchInflectorFactory::class, Language::FRENCH]; yield 'Norwegian Bokmal' => [NorwegianBokmalInflectorFactory::class, Language::NORWEGIAN_BOKMAL]; diff --git a/tests/Doctrine/Tests/Inflector/Rules/Dutch/DutchFunctionalTest.php b/tests/Doctrine/Tests/Inflector/Rules/Dutch/DutchFunctionalTest.php new file mode 100644 index 00000000..325d9867 --- /dev/null +++ b/tests/Doctrine/Tests/Inflector/Rules/Dutch/DutchFunctionalTest.php @@ -0,0 +1,57 @@ +build(); + } +}