public static function wordIsPlural($word) { // check if plural is in special word list if( \MwbExporter\Helper\SpecialWordList::getSingularOf($word)){ return true; } return strlen($word) > 1 && self::wordEndsWith($word, 's') && !self::wordEndsWith($word, 'ss') && !self::wordEndsWith($word, 'us'); }
public static function singularize($word) { if($tmpWord = \MwbExporter\Helper\SpecialWordList::getSingularOf($word)){ return ucfirst($tmpWord); } $word = self::stripWordEnd($word, 's'); // we can't just strip the s without looking at the remaining English plural endings // see http://en.wikipedia.org/wiki/English_plural // if the table name ends with "e" ("coache", "hashe", "addresse", "buzze", "heroe", ...) if ( self::wordEndsWith($word, 'che') or self::wordEndsWith($word, 'she') or self::wordEndsWith($word, 'sse') or self::wordEndsWith($word, 'zze') or self::wordEndsWith($word, 'oe') ) { // strip an "e", too $word = self::stripWordEnd($word, 'e'); // if table name ends with "ie" } elseif ( self::wordEndsWith($word, 'ie') ) { // replace "ie" by a "y" ("countrie" -> "country", "hobbie" -> "hobby", ...) $word = self::stripWordEnd($word, 'ie') . 'y'; } elseif ( self::wordEndsWith($word, 've') ) { // replace "ve" by an "f" ("calve" -> "calf", "leave" -> "leaf", ...) $word = self::stripWordEnd($word, 've') . 'f'; // does *not* work for certain words ("knive" -> "knif", "stave" -> "staf", ...) } else { // do nothing ("game", "referee", "monkey", ...) // note: table names like "Caches" can't be handled correctly because of the "che" rule above, // that word however basically stems from French and might be considered a special case anyway // also collective names like "Personnel", "Cast" (caution: SQL keyword!) can't be singularized } return $word; }