Skip to content

Commit

Permalink
Merge pull request #20687 from Yoast/218-improve-plural-form-for-fren…
Browse files Browse the repository at this point in the history
…ch-word-complexity

Improve plural form recognition for French word complexity
  • Loading branch information
FAMarfuaty authored Oct 27, 2023
2 parents 6b4e410 + 6d4ee5b commit f60ea93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ describe( "a test checking if the word is complex in French", function() {
expect( checkIfWordIsComplex( wordComplexityConfig, "ouvrir", premiumData ) ).toEqual( false );
} );

it( "returns irregular plural as non-complex if its singular version is found in the list", function() {
expect( checkIfWordIsComplex( wordComplexityConfig, "principaux", premiumData ) ).toEqual( false );
expect( checkIfWordIsComplex( wordComplexityConfig, "principal", premiumData ) ).toEqual( false );
} );

it( "returns irregular plural words longer than 9 characters as complex if it is not in the list", function() {
expect( checkIfWordIsComplex( wordComplexityConfig, "expérimentaux", premiumData ) ).toEqual( true );
} );

it( "returns an -x plural as non-complex if its singular version is found in the list", function() {
expect( checkIfWordIsComplex( wordComplexityConfig, "vaisseaux", premiumData ) ).toEqual( false );
expect( checkIfWordIsComplex( wordComplexityConfig, "vaisseau", premiumData ) ).toEqual( false );
} );

it( "returns words longer than 9 characters preceded by article l' or preposition d' as non complex if the words are in the list", function() {
expect( checkIfWordIsComplex( wordComplexityConfig, "l'ambassadeur", premiumData ) ).toEqual( false );
expect( checkIfWordIsComplex( wordComplexityConfig, "d'échantillon", premiumData ) ).toEqual( false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,24 @@ export default function checkIfWordIsComplex( config, word, premiumData ) {
* word longer than 9 characters is not complex if it starts with capital letter.
*/
if ( word[ 0 ].toLowerCase() === word[ 0 ] ) {
const standardSPluralSuffixesRegex = new RegExp( premiumData.suffixGroupsComplexity.standardSuffixesWithSplural );
const standardXPluralSuffixesRegex = new RegExp( premiumData.suffixGroupsComplexity.standardSuffixesWithXplural );
const irregularPluralSingularSuffixes = premiumData.suffixGroupsComplexity.irregularPluralSingularSuffixes;
const irregularPluralSuffixRegex = new RegExp( irregularPluralSingularSuffixes[ 0 ] );

/*
* If a word is longer than 9 characters and doesn't start with capital letter,
* we check further whether it is a plural ending in -s. If it is, we remove the -s suffix
* we check further whether it is a plural that ends on the -s or -x plural suffix. If it is, we remove the plural suffix
* and check if the singular word can be found in the frequency list.
* if it is a plural that does not end on -s or -x but on -aux, we replace the plural -aux suffix with the singular suffix -al.
* The word is not complex if the singular form is in the list.
*/
if ( word.endsWith( "s" ) ) {
if ( standardSPluralSuffixesRegex.test( word ) || standardXPluralSuffixesRegex.test( word ) ) {
word = word.substring( 0, word.length - 1 );
return ! frequencyList.includes( word );
} else if ( irregularPluralSuffixRegex.test( word ) ) {
word = word.replace( irregularPluralSuffixRegex, irregularPluralSingularSuffixes[ 1 ] );
}
return true;
return ! frequencyList.includes( word );
}

return false;
Expand Down

0 comments on commit f60ea93

Please sign in to comment.