01: /*
02: * Created on 12-Feb-2006
03: */
04: package uk.org.ponder.stringutil;
05:
06: /** A standalone Pluralizer that deals with most names that might arise
07: * as entity names.
08: * @author Antranig Basman (amb26@ponder.org.uk)
09: *
10: */
11:
12: public class Pluralizer {
13: // table from
14: // http://www.tiscali.co.uk/reference/dictionaries/english/data/d0082600.html
15: // and http://en.wikipedia.org/wiki/English_plural
16: public static final String[][] rules = { { "", "s" },
17: { "s", "ses" }, { "ss", "ss" }, { "sh", "shes" },
18: { "ss", "sses" }, { "ch", "ches" }, { "dg", "dges" },
19: { "x", "xes" }, { "o", "oes" }, { "f", "ves" },
20: { "fe", "ves" }, { "y", "ies" }, { "ies", "ies" },
21: { "ay", "ays" }, { "ey", "eys" }, { "iy", "iys" },
22: { "oy", "oys" }, { "uy", "uys" }, { "kilo", "kilos" },
23: { "photo", "photos" }, { "piano", "pianos" },
24: { "ox", "oxen" }, { "child", "children" },
25: { "louse", "lice" }, { "mouse", "mice" },
26: { "goose", "geese" }, { "tooth", "teeth" },
27: { "aircraft", "aircraft" }, { "sheep", "sheep" },
28: { "species", "species" }, { "foot", "feet" },
29: { "man", "men" }, { "ex", "ices" }, { "ix", "ices" },
30: { "um", "a" }, { "us", "i" }, { "eau", "eaux" },
31: { "reply", "replies" } };
32:
33: public static String singularize(String plural) {
34: for (int i = rules.length - 1; i >= 0; --i) {
35: if (plural.endsWith(rules[i][1])) {
36: return plural.substring(0, plural.length()
37: - rules[i][1].length())
38: + rules[i][0];
39: }
40: }
41: return plural;
42: }
43:
44: public static String pluralize(String singular) {
45: for (int i = rules.length - 1; i >= 0; --i) {
46: if (singular.endsWith(rules[i][0])) {
47: return singular.substring(0, singular.length()
48: - rules[i][0].length())
49: + rules[i][1];
50: }
51: }
52: return singular;
53: }
54:
55: }
|