Wikipedia:WikiProject Red Link Recovery/Link matching script/Pluralisation

From Wikipedia, the free encyclopedia

The function below uses some very simple rules to convert the passed word into a plural. Only versions of Mysql newer than 5.0.3 support stored procedures and functions.

For the report of pluralisations, I used this to convert all titles into plurals and check for matches with red links, then reset the titles to their original form before pluralising the red links and checking once more for matches.


CREATE FUNCTION pluralise( text varchar(255) ) RETURNS varchar(255)
BEGIN
  DECLARE l_ret varchar(255);
  
  IF ( text REGEXP '[xs]$' ) or ( text REGEXP '[cs]h$' ) THEN
    SET l_ret = concat( text, 'es' );
  ELSEIF ( text REGEXP 'ff$' ) or ( text REGEXP 'fe$' ) THEN
    SET l_ret = concat( left( text , length( text ) - 2 ), 'es' );
  ELSEIF ( text REGEXP '[^e]f$' ) THEN
    SET l_ret = concat( left( text , length( text ) - 1 ), 'ves' );
  ELSEIF ( text REGEXP 'y$' ) THEN
    SET l_ret = concat( left( text , length( text ) - 1 ), 'ies' );
  ELSEIF ( text REGEXP 'us$' ) THEN
    SET l_ret = concat( left( text , length( text ) - 2 ), 'i' );
  ELSEIF ( text REGEXP 'man$' ) THEN
    SET l_ret = concat( left( text , length( text ) - 3 ), 'men' );
  ELSEIF ( text REGEXP 'is$' ) THEN
    SET l_ret = concat( left( text , length( text ) - 2 ), 'es' );
  ELSE
    SET l_ret = concat( text, 's' );
  END IF;
  
  RETURN l_ret;
END;