🔧
This commit is contained in:
@@ -25,8 +25,35 @@ final class EnglishInflector implements InflectorInterface
|
||||
// Fourth entry: Whether the suffix may succeed a consonant
|
||||
// Fifth entry: singular suffix, normal
|
||||
|
||||
// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
|
||||
['a', 1, true, true, ['on', 'um']],
|
||||
// bacteria (bacterium)
|
||||
['airetcab', 8, true, true, 'bacterium'],
|
||||
|
||||
// corpora (corpus)
|
||||
['aroproc', 7, true, true, 'corpus'],
|
||||
|
||||
// criteria (criterion)
|
||||
['airetirc', 8, true, true, 'criterion'],
|
||||
|
||||
// curricula (curriculum)
|
||||
['alucirruc', 9, true, true, 'curriculum'],
|
||||
|
||||
// quora (quorum)
|
||||
['arouq', 5, true, true, 'quorum'],
|
||||
|
||||
// genera (genus)
|
||||
['areneg', 6, true, true, 'genus'],
|
||||
|
||||
// media (medium)
|
||||
['aidem', 5, true, true, 'medium'],
|
||||
|
||||
// memoranda (memorandum)
|
||||
['adnaromem', 9, true, true, 'memorandum'],
|
||||
|
||||
// phenomena (phenomenon)
|
||||
['anemonehp', 9, true, true, 'phenomenon'],
|
||||
|
||||
// strata (stratum)
|
||||
['atarts', 6, true, true, 'stratum'],
|
||||
|
||||
// nebulae (nebula)
|
||||
['ea', 2, true, true, 'a'],
|
||||
@@ -97,6 +124,9 @@ final class EnglishInflector implements InflectorInterface
|
||||
// statuses (status)
|
||||
['sesutats', 8, true, true, 'status'],
|
||||
|
||||
// article (articles), ancle (ancles)
|
||||
['sel', 3, true, true, 'le'],
|
||||
|
||||
// analyses (analysis), ellipses (ellipsis), fungi (fungus),
|
||||
// neuroses (neurosis), theses (thesis), emphases (emphasis),
|
||||
// oases (oasis), crises (crisis), houses (house), bases (base),
|
||||
@@ -141,7 +171,7 @@ final class EnglishInflector implements InflectorInterface
|
||||
// shoes (shoe)
|
||||
['se', 2, true, true, ['', 'e']],
|
||||
|
||||
// status (status)
|
||||
// status (status)
|
||||
['sutats', 6, true, true, 'status'],
|
||||
|
||||
// tags (tag)
|
||||
@@ -166,6 +196,9 @@ final class EnglishInflector implements InflectorInterface
|
||||
// Fourth entry: Whether the suffix may succeed a consonant
|
||||
// Fifth entry: plural suffix, normal
|
||||
|
||||
// axes (axis)
|
||||
['sixa', 4, false, false, 'axes'],
|
||||
|
||||
// criterion (criteria)
|
||||
['airetirc', 8, false, false, 'criterion'],
|
||||
|
||||
@@ -235,7 +268,13 @@ final class EnglishInflector implements InflectorInterface
|
||||
// teeth (tooth)
|
||||
['htoot', 5, true, true, 'teeth'],
|
||||
|
||||
// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
|
||||
// albums (album)
|
||||
['mubla', 5, true, true, 'albums'],
|
||||
|
||||
// quorums (quorum)
|
||||
['murouq', 6, true, true, ['quora', 'quorums']],
|
||||
|
||||
// bacteria (bacterium), curricula (curriculum), media (medium), memoranda (memorandum), phenomena (phenomenon), strata (stratum)
|
||||
['mu', 2, true, true, 'a'],
|
||||
|
||||
// men (man), women (woman)
|
||||
@@ -244,20 +283,11 @@ final class EnglishInflector implements InflectorInterface
|
||||
// people (person)
|
||||
['nosrep', 6, true, true, ['persons', 'people']],
|
||||
|
||||
// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
|
||||
['noi', 3, true, true, 'ions'],
|
||||
// criteria (criterion)
|
||||
['noiretirc', 9, true, true, 'criteria'],
|
||||
|
||||
// coupon (coupons)
|
||||
['nop', 3, true, true, 'pons'],
|
||||
|
||||
// seasons (season), treasons (treason), poisons (poison), lessons (lesson)
|
||||
['nos', 3, true, true, 'sons'],
|
||||
|
||||
// icons (icon)
|
||||
['noc', 3, true, true, 'cons'],
|
||||
|
||||
// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
|
||||
['no', 2, true, true, 'a'],
|
||||
// phenomena (phenomenon)
|
||||
['nonemonehp', 10, true, true, 'phenomena'],
|
||||
|
||||
// echoes (echo)
|
||||
['ohce', 4, true, true, 'echoes'],
|
||||
@@ -268,6 +298,9 @@ final class EnglishInflector implements InflectorInterface
|
||||
// atlases (atlas)
|
||||
['salta', 5, true, true, 'atlases'],
|
||||
|
||||
// aliases (alias)
|
||||
['saila', 5, true, true, 'aliases'],
|
||||
|
||||
// irises (iris)
|
||||
['siri', 4, true, true, 'irises'],
|
||||
|
||||
@@ -288,12 +321,21 @@ final class EnglishInflector implements InflectorInterface
|
||||
// circuses (circus)
|
||||
['suc', 3, true, true, 'cuses'],
|
||||
|
||||
// hippocampi (hippocampus)
|
||||
['supmacoppih', 11, false, false, 'hippocampi'],
|
||||
|
||||
// campuses (campus)
|
||||
['sup', 3, true, true, 'puses'],
|
||||
|
||||
// status (status)
|
||||
['sutats', 6, true, true, ['status', 'statuses']],
|
||||
|
||||
// conspectuses (conspectus), prospectuses (prospectus)
|
||||
['sutcep', 6, true, true, 'pectuses'],
|
||||
|
||||
// nexuses (nexus)
|
||||
['suxen', 5, false, false, 'nexuses'],
|
||||
|
||||
// fungi (fungus), alumni (alumnus), syllabi (syllabus), radii (radius)
|
||||
['su', 2, true, true, 'i'],
|
||||
|
||||
@@ -315,14 +357,14 @@ final class EnglishInflector implements InflectorInterface
|
||||
// indices (index)
|
||||
['xedni', 5, false, true, ['indicies', 'indexes']],
|
||||
|
||||
// fax (faxes, faxxes)
|
||||
['xaf', 3, true, true, ['faxes', 'faxxes']],
|
||||
|
||||
// boxes (box)
|
||||
['xo', 2, false, true, 'oxes'],
|
||||
|
||||
// indexes (index), matrixes (matrix)
|
||||
['x', 1, true, false, ['cies', 'xes']],
|
||||
|
||||
// appendices (appendix)
|
||||
['xi', 2, false, true, 'ices'],
|
||||
// indexes (index), matrixes (matrix), appendices (appendix)
|
||||
['x', 1, true, false, ['ces', 'xes']],
|
||||
|
||||
// babies (baby)
|
||||
['y', 1, false, true, 'ies'],
|
||||
@@ -384,6 +426,12 @@ final class EnglishInflector implements InflectorInterface
|
||||
|
||||
// traffic
|
||||
'ciffart',
|
||||
|
||||
// aircraft
|
||||
'tfarcria',
|
||||
|
||||
// hardware
|
||||
'erawdrah',
|
||||
];
|
||||
|
||||
public function singularize(string $plural): array
|
||||
|
||||
126
vendor/symfony/string/Inflector/SpanishInflector.php
vendored
Normal file
126
vendor/symfony/string/Inflector/SpanishInflector.php
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\String\Inflector;
|
||||
|
||||
final class SpanishInflector implements InflectorInterface
|
||||
{
|
||||
/**
|
||||
* A list of all rules for pluralise.
|
||||
*
|
||||
* @see https://www.spanishdict.com/guide/spanish-plural-noun-forms
|
||||
* @see https://www.rae.es/gram%C3%A1tica/morfolog%C3%ADa/la-formaci%C3%B3n-del-plural-plurales-en-s-y-plurales-en-es-reglas-generales
|
||||
*/
|
||||
// First entry: regex
|
||||
// Second entry: replacement
|
||||
private const PLURALIZE_REGEXP = [
|
||||
// Specials sí, no
|
||||
['/(sí|no)$/i', '\1es'],
|
||||
|
||||
// Words ending with vowel must use -s (RAE 3.2a, 3.2c)
|
||||
['/(a|e|i|o|u|á|é|í|ó|ú)$/i', '\1s'],
|
||||
|
||||
// Word ending in s or x and the previous letter is accented (RAE 3.2n)
|
||||
['/ás$/i', 'ases'],
|
||||
['/és$/i', 'eses'],
|
||||
['/ís$/i', 'ises'],
|
||||
['/ós$/i', 'oses'],
|
||||
['/ús$/i', 'uses'],
|
||||
|
||||
// Words ending in -ión must changed to -iones
|
||||
['/ión$/i', '\1iones'],
|
||||
|
||||
// Words ending in some consonants must use -es (RAE 3.2k)
|
||||
['/(l|r|n|d|j|s|x|ch|y)$/i', '\1es'],
|
||||
|
||||
// Word ending in z, must changed to ces
|
||||
['/(z)$/i', 'ces'],
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of all rules for singularize.
|
||||
*/
|
||||
private const SINGULARIZE_REGEXP = [
|
||||
// Specials sí, no
|
||||
['/(sí|no)es$/i', '\1'],
|
||||
|
||||
// Words ending in -ión must changed to -iones
|
||||
['/iones$/i', '\1ión'],
|
||||
|
||||
// Word ending in z, must changed to ces
|
||||
['/ces$/i', 'z'],
|
||||
|
||||
// Word ending in s or x and the previous letter is accented (RAE 3.2n)
|
||||
['/(\w)ases$/i', '\1ás'],
|
||||
['/eses$/i', 'és'],
|
||||
['/ises$/i', 'ís'],
|
||||
['/(\w{2,})oses$/i', '\1ós'],
|
||||
['/(\w)uses$/i', '\1ús'],
|
||||
|
||||
// Words ending in some consonants and -es, must be the consonants
|
||||
['/(l|r|n|d|j|s|x|ch|y)e?s$/i', '\1'],
|
||||
|
||||
// Words ended with vowel and s, must be vowel
|
||||
['/(a|e|i|o|u|á|é|ó|í|ú)s$/i', '\1'],
|
||||
];
|
||||
|
||||
private const UNINFLECTED_RULES = [
|
||||
// Words ending with pies (RAE 3.2n)
|
||||
'/.*(piés)$/i',
|
||||
];
|
||||
|
||||
private const UNINFLECTED = '/^(lunes|martes|miércoles|jueves|viernes|análisis|torax|yo|pies)$/i';
|
||||
|
||||
public function singularize(string $plural): array
|
||||
{
|
||||
if ($this->isInflectedWord($plural)) {
|
||||
return [$plural];
|
||||
}
|
||||
|
||||
foreach (self::SINGULARIZE_REGEXP as $rule) {
|
||||
[$regexp, $replace] = $rule;
|
||||
|
||||
if (1 === preg_match($regexp, $plural)) {
|
||||
return [preg_replace($regexp, $replace, $plural)];
|
||||
}
|
||||
}
|
||||
|
||||
return [$plural];
|
||||
}
|
||||
|
||||
public function pluralize(string $singular): array
|
||||
{
|
||||
if ($this->isInflectedWord($singular)) {
|
||||
return [$singular];
|
||||
}
|
||||
|
||||
foreach (self::PLURALIZE_REGEXP as $rule) {
|
||||
[$regexp, $replace] = $rule;
|
||||
|
||||
if (1 === preg_match($regexp, $singular)) {
|
||||
return [preg_replace($regexp, $replace, $singular)];
|
||||
}
|
||||
}
|
||||
|
||||
return [$singular.'s'];
|
||||
}
|
||||
|
||||
private function isInflectedWord(string $word): bool
|
||||
{
|
||||
foreach (self::UNINFLECTED_RULES as $rule) {
|
||||
if (1 === preg_match($rule, $word)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 === preg_match(self::UNINFLECTED, $word);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user