如何获得名词的所有格形式?
这是一种向给定输入名词添加撇号的算法。
您将如何构造一个字符串来显示所有权?
/**
* 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";
}
}
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";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
替代方案是:
通过避免为某些任意单词或名称生成所有格的需要来避免该问题。这就是我会做的......除非我感到受虐狂。
做一个简单的工作,将(不可避免地)导致英语无法通过“良好风格”测试一些情况。并准备好转移来自无穷无尽的装饰性的抱怨,这些装饰性的东西除了抱怨糟糕的风格/语法之外没有什么更好的事情可做。
花费很长时间构建能够将单词分析为单数/复数、常规名词/专有名词等的基础设施。然后根据您生成的文本的语法/语义分析来实施样式规则。 (然后为您的网站......或任何......需要支持的每种自然语言重复整个过程。)
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.)
不,这在语法上不正确。 Curtis's 是表示某物属于 Curtis 的正确方式,因为 Curtis 是单数。如果名词是复数,则可以使用末尾的撇号来表示所有格。
编辑:
肖恩,作为一名具有英语作家和编辑以及程序员经验的人,以我最谦虚的观点,我认为这个问题没有任何简单的答案。我不认为写“柯蒂斯”来表达所有格是不正确的,而且我也认为在这个主题上存在广泛的——尽管不是普遍的——一致。
解决这个问题的任何算法方法的真正作用是确定名词是单数还是复数,这是一个非常难以解决的问题,远远超出了 StackOverflow 答案的范围。祝你好运。
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.
反转的形式更稳定
The reversed form is more stable