Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Create plural diminutives in Dutch #425

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/yoastseo/spec/morphology/dutch/addNounSuffixesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ describe( "Adds noun suffixes", () => {
expect( addNounSuffixes( "baby", morphologyDataNL.addSuffixes, morphologyDataNL.nouns.suffixes ).sort() ).toEqual( [
"baby's",
"baby'tje",
"baby'tjes",
].sort() );
} );
it( "Adds default noun suffixes to a Dutch stem when the correct suffix cannot be predicted", () => {
expect( addNounSuffixes( "hond", morphologyDataNL.addSuffixes, morphologyDataNL.nouns.suffixes ).sort() ).toEqual( [
"hondje",
"hondjes",
"hondertje",
"hondertjes",
"honden",
"honders",
"hondes",
"hondetje",
"hondetjes",
].sort() );
} );
it( "Creates a second stem with doubled consonant and adds the right suffixes to each stem", () => {
Expand All @@ -83,21 +87,26 @@ describe( "Adds noun suffixes", () => {
"ballers",
"balles",
"balletje",
"balletjes",
].sort() );
} );
it( "Creates a second stem with voiced consonant and adds the right suffixes to each stem", () => {
expect( addNounSuffixes( "huis", morphologyDataNL.addSuffixes, morphologyDataNL.nouns.suffixes ).sort() ).toEqual( [
"huisje",
"huisjes",
"huisertje",
"huisertjes",
"huizen",
"huizers",
"huizes",
"huizetje",
"huizetjes",
].sort() );
} );
it( "Creates a second stem with an undoubled vowel and adds the right suffixes to each stem", () => {
expect( addNounSuffixes( "spoor", morphologyDataNL.addSuffixes, morphologyDataNL.nouns.suffixes ).sort() ).toEqual( [
"spoortje",
"spoortjes",
"sporen",
"sporers",
"spores",
Expand All @@ -111,6 +120,7 @@ describe( "Adds noun suffixes", () => {
it( "Replaces -g with -k in stems ending in -ing before attaching the diminutive suffix", () => {
expect( addNounSuffixes( "ketting", morphologyDataNL.addSuffixes, morphologyDataNL.nouns.suffixes ).sort() ).toEqual( [
"kettinkje",
"kettinkjes",
"kettingen",
"kettingers",
"kettinges",
Expand Down
30 changes: 23 additions & 7 deletions packages/yoastseo/src/morphology/dutch/addNounSuffixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ const getPluralSuffixes = function( stemmedWord, morphologyDataPluralSuffixes )
return pluralSuffixes;
};

/**
* Gets the predicted or default diminutive suffixes. Then creates the plural form of all the diminutive suffixes and
* returns all the diminutive suffixes.
*
* @param {string} stemmedWord The stemmed word.
* @param {Object} morphologyDataDiminutiveSuffixes The morphology data for adding diminutive suffixes.
* @returns {string[]} The diminutive suffixes.
*/
const getDiminutiveSuffixes = function( stemmedWord, morphologyDataDiminutiveSuffixes ) {
const singularDiminutiveSuffixes = getSuffixes( stemmedWord, morphologyDataDiminutiveSuffixes );

const pluralDiminutiveSuffixes = singularDiminutiveSuffixes.map( suffix => suffix + "s" );

return singularDiminutiveSuffixes.concat( pluralDiminutiveSuffixes );
};

/**
* Creates additional modified stems if needed and adds the relevant suffixes to the stem(s) in order to create noun forms.
*
Expand All @@ -71,24 +87,24 @@ export function addNounSuffixes( stemmedWord, morphologyDataAddSuffixes, morphol
const pluralSuffixes = getPluralSuffixes( stemmedWord, morphologyDataNounSuffixes.pluralSuffixes );

// Get diminutive suffixes.
const diminutiveSuffixes = getSuffixes( stemmedWord, morphologyDataNounSuffixes.diminutiveSuffixes );
const diminutiveSuffixes = getDiminutiveSuffixes( stemmedWord, morphologyDataNounSuffixes.diminutiveSuffixes );

// Join the diminutive and plural suffixes
let combinedSuffixes = pluralSuffixes.concat( diminutiveSuffixes );

const nounForms = [];

/* If the kje suffix exists in the suffixes for this word,
remove the last character of the stem, attach the suffix to the stem, and add the resulting
form to the noun forms array. */
remove the last character of the stem, add the suffixes -kje and -kjes to the stem, and add the resulting
forms to the noun forms array. */
if ( combinedSuffixes.includes( "kje" ) ) {
combinedSuffixes = combinedSuffixes.filter( suffix => suffix !== "kje" );
const kjeForm = stemmedWord.slice( 0, -1 ) + "kje";
nounForms.push( kjeForm );
const kjeSuffixes = combinedSuffixes.filter( suffix => suffix.includes( "kje" ) );
combinedSuffixes = combinedSuffixes.filter( suffix => ! suffix.includes( "kje" ) );
nounForms.push( ...applySuffixesToStem( stemmedWord.slice( 0, -1 ), kjeSuffixes ) );
}

// Then find the suffixes that require a stem modification (except for "kje")...
const stemModificationSuffixes = [ "en", "ers", "es", "etje" ];
const stemModificationSuffixes = morphologyDataNounSuffixes.requireStemModification;
const suffixesForModifiedStem = combinedSuffixes.filter( suffix => stemModificationSuffixes.includes( suffix ) );

// ...and remove them from the suffixesForUnmodifiedStem array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const checkInseparablePrefix = function( morphologyDataVerbs, stemmedWord, prefi
export function generateParticipleForm( morphologyDataVerbs, stemmedWord ) {
const inseparableExceptionParticiple = generateInseparableExceptionParticipleForm(
stemmedWord,
morphologyDataVerbs.inseparableVerbs
morphologyDataVerbs.inseparableVerbStems
);

if ( inseparableExceptionParticiple ) {
Expand Down