Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the possessive form of a noun?

Here's an algorithm for adding an apostrophe to a given input noun.

How would you contruct a string to show ownership?

/**
 * apostrophizes the string properly
 * <pre>
 * curtis = curtis'
 * shaun = shaun's
 * </pre>
 *
 * @param input string to apostrophize
 * @return apostrophized string or empty string if the input was empty or null.
 */
public static String apostrophize(String input) {
    if (isEmpty(input)) return "";

    if ("s".equalsIgnoreCase(StringUtils.right(input,1))) {
        return input + "'";
    } else {
        return input + "'s";
    }
}
like image 896
Shaun Avatar asked Feb 28 '23 17:02

Shaun


1 Answers

How would you construct a string to show ownership?

The alternatives are:

  • Avoid the problem by avoiding the need to generate a possessive for some arbitrary word or name. This is what I would do ... unless I was feeling masochistic.

  • Do a simple job of it that will (inevitably) result in English that fails the "good style" test in some cases. And be prepared to deflect complaints from the endless stream of dingbats who have nothing better to do with their time than complain about bad style / grammar.

  • Spend a long time building infrastructure that is capable of analysing words into singular / plural, regular noun / proper noun, etc, etc. Then implement the style rules according to the syntactic / semantic analysis of the text you are generating. (And then repeat the entire process for each natural language your website ... or whatever ... needs to support.)

like image 103
Stephen C Avatar answered Mar 11 '23 14:03

Stephen C