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";
}
}
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With