org.javagen.agile.oo.naming
Class RegularPlurals

java.lang.Object
  extended by org.javagen.agile.oo.naming.RegularPlurals
All Implemented Interfaces:
Pluralisation

public class RegularPlurals
extends Object
implements Pluralisation

Translate nouns from singular to plural and back again. This class supports a two-tier approach to handle both regular and irregular noun pluralization by supporting both regular-expression and lookup-table replacement respectively.

By default to-plural and to-singular grammer rules for English regular nouns are created. Additional regular expression-replacement pattern rules can be added using the addToPluralReplacementPattern and addToSingularReplacementPattern methods.

By default these pluralization rules are added for English language support:

  1. sibilant ending rule: dish-dishes, glass-glasses, witch-witches
  2. -oes rule: hero-heroes, potato-potatoes, volcano-volcanoes
  3. -ies rule: cherry-cherries, lady-ladies
  4. -s suffix rule: boy-boys, girl-girls, cat-cats, chair-chairs, judge-judges, phase-phases
Irregular plurals must be added explicitly to the singularToPlural lookup table. The reverse pluralToSingularl table will be created automatically:

 Map<String, String> sing2plural = new HashMap<String, String>();
 sing2plural.put("Aircraft","Aircraft");
 sing2plural.put("Child","Children");
 serviceImpl.setSingularToPlural(sing2plural);
 
Case is preserved for lowercase, uppercase and camelBack naming conventions. Lookup keys are not case-sensitive.

Author:
Richard Easterling
See Also:
http://en.wikipedia.org/wiki/English_plural

Constructor Summary
RegularPlurals()
          Setup regular noun to-plural and to-singular grammer rules for English language.
 
Method Summary
 void addToPluralReplacementPattern(String regex, String replacementPattern)
          Add a regex-replacementPattern pair to pluralization rules.
 void addToSingularReplacementPattern(String regex, String replacementPattern)
          Add a regex-replacementPattern pair to pluralization rules.
 Map<String,String> getPluralToSingular()
           
 Map<String,String> getSingularToPlural()
           
 RegexRenamer getToPluralRegexRenamer()
           
 RegexRenamer getToSingularRegexRenamer()
           
protected  String lookupPlural(String singular)
          Lookup irregular plural noun.
protected  String lookupSingular(String plural)
          Lookup irregular singular noun.
 void setSingularToPlural(Map<String,String> singularToPlural)
          Setter for both singularToPlural and pluralToSingular maps.
 void setToPluralRegexRenamer(RegexRenamer toPluralRegexRenamer)
           
 void setToSingularRegexRenamer(RegexRenamer toSingularRegexRenamer)
           
 String toPlural(String singular)
          Convert singular noun to plural form.
 String toSingular(String plural)
          Convert plural noun to singular form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegularPlurals

public RegularPlurals()
Setup regular noun to-plural and to-singular grammer rules for English language.

Method Detail

toPlural

public String toPlural(String singular)
Convert singular noun to plural form.

Specified by:
toPlural in interface Pluralisation

toSingular

public String toSingular(String plural)
Convert plural noun to singular form.

Specified by:
toSingular in interface Pluralisation

lookupPlural

protected String lookupPlural(String singular)
Lookup irregular plural noun. Checks if it's already plural.


lookupSingular

protected String lookupSingular(String plural)
Lookup irregular singular noun. Checks if it's already singular.


addToPluralReplacementPattern

public void addToPluralReplacementPattern(String regex,
                                          String replacementPattern)
Add a regex-replacementPattern pair to pluralization rules. A reverse rule should be added to the singular rules using addToSingularReplacementPattern.


addToSingularReplacementPattern

public void addToSingularReplacementPattern(String regex,
                                            String replacementPattern)
Add a regex-replacementPattern pair to pluralization rules. A reverse rule should be added to the plural rules using addToPluralReplacementPattern.


getToPluralRegexRenamer

public RegexRenamer getToPluralRegexRenamer()

setToPluralRegexRenamer

public void setToPluralRegexRenamer(RegexRenamer toPluralRegexRenamer)

getToSingularRegexRenamer

public RegexRenamer getToSingularRegexRenamer()

setToSingularRegexRenamer

public void setToSingularRegexRenamer(RegexRenamer toSingularRegexRenamer)

getSingularToPlural

public Map<String,String> getSingularToPlural()

setSingularToPlural

public void setSingularToPlural(Map<String,String> singularToPlural)
Setter for both singularToPlural and pluralToSingular maps.

Parameters:
singularToPlural - map of singular-plural nouns.

getPluralToSingular

public Map<String,String> getPluralToSingular()


Copyright 2006-2006-2007 Outsource Cafe Inc.. All Rights Reserved.