views:

286

answers:

4

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";
    }
}
+2  A: 

No, this is not grammatically correct. Curtis's is the correct way to say that something belongs to Curtis, since Curtis is singular. If a noun is plural you would using the trailing apostrophe to indicate the possessive.

Edit: Shaun, in my most humble opinion as person with experience as a writer and editor of the English language as well as a programmer, I don't feel that there is any easy answer to this problem. I do not feel that it is correct to write "Curtis'" to express the possessive, and I also feel that there is widespread -- though not universal -- agreement on the subject.

The real work of any algorithmic approach to solving this problem is determining whether or not the noun is singular or plural, and that is an exceedingly difficult problem to solve, one that is well beyond the scope of a StackOverflow answer. Best of luck to you.

Adam Crossland
Adam is correct. And since there's no easy way for a program to tell whether something ending in "s" is a plural noun or a singular noun, it looks like you're out of luck.
Paul Clapham
According to Wikipedia - http://bit.ly/17kMJG - there is not complete agreeance on this topic. While including the s is usually preferred, not having it on is sometimes considered acceptable.
Michael Madsen
While the article does say that there is some disagreement, it makes a rather half-hearted case against always using 's. If the MLA and The Economist both mandate it, that usage is a safe way to come off as literate and well-educated. I certainly think that if you are looking to write an algorithm, I would choose that approach, but as Paul mentioned above, it can't be practically solved algorithmically.
Adam Crossland
-1. Does not answer the question: How would you contruct a string to show ownership?
Rob Kennedy
That wasn't the original question, Rob. It's been edited since I answered the question, which was "Is this the correct way?"
Adam Crossland
@Adam: The two first sentences in your answer are simply wrong. If "Curtis'" or "Curtis's" is the correct way to express what belongs to Curtis is a matter of taste or a matter of which style manual you have to follow.
jarnbjo
I respectfully disgaree. There is more than enough agreement on the subject to say that an algorithm such as shown in the question would produce results that many would feel is incorrect.
Adam Crossland
Sorry, Adam. Didn't notice Dave had changed the question (although answers to *that* question will probably help Shaun quite a bit more than answers to the question he asked).
Rob Kennedy
A: 

For what it's worth, take a look at:

http://frwebgate.access.gpo.gov/cgi-bin/getdoc.cgi?dbname=2008_style_manual&amp;docid=f:chapter8.pdf

Codify that and you have yourself a fairly good algorithm for encoding apostrophes.

Dave Jarvis
No point in referring to an arbitrary style manual, unless you know which style manual the questioner intend to follow. There is no conclusive agreement on how to build the possessive form in the English language.
jarnbjo
Just because there's not universal agreement doesn't mean it can't be useful to just pick *some* way and use it. If Shaun has no style manual to use yet, then he may as well use the one Dave linked to.
Rob Kennedy
Hmmmm. This usage guide says, "The possessive case of a singular or plural noun ending in s or with an s sound is formed by adding an apostrophe only." The examples agree: *hostess* becomes *hostess'* and *Schmitz* becomes *Schmitz'*. But both look wrong to me, and *my neice' choice* looks worse still.
Jason Orendorff
+4  A: 

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.)

Stephen C
I like the first bullet - it seems that the output sentences could be structured to avoid the problem altogether; safely using _its_ where appropriate.
JPDecker
+1  A: 

The reversed form is more stable

 String.Format("The {1} of {0}", owner, item);
Pete Kirkham